private Map < String , ParseTreeNode > getTokens ( ) throws GrammarException , TreeException { Map < String , ParseTreeNode > tokens = new HashMap < String , ParseTreeNode > ( ) ; ParseTreeNode tokensTree = parserTree . getChild ( "Tokens" ) ; ParseTreeNode tokenDefinitions = tokensTree . getChild ( "TokenDefinitions" ) ; for ( ParseTreeNode tokenDefinition : tokenDefinitions . getChildren ( "TokenDefinition" ) ) { // identifier... String identifier = tokenDefinition . getChild ( "IDENTIFIER" ) . getText ( ) ; // token parts... tokens . put ( identifier , tokenDefinition ) ; // visibility... ParseTreeNode visibilityAST = tokenDefinition . getChild ( "Visibility" ) ; if ( visibilityAST . hasChild ( "HIDE" ) ) { tokenVisibility . put ( identifier , Visibility . HIDDEN ) ; } else if ( visibilityAST . hasChild ( "IGNORE" ) ) { tokenVisibility . put ( identifier , Visibility . IGNORED ) ; } else { tokenVisibility . put ( identifier , Visibility . VISIBLE ) ; } } return tokens ; }
This method reads all tokens from AST and returns a map with all of them .