我有一个规则,当它是一个解析器(小写)规则时匹配字符串,但不是当它是一个词法分析器(大写)规则时。这是代码:
not_combat
: (ownership|'the') PHASES
;
ownership
: SELECTIVES (player_opponent'\'s'?)? // this needs to be a parser rule, fails on lexer rule... dunno why.
;
SELECTIVES
: 'your'|'each'|'that'
;
player_opponent
: 'player'|'opponent'
;

我在IntelliJ Idea中运行Antlr4插件,使用内置规则测试器和解析树。我的测试字符串是each player's upkeep
,其中player_opponent
解析器规则将起作用,但词法分析器Player_opponent
规则将失败,字符串为player
,但不会出现字符串opponent
,这对我来说真的很混乱。