grammar mygrammar;
string : '"' ( ESC | ~('\u0000'..'\u001f' | '\\' | '\"' ) )* '"';
number : HEX_NUMBER | '-'? INTEGER_NUMBER ( '.' INTEGER_NUMBER )?;
HEX_NUMBER : '0x' HEX_DIGIT+;
INTEGER_NUMBER : DIGIT+;
WS: (' '|'\n'|'\r'|'\t')+ {$channel=HIDDEN;} ; // ignore whitespace
fragment
ESC : '\\' (UNI_ESC |'b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\');
fragment
UNI_ESC : 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT;
fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
DIGIT : ('0'..'9');
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
这是我在 ANTLRWorks 控制台中收到的错误消息
[14:49:09] error(208): mygrammar.g:7:1: The following token definitions can never be matched because prior tokens match the same input: T__16
如果我注释掉string
它生成代码的行,我如何同时拥有规则string
和number
规则?