Calling terminal fragment in another fragment does not work as expected #638
-
NOTE: This title is kind of misleading. The problem here is not about calling fragment in another fragment, but just a subtle bug that some regexes are not surrounded by parenthesis in a mixed one. Hey guys, I ran into a problem with the terminal fragment. According to my tests, these two following ways to define
The second one is just manually copying&pasting the regex and it has the desired behaviour, but the first one does not work as expected. Am I missing something about the terminal fragment (like fragment is not supposed to be called in another fragment?), or is there something wrong with my code? As far as I understand, it works like copy and paste, except that it relieves the burden of adding parentheses manually. By the way, when I use terminal fragment, the generator complains about never using this rule, it reports something like
Do I need to do something to suppress such warnings, or this feature is not fully supported yet? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hey @luan-xiaokun
It's supported, but the missing validation was a bug, see #633.
So Chevrotain (our underlying parser library) is heavily reliant on the order of terminals. It will always perform a first match approach (i.e. find the first tokentype that matches the next characters) instead of a longest fit (as one might expect). So in your case, the
|
Beta Was this translation helpful? Give feedback.
Hey @luan-xiaokun
It's supported, but the missing validation was a bug, see #633.
So Chevrotain (our underlying parser library) is heavily reliant on the order of terminals. It will always perform a first match approach (i.e. find the first tokentype that matches the next characters) instead of a longest fit (as one might expect). So in your case, the
DECSEQ
terminal is always parsed first, even thoughDECFRAG
might fit as well. To fix this, you'll just h…