Access Sub-Contexts of Main-Context in ANTLR4 Tree-Listener -


currently i'm using code access sub-contexts of main-context in tree listener implementation antlr4:

ctx.children.foreach(function(child) {     if (child.italic != undefined) {         var text = child.italic().gettext();          ...     } else if (child.labelref != undefined) {         var text = child.labelref().gettext();          ...     }      ... 

due fact i'm using javascript antlr4 target i'm not quite sure if correct way of accessing information this.

if c# or java target think find best way. or result in

child.italic != null 

calls , stuff that?

the results fine , everything's working. i'm curious if there's better solution.

yes, how access individual subparts. alterntaively, can use childrens property of main context, contains parsetree instances (actually either terminalnode or rulecontext instances, depending on whether it's terminal or not). way don't need check individual sub context (which view of childrens list anyway).

side note: instead of sub contexts can use variables in grammar, e.g.

expr:   left = int op = ('+' | '-') right = int   | left = int op = ('*' | '/') right = int ; 

this create variables left , right can directly access without going subcontexts.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -