How to get the name of the terminal node while walking the tree

163 views
Skip to first unread message

Right_Then

unread,
Dec 21, 2014, 9:12:27 AM12/21/14
to
Dear Fellows,

parseRuleMade: ParserRuleName Colon ( parseRuleElements )* EndStatement 
;

is a parser rule and while walking through the grammar i want to grab the name of the lexerRules i.e
  1. ParserRuleName
  2. Colon
  3. EndStatement
inside this rule.
i can get their values through ctx.children.get( i ).getText  ( ...scala... )
althou ctx.children.get( i ).asInstanceOf[ TerminalNode ].getSymbol.getType 
gives me the number which Antlr4 generates in GrammarNameLexer file
but that number not always corresponds to the index of ruleNames array element in the GrammarNameLexer file. So that one can grab the name from there.
how to go about it please.

Thanks Regards
Right_Then

Reply all
Reply to author
Forward
0 new messages