Inconsistent token handling in ANTLR4 -
the antlr4 book references multi-mode example
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 island mode text : ~'<'+ ; // clump text mode island; close : '>' -> mode(default_mode) ; // sea mode slash : '/' ; id : [a-za-z]+ ; // match/send id in tag parser
https://github.com/stfairy/learn-antlr4/blob/master/tpantlr2-code/lexmagic/modetagsparser.g4
parser grammar modetagsparser; options { tokenvocab=modetagslexer; } // use tokens modetagslexer.g4 file: (tag | text)* ; tag : '<' id '>' | '<' '/' id '>' ;
i'm trying build on example, using «
, »
characters delimiters. if substitute i'm getting error 126
cannot create implicit token string literal in non-combined grammar: '«'
in fact, seems occur have «
character in parser tag
rule.
tag : '«' id '>';
with
open : '«' -> pushmode(island); text : ~'«'+;
is there antlr foo i'm missing? using antlr4-maven-plugin
4.2
.
the wiki mentions along these lines, way read that's contradicting example on github , anecdotal experience when using <
. see "redundant string literals" @ https://theantlrguy.atlassian.net/wiki/display/antlr4/lexer+rules
one of following happening:
you forgot update
open
rule in modetagslexer.g4 use following form:open : '«' -> mode(island) ;
you found bug in antlr 4, should reported issue tracker.
Comments
Post a Comment