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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -