parsing - ANTLR: Get text representation of a sub lexer rule -
consider following lexer rules in antlr4:
id: [a-z]+; int: [0-9]+; array: id '[' int ']'; is possible in tree walking scenario have access ctx.array() (where ctx subclass of parserrulecontext generated out of parser rule) text representation of lexer rules id , int? fetch whole text representation ctx.array().gettext() , parse contents of id , int using regexes , wondering if there 'cleaner' out of box solution antlr provides.
note: because of external dependencies making array parser rule not option.
thanks in advance meaningful answers.
lexer rules in antlr 4 cannot broken down parts. design decision made part of massive speed , memory improvement antlr 4 lexers on antlr 3 lexers. antlr 3 lexers recursive descent recognizers many of same features parsers. in antlr 4, lexer nothing more dfa recognizer support semantic predicates, boundaries between individual components of token not tracked @ all.
you'll have either make array parser rule, or separately parse result of gettext() when need break token's text.
Comments
Post a Comment