1
我有以下的語法:antlr4語法錯誤
grammar Token;
prog: (expr NL?)+ EOF;
expr: '[' type ']';
type : typeid ':' value;
typeid : 'TXT' | 'ENC' | 'USR';
value: Text | INT;
INT : '0' | [1-9] [0-9]*;
//WS : [ \t]+;
WS : [ \t\n\r]+ -> skip ;
NL: '\r'? '\n';
Text : ~[\]\[\n\r"]+ ;
,我需要解析的文字是這樣的下面
[TXT:look at me!]
[USR:19700]
[TXT:, can I go there?]
[ENC:124124]
[TXT:this is needed for you to go...]
我需要拆分這個文本,但我得到了一些當我運行錯誤grun.bat Token prog -gui -trace -diagnostics
enter prog, LT(1)=[
enter expr, LT(1)=[
consume [@0,0:0='[',<3>,1:0] rule expr
enter type, LT(1)=TXT:look at me!
enter typeid, LT(1)=TXT:look at me!
line 1:1 mismatched input 'TXT:look at me!' expecting {'TXT', 'ENC', 'USR'}
... much more ...
我的語法有什麼問題?請幫幫我!
文本相匹配的方式太多了。例如,它匹配「TXT」。嘗試使其更具體。 – 2014-10-06 16:51:40
@TheANTLRGuy,但我需要匹配'TXT'和']'之間的任何文本,我怎樣才能讓'Text'更具體呢? – thiagoh 2014-10-06 16:54:39
嘗試〜']'也許? – 2014-10-06 18:02:55