📄 codegentreewalker.java
字号:
break; } default: { throw new NoViableAltException(_t); } } } { int _cnt46=0; _loop46: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==ALT)) { alt=alternative(_t); _t = _retTree; r=(GrammarAST)_t; rew=rewrite(_t); _t = _retTree; if ( this.blockNestingLevel==RULE_BLOCK_NESTING_LEVEL ) { this.outerAltNum++; } // add the rewrite code as just another element in the alt :) if ( rew!=null ) { alt.setAttribute("elements.{el,line,pos}", rew, Utils.integer(r.getLine()), Utils.integer(r.getColumn())); } // add this alt to the list of alts for this block code.setAttribute("alts",alt); alt.setAttribute("altNum", Utils.integer(altNum)); alt.setAttribute("outerAlt", Boolean.valueOf(blockNestingLevel==RULE_BLOCK_NESTING_LEVEL)); altNum++; } else { if ( _cnt46>=1 ) { break _loop46; } else {throw new NoViableAltException(_t);} } _cnt46++; } while (true); } GrammarAST tmp32_AST_in = (GrammarAST)_t; match(_t,EOB); _t = _t.getNextSibling(); _t = __t43; _t = _t.getNextSibling(); blockNestingLevel--; } else { throw new NoViableAltException(_t); } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return code; } public final void exceptionGroup(AST _t, StringTemplate ruleST ) throws RecognitionException { GrammarAST exceptionGroup_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case LITERAL_catch: { { int _cnt50=0; _loop50: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==LITERAL_catch)) { exceptionHandler(_t,ruleST); _t = _retTree; } else { if ( _cnt50>=1 ) { break _loop50; } else {throw new NoViableAltException(_t);} } _cnt50++; } while (true); } { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case LITERAL_finally: { finallyClause(_t,ruleST); _t = _retTree; break; } case EOR: { break; } default: { throw new NoViableAltException(_t); } } } break; } case LITERAL_finally: { finallyClause(_t,ruleST); _t = _retTree; break; } default: { throw new NoViableAltException(_t); } } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; } public final StringTemplate setBlock(AST _t) throws RecognitionException { StringTemplate code=null; GrammarAST setBlock_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST s = null; if ( blockNestingLevel==RULE_BLOCK_NESTING_LEVEL && grammar.buildAST() ) { Rule r = grammar.getRule(currentRuleName); currentAltHasASTRewrite = r.hasRewrite(outerAltNum); if ( currentAltHasASTRewrite ) { r.trackTokenReferenceInAlt(setBlock_AST_in, outerAltNum); } } try { // for error handling s = (GrammarAST)_t; match(_t,BLOCK); _t = _t.getNextSibling(); StringTemplate setcode = getTokenElementST("matchSet", "set", s, null, null); int i = ((TokenWithIndex)s.getToken()).getIndex(); setcode.setAttribute("elementIndex", i); if ( grammar.type!=Grammar.LEXER ) { generator.generateLocalFOLLOW(s,"set",currentRuleName,i); } setcode.setAttribute("s", generator.genSetExpr(templates,s.getSetValue(),1,false)); StringTemplate altcode=templates.getInstanceOf("alt"); altcode.setAttribute("elements.{el,line,pos}", setcode, Utils.integer(s.getLine()), Utils.integer(s.getColumn()) ); altcode.setAttribute("altNum", Utils.integer(1)); altcode.setAttribute("outerAlt", Boolean.valueOf(blockNestingLevel==RULE_BLOCK_NESTING_LEVEL)); if ( !currentAltHasASTRewrite && grammar.buildAST() ) { altcode.setAttribute("autoAST", Boolean.valueOf(true)); } code = altcode; } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return code; } public final StringTemplate alternative(AST _t) throws RecognitionException { StringTemplate code=templates.getInstanceOf("alt"); GrammarAST alternative_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST a = null; /* // TODO: can we use Rule.altsWithRewrites??? if ( blockNestingLevel==RULE_BLOCK_NESTING_LEVEL ) { GrammarAST aRewriteNode = #alternative.findFirstType(REWRITE); if ( grammar.buildAST() && (aRewriteNode!=null|| (#alternative.getNextSibling()!=null && #alternative.getNextSibling().getType()==REWRITE)) ) { currentAltHasASTRewrite = true; } else { currentAltHasASTRewrite = false; } } */ if ( blockNestingLevel==RULE_BLOCK_NESTING_LEVEL && grammar.buildAST() ) { Rule r = grammar.getRule(currentRuleName); currentAltHasASTRewrite = r.hasRewrite(outerAltNum); } String description = grammar.grammarTreeToString(alternative_AST_in, false); description = generator.target.getTargetStringLiteralFromString(description); code.setAttribute("description", description); if ( !currentAltHasASTRewrite && grammar.buildAST() ) { code.setAttribute("autoAST", Boolean.valueOf(true)); } StringTemplate e; try { // for error handling AST __t57 = _t; a = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,ALT); _t = _t.getFirstChild(); { int _cnt59=0; _loop59: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==BLOCK||_t.getType()==OPTIONAL||_t.getType()==CLOSURE||_t.getType()==POSITIVE_CLOSURE||_t.getType()==CHAR_RANGE||_t.getType()==EPSILON||_t.getType()==GATED_SEMPRED||_t.getType()==SYN_SEMPRED||_t.getType()==BACKTRACK_SEMPRED||_t.getType()==ACTION||_t.getType()==ASSIGN||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF||_t.getType()==BANG||_t.getType()==PLUS_ASSIGN||_t.getType()==SEMPRED||_t.getType()==ROOT||_t.getType()==RULE_REF||_t.getType()==NOT||_t.getType()==TREE_BEGIN||_t.getType()==WILDCARD)) { GrammarAST elAST=(GrammarAST)_t; e=element(_t,null,null); _t = _retTree; if ( e!=null ) { code.setAttribute("elements.{el,line,pos}", e, Utils.integer(elAST.getLine()), Utils.integer(elAST.getColumn()) ); } } else { if ( _cnt59>=1 ) { break _loop59; } else {throw new NoViableAltException(_t);} } _cnt59++; } while (true); } GrammarAST tmp33_AST_in = (GrammarAST)_t; match(_t,EOA); _t = _t.getNextSibling(); _t = __t57; _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return code; } public final StringTemplate rewrite(AST _t) throws RecognitionException { StringTemplate code=null; GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST r = null; GrammarAST pred = null; StringTemplate alt; if ( rewrite_AST_in.getType()==REWRITE ) { if ( generator.grammar.buildTemplate() ) { code = templates.getInstanceOf("rewriteTemplate"); } else { code = templates.getInstanceOf("rewriteCode"); code.setAttribute("treeLevel", Utils.integer(OUTER_REWRITE_NESTING_LEVEL)); code.setAttribute("rewriteBlockLevel", Utils.integer(OUTER_REWRITE_NESTING_LEVEL)); code.setAttribute("referencedElementsDeep", getTokenTypesAsTargetLabels(rewrite_AST_in.rewriteRefsDeep)); Set<String> tokenLabels = grammar.getLabels(rewrite_AST_in.rewriteRefsDeep, Grammar.TOKEN_LABEL); Set<String> tokenListLabels = grammar.getLabels(rewrite_AST_in.rewriteRefsDeep, Grammar.TOKEN_LIST_LABEL); Set<String> ruleLabels = grammar.getLabels(rewrite_AST_in.rewriteRefsDeep, Grammar.RULE_LABEL); Set<String> ruleListLabels = grammar.getLabels(rewrite_AST_in.rewriteRefsDeep, Grammar.RULE_LIST_LABEL); // just in case they ref $r for "previous value", make a stream // from retval.tree StringTemplate retvalST = templates.getInstanceOf("prevRuleRootRef"); ruleLabels.add(retvalST.toString()); code.setAttribute("referencedTokenLabels", tokenLabels); code.setAttribute("referencedTokenListLabels", tokenListLabels); code.setAttribute("referencedRuleLabels", ruleLabels); code.setAttribute("referencedRuleListLabels", ruleListLabels); } } try { // for error handling { _loop95: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==REWRITE)) { rewriteRuleRefs = new HashSet(); AST __t93 = _t; r = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,REWRITE); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case SEMPRED: { pred = (GrammarAST)_t; match(_t,SEMPRED); _t = _t.getNextSibling(); break; } case ALT: case TEMPLATE: case ACTION: { break; } default: { throw new NoViableAltException(_t); } } } alt=rewrite_alternative(_t); _t = _retTree; _t = __t93; _t = _t.getNextSibling(); rewriteBlockNestingLevel = OUTER_REWRITE_NESTING_LEVEL; List predChunks = null; if ( pred!=null ) { //predText = #pred.getText(); predChunks = generator.translateAction(currentRuleName,pred); } String description = grammar.grammarTreeToString(r,false); description = generator.target.getTargetStringLiteralFromString(description); code.setAttribute("alts.{pred,alt,description}", predChunks, alt, description); pred=null; } else { break _loop95; } } while (true); } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return code; } public final void exceptionHandler(AST _t, StringTemplate ruleST ) throws RecognitionException { GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling AST __t53 = _t; GrammarAST tmp34_AST_in = (GrammarAST)_t; match(_t,LITERAL_catch); _t = _t.getFirstChild(); GrammarAST tmp35_AST_in = (GrammarAST)_t; match(_t,ARG_ACTION); _t = _t.getNextSibling(); GrammarAST tmp36_AST_in = (GrammarAST)_t; match(_t,ACTION); _t = _t.getNextSibling(); _t = __t53; _t = _t.getNextSibling(); List chunks = generator.translateAction(currentRuleName,tmp36_AST_in); ruleST.setAttribute("exceptions.{decl,action}",tmp35_AST_in.getText(),chunks); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; } public final void finallyClause(AST _t, StringTemplate ruleST ) throws RecognitionException { GrammarAST finallyClause_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling AST __t55 = _t; GrammarAST tmp37_AST_in = (GrammarAST)_t; match(_t,LITERAL_finally); _t = _t.getFirstChild(); GrammarAST tmp38_AST_in = (GrammarAST)_t; match(_t,ACTION); _t = _t.getNextSibling(); _t = __t55; _t = _t.getNextSibling(); List chunks = generator.translateAction(currentRuleName,tmp38_AST_in); ruleST.setAttribute("finally",chunks); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; } public final StringTemplate element(AST _t, GrammarAST label, GrammarAST astSuffix ) throws RecognitionException { StringTemplate code=null; GrammarAST element_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST n = null; GrammarAST alabel = null; GrammarAST label2 = null; GrammarAST a = null; GrammarAST b = null; GrammarAST sp = null; GrammarAST gsp = null; IntSet elements=null; GrammarAST ast = null; try { // for error handling if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case ROOT: { AST __t61 = _t; GrammarAST tmp39_AST_in = (GrammarAST)_t; match(_t,ROOT); _t = _t.getFirstChild(); code=element(_t,label,tmp39_AST_in); _t = _retTree; _t = __t61; _t = _t.getNextSibling(); break; } case BANG: { AST __t62 = _t; GrammarAST tmp40_AST_in = (GrammarAST)_t; match(_t,BANG); _t = _t.getFirstChild(); code=element(_t,label,tmp40_AST_in); _t = _retTree; _t = __t62; _t = _t.getNextSibling(); break; } case NOT: { AST __t63 = _t; n = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,NOT); _t = _t.getFirstChild(); code=notElement(_t,n, label, astSuffix); _t = _retTree; _t = __t63; _t = _t.getNextSibling(); break; } case ASSIGN: { AST __t64 = _t; GrammarAST tmp41_AST_in = (GrammarAST)_t; match(_t,ASSIGN); _t = _t.getFirstChild(); alabel = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); code=element(_t,alabel,astSuffix); _t = _retTree; _t = __t64; _t = _t.getNextSibling(); break; } case PLUS_ASSIGN: { AST __t65 = _t; GrammarAST tmp42_AST_in = (GrammarAST)_t; match(_t,PLUS_ASSIGN); _t = _t.getFirstChild(); label2 = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); code=element(_t,label2,astSuffix); _t = _retTree;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -