use of org.beetl.core.statement.Expression 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;
}
use of org.beetl.core.statement.Expression in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseTextOutputSt.
protected Statement parseTextOutputSt(TextOutputStContext ctx) {
TextStatmentContext tsc = ctx.textStatment();
FormatExpression format = null;
boolean isSafe = false;
if (tsc.NOT() != null) {
isSafe = true;
}
TextVarContext tvc = tsc.textVar();
if (tvc.COMMA() != null) {
String formatName = null;
String pattern = null;
String tokenName = null;
int line = 0;
TextformatContext tfc = tvc.textformat();
TerminalNode node = tfc.StringLiteral();
if (node != null) {
tokenName = pattern = getStringValue(node.getText());
line = node.getSymbol().getLine();
}
FunctionNsContext fnsc = tfc.functionNs();
if (fnsc != null) {
List<TerminalNode> listId = fnsc.Identifier();
formatName = this.getID(listId);
tokenName = formatName;
line = listId.get(0).getSymbol().getLine();
}
format = new FormatExpression(formatName, pattern, org.beetl.core.statement.GrammarToken.createToken(tokenName, line));
}
Expression exp = this.parseExpress(tvc.expression());
if (isSafe) {
SafePlaceholderST placeholder = new SafePlaceholderST(exp, format, null);
return placeholder;
} else {
PlaceholderST placeholder = new PlaceholderST(exp, format, null);
return placeholder;
}
}
use of org.beetl.core.statement.Expression in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseSwitch.
protected SwitchStatement parseSwitch(SiwchStContext sctx) {
// this.pbCtx.enterBlock();
// this.pbCtx.current.canStopContinueBreakFlag = true;
ExpressionContext ect = sctx.parExpression().expression();
Expression exp = this.parseExpress(ect);
List<SwitchBlockStatementGroupContext> list = sctx.switchBlock().switchBlockStatementGroup();
LinkedHashMap<Expression, BlockStatement> condtionsStatementsMap = new LinkedHashMap<Expression, BlockStatement>();
List<Expression> conditionList = new ArrayList<Expression>();
BlockStatement defaultBlock = null;
for (SwitchBlockStatementGroupContext group : list) {
List<SwitchLabelContext> labels = group.switchLabel();
List<StatementContext> stats = group.statement();
BlockStatement block = stats != null ? this.parseBlock(stats, group) : null;
for (SwitchLabelContext label : labels) {
Expression caseExp = this.parseExpress(label.expression());
if (caseExp == null) {
// default
defaultBlock = block;
break;
} else {
conditionList.add(caseExp);
condtionsStatementsMap.put(caseExp, block);
}
}
}
SwitchStatement switchStat = new SwitchStatement(exp, condtionsStatementsMap, defaultBlock, this.getBTToken(sctx.getStart()));
return switchStat;
}
use of org.beetl.core.statement.Expression in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseSelect.
protected SelectStatement parseSelect(SelectStContext selectCtx) {
// this.pbCtx.enterBlock();
// this.pbCtx.current.canStopContinueBreakFlag = true;
G_switchStatmentContext ctx = selectCtx.g_switchStatment();
ExpressionContext exp = ctx.expression();
Expression base = exp != null ? this.parseExpress(exp) : null;
List<G_caseStatmentContext> caseCtxList = ctx.g_caseStatment();
List<Expression> condtionList = new LinkedList<Expression>();
List<BlockStatement> blockList = new LinkedList<BlockStatement>();
for (G_caseStatmentContext caseCtx : caseCtxList) {
List<ExpressionContext> expCtxList = caseCtx.expression();
List<StatementContext> statCtxList = caseCtx.statement();
BlockStatement block = this.parseBlock(statCtxList, caseCtx);
for (ExpressionContext expCtx : expCtxList) {
Expression condition = this.parseExpress(expCtx);
// select case 的条件是||的关系,只要任何一个条件满足,都可以执行block
condtionList.add(condition);
blockList.add(block);
}
}
BlockStatement defaultStatement = null;
G_defaultStatmentContext defaultCtx = ctx.g_defaultStatment();
if (defaultCtx != null) {
List<StatementContext> defaultCtxList = ctx.g_defaultStatment().statement();
defaultStatement = this.parseBlock(defaultCtxList, ctx);
}
SelectStatement select = new SelectStatement(base, condtionList.toArray(new Expression[0]), blockList.toArray(new BlockStatement[0]), defaultStatement, this.getBTToken(selectCtx.Select().getSymbol()));
return select;
}
use of org.beetl.core.statement.Expression in project beetl2.0 by javamonkey.
the class AntlrProgramBuilder method parseNotExpression.
protected NotBooleanExpression parseNotExpression(NotExpContext ctx) {
Expression exp = this.parseExpress(ctx.expression());
NotBooleanExpression notExp = new NotBooleanExpression(exp, this.getBTToken(ctx.NOT().getSymbol()));
return notExp;
}
Aggregations