📄 codegentreewalker.java
字号:
GrammarAST a = null; // TODO: can we use Rule.altsWithRewrites??? if ( blockNestingLevel==RULE_BLOCK_NESTING_LEVEL ) { GrammarAST aRewriteNode = alternative_AST_in.findFirstType(REWRITE); if ( grammar.buildAST() && (aRewriteNode!=null|| (alternative_AST_in.getNextSibling()!=null && alternative_AST_in.getNextSibling().getType()==REWRITE)) ) { currentAltHasASTRewrite = true; } else { currentAltHasASTRewrite = false; } } 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 __t58 = _t; a = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,ALT); _t = _t.getFirstChild(); { int _cnt60=0; _loop60: 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()==SET||_t.getType()==GATED_SEMPRED||_t.getType()==SYN_SEMPRED||_t.getType()==ACTION||_t.getType()==ASSIGN||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF||_t.getType()==PLUS_ASSIGN||_t.getType()==SEMPRED||_t.getType()==NOT||_t.getType()==TREE_BEGIN||_t.getType()==RULE_REF||_t.getType()==WILDCARD)) { GrammarAST elAST=(GrammarAST)_t; e=element(_t); _t = _retTree; if ( e!=null ) { code.setAttribute("elements.{el,line,pos}", e, Utils.integer(elAST.getLine()), Utils.integer(elAST.getColumn()) ); } } else { if ( _cnt60>=1 ) { break _loop60; } else {throw new NoViableAltException(_t);} } _cnt60++; } while (true); } GrammarAST tmp33_AST_in = (GrammarAST)_t; match(_t,EOA); _t = _t.getNextSibling(); _t = __t58; _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)); currentBlockST = code; } } try { // for error handling { _loop121: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==REWRITE)) { rewriteRuleRefs = new HashSet(); AST __t119 = _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 = __t119; _t = _t.getNextSibling(); rewriteBlockNestingLevel = OUTER_REWRITE_NESTING_LEVEL; List predChunks = null; if ( pred!=null ) { //predText = #pred.getText(); pred.outerAltNum = this.outerAltNum; 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 _loop121; } } while (true); } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return code; } public final void exceptionSpec(AST _t, StringTemplate ruleST ) throws RecognitionException { GrammarAST exceptionSpec_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling AST __t51 = _t; GrammarAST tmp34_AST_in = (GrammarAST)_t; match(_t,LITERAL_exception); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case ARG_ACTION: { GrammarAST tmp35_AST_in = (GrammarAST)_t; match(_t,ARG_ACTION); _t = _t.getNextSibling(); break; } case 3: case LITERAL_catch: { break; } default: { throw new NoViableAltException(_t); } } } { _loop54: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==LITERAL_catch)) { exceptionHandler(_t,ruleST); _t = _retTree; } else { break _loop54; } } while (true); } _t = __t51; _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; } public final void exceptionHandler(AST _t, StringTemplate ruleST ) throws RecognitionException { GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; try { // for error handling AST __t56 = _t; GrammarAST tmp36_AST_in = (GrammarAST)_t; match(_t,LITERAL_catch); _t = _t.getFirstChild(); GrammarAST tmp37_AST_in = (GrammarAST)_t; match(_t,ARG_ACTION); _t = _t.getNextSibling(); GrammarAST tmp38_AST_in = (GrammarAST)_t; match(_t,ACTION); _t = _t.getNextSibling(); _t = __t56; _t = _t.getNextSibling(); List chunks = generator.translateAction(currentRuleName,tmp38_AST_in); ruleST.setAttribute("exceptions.{decl,action}",tmp37_AST_in.getText(),chunks); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; } public final StringTemplate element(AST _t) throws RecognitionException { StringTemplate code=null; GrammarAST element_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST n = null; GrammarAST c = null; GrammarAST ast1 = null; GrammarAST s = null; GrammarAST ast2 = null; GrammarAST t = null; GrammarAST ast3 = null; GrammarAST st = null; GrammarAST ast4 = null; GrammarAST a = null; GrammarAST b = null; GrammarAST label = null; GrammarAST assign_n = null; GrammarAST assign_c = null; GrammarAST assign_ast1 = null; GrammarAST assign_s = null; GrammarAST assign_ast2 = null; GrammarAST assign_t = null; GrammarAST assign_ast3 = null; GrammarAST assign_st = null; GrammarAST assign_ast4 = null; GrammarAST label2 = null; GrammarAST act = 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 SET: case STRING_LITERAL: case CHAR_LITERAL: case TOKEN_REF: case RULE_REF: case WILDCARD: { code=atom(_t,null); _t = _retTree; break; } case NOT: { AST __t62 = _t; n = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,NOT); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case CHAR_LITERAL: { AST __t64 = _t; c = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,CHAR_LITERAL); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case BANG: case ROOT: case RULEROOT: { ast1 = _t==ASTNULL ? null : (GrammarAST)_t; ast_suffix(_t); _t = _retTree; break; } case 3: { break; } default: { throw new NoViableAltException(_t); } } } _t = __t64; _t = _t.getNextSibling(); int ttype=0; if ( grammar.type==Grammar.LEXER ) { ttype = Grammar.getCharValueFromGrammarCharLiteral(c.getText()); } else { ttype = grammar.getTokenType(c.getText()); } elements = grammar.complement(ttype); ast = ast1; break; } case STRING_LITERAL: { AST __t66 = _t; s = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,STRING_LITERAL); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case BANG: case ROOT: case RULEROOT: { ast2 = _t==ASTNULL ? null : (GrammarAST)_t; ast_suffix(_t); _t = _retTree; break; } case 3: { break; } default: { throw new NoViableAltException(_t); } } } _t = __t66; _t = _t.getNextSibling(); int ttype=0; if ( grammar.type==Grammar.LEXER ) { // TODO: error! } else { ttype = grammar.getTokenType(s.getText()); } elements = grammar.complement(ttype); ast = ast2; break; } case TOKEN_REF: { AST __t68 = _t; t = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,TOKEN_REF); _t = _t.getFirstChild(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case BANG: case ROOT: case RULEROOT: { ast3 = _t==ASTNULL ? null : (GrammarAST)_t; ast_suffix(_t); _t = _retTree; break; } case 3: { break; } default: { throw new NoViableAltException(_t); } } } _t = __t68; _t = _t.getNextSibling(); int ttype = grammar.getTokenType(t.getText()); elements = grammar.complement(ttype); ast = ast3; break; } case SET: { AST __t70 = _t; st = _t==ASTNULL ? null :(GrammarAST)_t; match(_t,SET); _t = _t.getFirstChild(); { int _cnt72=0; _loop72: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==CHAR_RANGE||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF)) { setElement(_t); _t = _retTree; } else { if ( _cnt72>=1 ) { break _loop72; } else {throw new NoViableAltException(_t);} } _cnt72++; } while (true); } { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case BANG: case ROOT: case RULEROOT: { ast4 = _t==ASTNULL ? null : (GrammarAST)_t; ast_suffix(_t); _t = _retTree; break; } case 3: { break; } default: { throw new NoViableAltException(_t); } } } _t = __t70; _t = _t.getNextSibling(); // SETs are not precomplemented by buildnfa.g like // simple elements. elements = st.getSetValue(); ast = ast4; break; } default: { throw new NoViableAltException(_t); } } } code = getTokenElementST("matchSet", "set", (GrammarAST)n.getFirstChild(), ast, null); code.setAttribute("s", generator.genSetExpr(templates,elements,1,false)); code.setAttribute("elementIndex", ((TokenWithIndex)n.getToken()).getIndex()); if ( grammar.type!=Grammar.LEXER ) { generator.generateLocalFOLLOW(n,"set",currentRuleName); } _t = __t62; _t = _t.getNextSibling(); break; } case CHAR_RANGE: { AST __t74 = _t; GrammarAST tmp39_AST_in = (GrammarAST)_t; match(_t,CHAR_RANGE); _t = _t.getFirstChild(); a = (GrammarAST)_t; match(_t,CHAR_LITERAL); _t = _t.getNextSibling(); b = (GrammarAST)_t; match(_t,CHAR_LITERAL); _t = _t.getNextSibling(); _t = __t74; _t = _t.getNextSibling(); code = templates.getInstanceOf("charRangeRef"); String low = generator.target.getTargetCharLiteralFromANTLRCharLiteral(generator,a.getText()); String high = generator.target.getTargetCharLiteralFromANTLRCharLiteral(generator,b.getText()); code.setAttribute("a", low); code.setAttribute("b", high); break; } case ASSIGN: { AST __t75 = _t; GrammarAST tmp40_AST_in = (GrammarAST)_t; match(_t,ASSIGN); _t = _t.getFirstChild(); label = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); { if (_t==null) _t=ASTNULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -