Hello.
I want to process large files, some are >5GB in size. I am relatively new to ANTLR and I have been studying The Definitive ANTLR 4 Reference book and online StringTemplate documentation for learning. Following are two approaches that I have come up with for this particular requirement:
· Alternative 1: Use ANTLR 4.4 grammar implementation alone. Furthermore, to avoid maximum possible performance overhead I have decided NOT to build AST during processing the file. Alternatively, I am planning to implement all the parsing logic in Embedded Actions (For instance, for any operation that I would like to perform on exitRule method I will add it to Embedded Action with @after modifier and similar for enterRule operations.)
· Alternative 2: Use StringTemplate Group file to build my target (XML) structure “view” and ANTLR grammar for source (JSON) will be “Controller” and source content could be “Model”.
I am bit in dilemma on which option to go for. So any suggestion/help/idea on following of my concerns will surely be highly appreciated.
Is it recommended using StringTemplate to build this translator because unlike .NET and HTML , languages with most of the code structure being static and dynamic parameter values to be injected, XML does not have much of metadata information except few special characters like triangular braces (Of course in context of JSON to XML Translation. Because in this case we would be injecting few metadata characters ,View (<tagName>value</tagName>), around actual source data ,Model (Source content that provides almost everything from tag name ,value and hierarchy). Does this use case not suitable to the actual philosophy of StringTemplate ?
I have read about StringTemplate question on stackoverflow.com that was discussed before launch of ANTLR 4 and it shows use of method to call a StringTemplate group from a parser rule but my latest NetBeans with ANTLRWorks 2.0 plugin invalidate the following syntax. Is it deprecated and so what are alternatives that made available for such operations?
http://stackoverflow.com/questions/6088834/use-of-stringtemplate-in-antlr
(ANTLR Grammar)
defField
: t=type v+=VAR (',' v+=VAR)* SEP -> defFieldSchema(type={$t.text}, vars={$v})
;
The reason why I am seeking justification on “Can’t I do this translation with Embedded Action” is based on following example from StringTemplate Documentation from (https://theantlrguy.atlassian.net/wiki/display/ST/Language+Translation+Using+ANTLR+and+StringTemplate)
If anyway I am using Embedded Action in each rule should I simply convert JSON content into xml tag names and tag values without passing data to StringTemplate because I want to avoid any unnecessary data movements to get higher performance.
variable returns [StringTemplate code=null]
{StringTemplate t=null,d=null;}
: t=type d=declarator SEMI
{
if ( currentFunctionName==null ) {
code = template("globalVariable");
}
else {
code = template("variable");
}
code.setAttribute("type", t);
code.setAttribute("name", d);
}
;
declarator returns [StringTemplate code=null]
: id:ID {code=text(id.getText());}
;
Perhaps there are other viable options that I have not yet considered? Feel free Please educate me.
Thanks in advance.