java - Exact String parsing on antlr4 -
i having issue while doing parsing of file. scenario follows :
in file got parse, have values follows
abc/123/test
the first 3 letters kind of identifiers, , way can differ various line
in grammar file:
file1: str1?; str1 : newline identifier1 slant integer slant alpha; integer : [0-9]+; alpha : [a-z]+; slant : '/'; newline : '/n'; identifier1 : 'abc';
while running parser, parser not getting line identifier abc, instead giving me strange error
mismatched input 'abc' expecting 'abc'
how can parse against exact string in antlr4?
the problem lexer lexes abc
alpha
instead of identifier1
. here why:
- your
identifier1
rules should rather lexer instead of parser rule. renameidentifier1
- the
identifier1
rule must declared beforealpha
rule, otherwise,alpha
have higher precedence ,abc
parsedalpha
instead ofidentifier1
. sure moveidentifier1
rule abovealpha
rule, should wok fine.
Comments
Post a Comment