我有一个要求,其中我已将Lexer令牌写为:
IF_LEXER_TOKEN: 'IF' (.)* 'END_IF'
ANY :(options {greedy=true;}: .)* ;
但如果输入为:
IF a>b then a=b END_IF
IF c>d then c=d
在这种情况下,预期的行为是它应该使用令牌IF_LEXER_TOKEN
作为第一行,ANY令牌作为第二行,而是考虑两行的ANY令牌。请帮助。注意:由于某些限制,我无法为上述场景创建解析器规则。
答案 0 :(得分:0)
My answer would be: don't do what you're trying to do. Never use .*
or .+
at the end of a lexer rule: it consumes everything until EOF
.
I don't know exactly what you're trying to do, but it seems to me you're trying to get an answer to problem Y
1, while you ought to be explaining problem X
1.
1 https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem