trompeloeil icon indicating copy to clipboard operation
trompeloeil copied to clipboard

Accessing matcher instance in RETURN statement

Open laudrup opened this issue 5 years ago • 2 comments

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.

laudrup avatar Jun 12 '20 18:06 laudrup

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.

rollbear avatar Jun 12 '20 19:06 rollbear

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.

laudrup avatar Jun 12 '20 19:06 laudrup