-
Notifications
You must be signed in to change notification settings - Fork 175
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
Negative lookahead/trailing context #181
Comments
In general negative lookahead is not supported. You can have a pair of rules:
Otherwise, if your lookahead expression is simple, it might be possible to manually invert it: e.g. inverted Note that in re2c-0.16 trailing contexts might not work as expected (see #165). This bug is fixed in |
Of course, a pair of rules is not exactly the same as negative lookahead: the first rule may prevent shorter overlapping rules from matching. |
Cool. I could do what you suggest very easily, and I believe my case will not tickle the bug in question. How, though, do you reject a pattern in an action after a rule? The manual does not make it obvious. (Perhaps this is another thing that could be documented?) |
Actually, I just realized that the problem with shorter overlapping rules would bite me here. This is somewhat irritating. What I need to express is this, approximately:
Unfortunately, it turns out that otherwise relatively obvious rules like: |
This is a very common situation; I would probably do the following. First, list all lexemes explicitly:
Then deal with each type of lexeme in its own way, depending on what exactly you are trying to achieve. If you describe your problem in more details I might suggest something more suitable. This is how re2c can be used to lex C++: http://re2c.org/examples/example_07.html (this includes recognizing and parsing integers, floats and strings). |
I solved my particular problem by doing the equivalent of: A true negative trailing context system might be nice, but I seem to be fine without it for the moment. Interestingly, I found some sort of weird problem when I parenthesized that expression. I have reported it separately as a bug. |
Glad you solved your problem! |
Indeed. Though if there's a wishlist file of some sort, negative trailing context might be a nice thing to add. :) (I get that it is unlikely to show up any time soon.) |
Sure, I will leave the bug open as a reminder. |
The
r / s
syntax allows me to specify trailing context that isn't included in the matched expression.What's the easiest way to specify negative trailing context, that is, a
/ s
whose pattern, if it is present, causesr
not to be be matched?(I realize this feature might not exist as such.)
The text was updated successfully, but these errors were encountered: