//throws RecognitionException, TokenStreamException public void template( StringTemplate self ) { IToken s = null; IToken nl = null; this.self = self; try { // for error handling { // ( ... )* for (;;) { switch ( LA(1) ) { case LITERAL: { s = LT(1); match(LITERAL); self.addChunk(new StringRef(self,s.getText())); break; } case NEWLINE: { nl = LT(1); match(NEWLINE); if ( LA(1)!=ELSE && LA(1)!=ENDIF ) { self.addChunk(new NewlineRef(self,nl.getText())); } break; } case ACTION: case IF: { action(self); break; } default: { goto _loop3_breakloop; } } } _loop3_breakloop: ; } // ( ... )* } catch (RecognitionException ex) { reportError(ex); recover(ex,tokenSet_0_); } }
//throws RecognitionException, TokenStreamException public void action( StringTemplate self ) { IToken a = null; IToken i = null; try { // for error handling switch ( LA(1) ) { case ACTION: { a = LT(1); match(ACTION); String indent = ((ChunkToken)a).getIndentation(); ASTExpr c = self.parseAction(a.getText()); c.setIndentation(indent); self.addChunk(c); break; } case IF: { i = LT(1); match(IF); ConditionalExpr c = (ConditionalExpr)self.parseAction(i.getText()); // create and precompile the subtemplate StringTemplate subtemplate = new StringTemplate(self.getGroup(), null); subtemplate.setEnclosingInstance(self); subtemplate.setName(i.getText()+" subtemplate"); self.addChunk(c); template(subtemplate); if ( c!=null ) c.setSubtemplate(subtemplate); { switch ( LA(1) ) { case ELSE: { match(ELSE); // create and precompile the subtemplate StringTemplate elseSubtemplate = new StringTemplate(self.getGroup(), null); elseSubtemplate.setEnclosingInstance(self); elseSubtemplate.setName("else subtemplate"); template(elseSubtemplate); if ( c!=null ) c.setElseSubtemplate(elseSubtemplate); break; } case ENDIF: { break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } match(ENDIF); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } catch (RecognitionException ex) { reportError(ex); recover(ex,tokenSet_1_); } }