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:

  1. you forgot update open rule in modetagslexer.g4 use following form:

    open  : '«' -> mode(island) ; 
  2. you found bug in antlr 4, should reported issue tracker.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -