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 in antlrinputstream takes string
  • 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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -