//throws RecognitionException public Object attribute(AST _t) { Object value=null; antlr.stringtemplate.language.StringTemplateAST attribute_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t; antlr.stringtemplate.language.StringTemplateAST prop = null; antlr.stringtemplate.language.StringTemplateAST i3 = null; antlr.stringtemplate.language.StringTemplateAST i = null; antlr.stringtemplate.language.StringTemplateAST s = null; antlr.stringtemplate.language.StringTemplateAST at = null; Object obj = null; String propName = null; Object e = null; try { // for error handling if (null == _t) _t = ASTNULL; switch ( _t.Type ) { case DOT: { AST __t33 = _t; antlr.stringtemplate.language.StringTemplateAST tmp6_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,DOT); _t = _t.getFirstChild(); obj=expr(_t); _t = retTree_; { if (null == _t) _t = ASTNULL; switch ( _t.Type ) { case ID: { prop = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,ID); _t = _t.getNextSibling(); propName = prop.getText(); break; } case VALUE: { AST __t35 = _t; antlr.stringtemplate.language.StringTemplateAST tmp7_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,VALUE); _t = _t.getFirstChild(); e=expr(_t); _t = retTree_; _t = __t35; _t = _t.getNextSibling(); if (e!=null) {propName=e.ToString();} break; } default: { throw new NoViableAltException(_t); } } } _t = __t33; _t = _t.getNextSibling(); value = chunk.getObjectProperty(self,obj,propName); break; } case ID: { i3 = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,ID); _t = _t.getNextSibling(); value=self.getAttribute(i3.getText()); break; } case INT: { i = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,INT); _t = _t.getNextSibling(); value=Int32.Parse(i.getText()); break; } case STRING: { s = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,STRING); _t = _t.getNextSibling(); value=s.getText(); break; } case ANONYMOUS_TEMPLATE: { at = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t; match((AST)_t,ANONYMOUS_TEMPLATE); _t = _t.getNextSibling(); value=at.getText(); if ( at.getText()!=null ) { StringTemplate valueST =new StringTemplate(self.getGroup(), at.getText()); valueST.setEnclosingInstance(self); valueST.setName("<anonymous template argument>"); value = valueST; } break; } default: { throw new NoViableAltException(_t); } } } catch (RecognitionException ex) { reportError(ex); if (null != _t) { _t = _t.getNextSibling(); } } retTree_ = _t; return value; }
/// <summary> /// Evaluate an argument list within the context of the enclosing /// template but store the values in the context of self, the /// new embedded template. For example, bold(item=item) means /// that bold.item should get the value of enclosing.item. /// </summary> protected internal virtual void evaluateArguments(StringTemplate self) { StringTemplateAST argumentsAST = self.getArgumentsAST(); if (argumentsAST == null || argumentsAST.getFirstChild() == null) { // return immediately if missing tree or no actual args return ; } // Evaluate args in the context of the enclosing template, but we // need the predefined args like 'it', 'attr', and 'i' to be // available as well so we put a dummy ST between the enclosing // context and the embedded context. The dummy has the predefined // context as does the embedded. StringTemplate enclosing = self.getEnclosingInstance(); StringTemplate argContextST = new StringTemplate(self.getGroup(), ""); argContextST.setName("<invoke "+self.getName()+" arg context>"); argContextST.setEnclosingInstance(enclosing); argContextST.setArgumentContext(self.getArgumentContext()); ActionEvaluator eval = new ActionEvaluator(argContextST, this, null); try { // using any initial argument context (such as when obj is set), // evaluate the arg list like bold(item=obj). Since we pass // in any existing arg context, that context gets filled with // new values. With bold(item=obj), context becomes: // {[obj=...],[item=...]}. IDictionary ac = eval.argList(argumentsAST, self, self.getArgumentContext()); self.setArgumentContext(ac); } catch (RecognitionException re) { self.error("can't evaluate tree: " + argumentsAST.ToStringList(), re); } }