Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing matcher instance in RETURN statement #194

Open
laudrup opened this issue Jun 12, 2020 · 2 comments
Open

Accessing matcher instance in RETURN statement #194

laudrup opened this issue Jun 12, 2020 · 2 comments

Comments

@laudrup
Copy link
Contributor

laudrup commented Jun 12, 2020

It is quite neat and useful to be able to create custom matchers, but it is a bit unfortunate that it's not easy/possible to access the actual matcher instance in the RETURN or LR_RETURN statement.

Say you have a custom matcher that matches the regex "I want (\d+) apples", it would be quite useful to be able to access the captured integer easily in the RETURN statement and return something like "Here are " + std::to_string(matcher_object.count()) + " apples".

Currently it seems like the RETURN statement can only access the entire matched input argument(s) (ie. _1, _2 etc.) and in cases like this has to more or less redo the work the matcher has already done.

I might be missing something and I don't know if it makes any sense at all, just thought I would share my thoughts.

@rollbear
Copy link
Owner

This is an interesting idea that I have not thought of. As it is currently written it is not possible, but it may be achievable. I'll see what I can do, but to be honest, it is unlikely to happen soon.

@laudrup
Copy link
Contributor Author

laudrup commented Jun 12, 2020

Cool. Thanks for the quick reply.

I wish I could offer the help, but I must admit that the template and macro magic inside trompeloeil is not exactly easy to understand and I assume this requires messing quite a bit with the inner workings of the library.

But let me know if there might be anything I could do to help anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants