-
Notifications
You must be signed in to change notification settings - Fork 565
Describe non-greedy repetition operators #2125
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
base: master
Are you sure you want to change the base?
Conversation
I realized that we never described what the `(non-greedy)` text meant. Although I suspect most readers understand it, I felt like it would be best to be explicit about what it means.
| ``` | ||
|
|
||
| When presented with the input `"one" or "two"`, the EXAMPLE_STRING rule will match `"one"` instead of the entire input. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that example isn't illustrating what you intend it to: with the ~" there, greediness doesn't make any difference. The repetition has to stop before the first " in any case.
|
I don't think there's a way of interpreting "stops matching as soon as possible" which makes the current tokenisation rules work. Consider whether Looking at the definition of Looking at the definition of (So in some sense the non-greedy expression in Now consider whether
But we've already decided above that it does. That isn't the answer we want. I put one suggestion for dealing with this in rust-lang/fls#600 (comment) I suppose another approach might be to find a way to make the spec say that tokenisation would never consider |
|
Thanks for the feedback! Indeed this is not right and a bit of a mess. Sorry, I should have posted that we may be considering removing the non-greedy rules, and thus not merging this PR. They are now only used in the raw string rules, and we may take a different approach for those. Hopefully I'll be able to post more on it soonish. |
|
Something we had talked about is that if we did keep Rule 1: Rule 2: The second rule is fairly subtle, especially in its interaction with cut. |
I realized that we never described what the
(non-greedy)text meant. Although I suspect most readers understand it, I felt like it would be best to be explicit about what it means.