-
I have trouble getting alternatives to work. I have seen that article: https://chevrotain.io/docs/guide/resolving_grammar_errors.html#AMBIGUOUS_ALTERNATIVES and it absolutely makes sense. Taking the example from the page:
I have another alternative, the one with an "empty" end:
How would I resolve this using chevrotain? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Does Chevrotain complain about this during parser initialization or only fails at runtime? Naively I would refactor this and extract the common prefix
If for whatever reason that is not possible you could consider using GATES to distinguish between the alternatives In theory you could write your own lookahead logic inside the GATEs, going as far as using backtracking |
Beta Was this translation helpful? Give feedback.
-
I would like to implement your refactoring example, but don't know how to express the third case ("A" "B" "C" "D") without "1" or "2"?.
but how about the third case? What if neither "1" nor "2" exists in the input string? |
Beta Was this translation helpful? Give feedback.
-
It seems like something like this works:
Is that good style? |
Beta Was this translation helpful? Give feedback.
It seems like something like this works:
Is that good style?