java - Processing a String with ANTLR4 -
i'm trying convert grammar v3 v4 , having trouble finding right pieces.
in v3 process string, used:
public static dataextractor create(string dataspec) { charstream stream = new antlrstringstream(dataspec); dataspecificationlexer lexer = new dataspecificationlexer(stream); commontokenstream tokens = new commontokenstream(lexer); dataspecificationparser parser = new dataspecificationparser(tokens); return parser.dataspec(); }
how change work in v4?
the changes made are:
antlrstringstream
has been replaced constructor inantlrinputstream
takesstring
- parser rules return context object has public field named according
returns
clause of rule.
so if dataspec
rule says "returns [dataextractor extractor]
", v4 method becomes:
public static dataextractor create(string dataspec) { charstream stream = new antlrinputstream(dataspec); dataspecificationlexer lexer = new dataspecificationlexer(stream); commontokenstream tokens = new commontokenstream(lexer); dataspecificationparser parser = new dataspecificationparser(tokens); return parser.dataspec().extractor; }
Comments
Post a Comment