use of org.beetl.core.parser.BeetlParser.AssignIdContext in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseAssign.
/**
* 定义变量
* @param amc
* @return
*/
protected VarAssignStatement parseAssign(AssignMentContext amc) {
VarAssignStatement vas = null;
if (amc instanceof AssignGeneralInStContext) {
AssignGeneralInStContext agc = (AssignGeneralInStContext) amc;
ExpressionContext expCtx = agc.generalAssignExp().expression();
Expression exp = parseExpress(expCtx);
VarRefContext varRefCtx = agc.generalAssignExp().varRef();
if (varRefCtx.children.size() == 1) {
// var a=1;
Token token = varRefCtx.Identifier().getSymbol();
vas = new VarAssignStatement(exp, getBTToken(token));
} else {
// var a.b=1 since 2.7.0
VarRef ref = this.parseVarRefInLeftExpression(varRefCtx);
vas = new VarRefAssignStatement(exp, ref);
}
return vas;
} else if (amc instanceof AssignIdContext) {
AssignIdContext idCtx = (AssignIdContext) amc;
vas = new VarAssignStatement(Literal.NULLLiteral, getBTToken(idCtx.Identifier().getSymbol()));
return vas;
} else if (amc instanceof AssignTemplateVarContext) {
AssignTemplateVarContext templateVarCtx = (AssignTemplateVarContext) amc;
BlockContext blockCtx = templateVarCtx.block();
BlockStatement block = this.parseBlock(blockCtx.statement(), blockCtx);
ContentBodyExpression bodyExp = new ContentBodyExpression(block, getBTToken(templateVarCtx.Identifier().getSymbol()));
vas = new VarAssignStatement(bodyExp, getBTToken(templateVarCtx.Identifier().getSymbol()));
} else {
throw new RuntimeException("不支持 在 " + amc.start.getLine());
}
return vas;
}
Aggregations