1

This is probably simple but I can't see the solution. Antlr v 4.0 tells me:

error(50): C:\Users\Brenden\Dev\proj\WikiParser\antlr\wiki\wikigrammar.g4:27:8:
syntax error: extraneous input '' LINK_BODY '' expecting GT while looking for rule element

This is for the input line:

link: '<' LINK_BODY '>' ;

27:8 refers to the < character. Not sure what is going on. Does < need to be escaped or something? I didn't see that on the wiki. The rest of the file seems to parse OK, there's several lines, the one above this one seems OK, it's terminated with a ; so I don't think anything else is messing this line up. Halp?

Edit: here's LINK_BODY, if it matters:

LINK_BODY: ~[<">]+ ;
4

1 回答 1

1

此语法的问题始于'\'在规则中使用不正确的转义序列,导致未终止的字符串文字。由于 ANTLR 4.0 允许词法分析器集(例如[a-z])或词法分析器字符串文字(例如'parser')包含换行符,'因此从错误点到文件末尾的每个字符都会导致它在所有错误的点。

[尚未发布的] ANTLR 4.0.1 通过禁止在这两个标记中嵌入换行符来更改此行为。

https://github.com/antlr/antlr4/pull/169

于 2013-05-01T13:36:56.020 回答