简体   繁体   中英

Antlr4: Prevent rule and token conflicts

Given following grammar:

grammar minimal;

rule: '(' rule_name body ')';
rule_name : NAME;
body : '(' AT NAME ')';

AT : 'at';
NAME: LETTER ANY_CHAR*;
fragment LETTER: 'a' .. 'z' | 'A' .. 'Z';
fragment ANY_CHAR: LETTER | '0' .. '9' | '-' | '_';
WHITESPACE: ( ' ' | '\t' | '\r' | '\n' )+ -> skip;

How can I match (at (at bar)) with at as a valid function name without getting conflicts with the AT token from body without rearranging the grammar?

要消除冲突并保留预期的令牌类型:

rule_name : ( NAME | AT ) -> type(NAME) ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM