-
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
Add new syntax for negated condition lists. #200
Comments
Hi Chris, I think that you should just use empty string
This way the rule says exactly that what you're trying to achieve: if none of the input could be matched, go to some other condition and resume from there. Note that you can use trailing context if you want to match some input without consuming it, as in http://re2c.org/examples/example_05.html at line 35:
Unreachable rules are those that can never be triggered (on no input string). In your case, |
(edited) I tried the empty string - I've reproduced re2c's output below (following comment). -- all warnings are enabled. |
first attempt - not sure if this was a success or not (line 900 is a catchall for bad input)
|
It's because of the rule As for |
okay thanks - FYI, I updated the other comment - because I misread your first response slightly. I'll try the above now |
confirmed that works - thanks! It's unfortunate there's no syntax for exclusionary conditions
it would be useful to be able to do |
If you use By the way, I just noticed that you use rules like this:
This is incorrect because you have a fallthrough at the end of rule: re2c does not automatically generate any
Or better, if you know the right condition, to something like:
Condition syntax is a bit deceiving --- despite the way it looks, it's only semi-automated and you still have to write most of the code yourself. This is because in each rule the programmer usually knows the next condition, and the shortcut |
Yes, and not too hard to implement (the hardest bit is deciding on the syntax). I'll change the name of the issue and leave it open as a feature request for now. |
okay, that sounds great - a new feature, thanks! and FYI - regarding the missing continue / return... in fact I already spotted it
|
inclusive_condition.re.txt
inclusive_condition.c.txt
I've implemented a lexer using re2c that mirrors flex's use of a condition stack, it works well with a couple workarounds. I'd like a bit of clarity on the default rule and direct goto as below (I'm using this to implement inclusive conditions).
results in code like this:
In the case of the default action (goto p133) the cursor is advanced (in my case, this means the ";" is eaten the P3 state, rather than the p135 label ever getting executed. This, because the P3 state also considers the ";" character.
My workaround is to customise to goto statement
re2c:cond:goto = '--YYCURSOR; goto @@;' ;
If the above behaviour is the defined behaviour, then perhaps a warning should be issued that the rule
<STMT> ";"
is unreachable? otherwise, is there a bug to fix?The text was updated successfully, but these errors were encountered: