的ANTLR4書處理引用了一個多模式的例子不一致令牌ANTLR4
https://github.com/stfairy/learn-antlr4/blob/master/tpantlr2-code/lexmagic/ModeTagsLexer.g4
lexer grammar ModeTagsLexer;
// Default mode rules (the SEA)
OPEN : '<' -> mode(ISLAND) ; // switch to ISLAND mode
TEXT : ~'<'+ ; // clump all text together
mode ISLAND;
CLOSE : '>' -> mode(DEFAULT_MODE) ; // back to SEA mode
SLASH : '/' ;
ID : [a-zA-Z]+ ; // match/send ID in tag to parser
https://github.com/stfairy/learn-antlr4/blob/master/tpantlr2-code/lexmagic/ModeTagsParser.g4
parser grammar ModeTagsParser;
options { tokenVocab=ModeTagsLexer; } // use tokens from ModeTagsLexer.g4
file: (tag | TEXT)* ;
tag : '<' ID '>'
| '<' '/' ID '>'
;
我試圖建立這個例子,但使用用於分隔符的«
和»
字符。如果我可以替換爲我收到錯誤126
cannot create implicit token for string literal in non-combined grammar: '«'
事實上,這似乎是我在解析器tag
規則«
字符儘快發生。
tag : '«' ID '>';
與
OPEN : '«' -> pushMode(ISLAND);
TEXT : ~'«'+;
有一些ANTLR富我失蹤?這是使用antlr4-maven-plugin
4.2
。
維基提到了這方面的內容,但我讀到的方式與github上的例子和使用<
時的軼事經驗相矛盾。請參閱「冗餘字符串文字」在https://theantlrguy.atlassian.net/wiki/display/ANTLR4/Lexer+Rules
我當然更新了OPEN規則,上面的第二個片段是剪切/粘貼。我會試着敲一張票的測試用例。謝謝 – ptomli
這看起來像是一個antlr4-maven-plugin和/或m2e的問題。除此之外,我還沒有真正能夠追蹤它。你知道比我更多的方式,你可能有更好的運氣,看到示例項目https://github.com/ptomli/antlr4-22613293 – ptomli
FWIW,我爲此創建了一張票,最終https:// github。 com/antlr/antlr4/issues/563 – ptomli