antlr4 - Inheriting from Own class instead from XMLParserRuleContext -


i using 'visitor' pattern generate xml parsed code. on typical context class looks like:

public static class on_dtmcontext extends parserrulecontext {     public list<fieldcontext> field() {         return getrulecontexts(fieldcontext.class);     }     public terminalnode on() { return gettoken(src_rep_screenparser.on, 0); }     public on_dtm_headercontext on_dtm_header() {         return getrulecontext(on_dtm_headercontext.class,0);     } ..... } 

and access element in visitors call function using rulecontext's 'gettext' member function. write class inheriting 'parserrulecontext' , overload 'gettext' in order replace characters '<' or '>' xml escape sequences. there way can have code generated , having context classes inheriting class, as:

public static class on_dtmcontext extends xmlparserrulecontext {     public list<fieldcontext> field() {         return getrulecontexts(fieldcontext.class);     }     public terminalnode on() { return gettoken(src_rep_screenparser.on, 0); }     public on_dtm_headercontext on_dtm_header() {         return getrulecontext(on_dtm_headercontext.class,0);     } ..... } 

thank help! kind regards, wolf

is there reason why trying extend class, rather creating parser rule in grammar capture < , > can translate them occur?

the parser rules like:

lessthan     : '<'     ;  greaterthan     : '>'     ; 

at point, have specific visitors each of terms , translate them will.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -