-
Notifications
You must be signed in to change notification settings - Fork 72
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
order of tokens in choice matters? #26
Comments
Hi! I tried to reply to the email you sent, but it finally bounced today after several days. I'll reproduce it here. The problem you're running into is a known one, and has to do with the fact that Hammer's default backend is packrat parsing. The choice operator in packrat is ordered, which means that if you define a parser that chooses between "asdf" and "asdfv", the first choice in its list that the input string matches will succeed. This is why it works when "asdfv" is the first choice and "asdf" is the second one. This is an inherent limitation of packrat, it's confusing, and we don't like it either, which is why we're planning on implementing ALL* (from ANTLR) and having it be the default backend, although we'll keep packrat around. All the other backends have the unordered choice you're used to, so if the grammar you're implementing is actually regular or context-free, you can use one of them:
I need to write this up for the docs still, so thanks for the reminder. |
Thanks for the response! Makes sense I think, but i don't get one thing: If i parse your response correctly (which i doubt, as i'm confused) then that would mean on the "asdfv" input the parser should match and return "asdf", no? The negative branch of the
|
If a token is a prefix of another token in a choice, then depending on the order of their listing in the choice influences the results of the parser. an example:
sorry if this is due to my poor understanding and in fact an intended feature.
The text was updated successfully, but these errors were encountered: