cucumber-expressions: Allow parentheses to be explicitly escaped #334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This allows parentheses to be explicitly escaped in cucumber expressions, so that they can be interpreted literally. This addresses issue #333.
Details
I changed
OPTIONAL_REGEXP
so that it looks for an optional escape character before the opening parenthesis. If found, the subsequentgsub
will emit escaped parentheses, rather than the optional group.It was necessary to look for a double-escaped parenthesis, though, because of how the
ESCAPE_REGEXP
was already escaping special characters.Motivation and Context
The motivation is described in #333, but to summarize in brief, I am using Cucumber to describe an API in a platform-agnostic manner, for a book I am writing. I am using the Cucumber scenarios to describe function calls, which enclose parameter lists in parentheses. The cucumber expressions were not liking that very much.
How Has This Been Tested?
I added a spec that matches an expression with escaped parentheses, and showed that the expression was successfully parsed. All other tests continue to be green with this change.
Types of changes
Checklist:
Thank you!