Search in sources :

Example 1 with TextformatContext

use of org.beetl.core.parser.BeetlParser.TextformatContext 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;
    }
}
Also used : SafePlaceholderST(org.beetl.core.statement.SafePlaceholderST) PlaceholderST(org.beetl.core.statement.PlaceholderST) SafePlaceholderST(org.beetl.core.statement.SafePlaceholderST) TextformatContext(org.beetl.core.parser.BeetlParser.TextformatContext) ContentBodyExpression(org.beetl.core.statement.ContentBodyExpression) ArthExpression(org.beetl.core.statement.ArthExpression) JsonMapExpression(org.beetl.core.statement.JsonMapExpression) CompareExpression(org.beetl.core.statement.CompareExpression) FunctionExpression(org.beetl.core.statement.FunctionExpression) IncDecExpression(org.beetl.core.statement.IncDecExpression) Expression(org.beetl.core.statement.Expression) AndExpression(org.beetl.core.statement.AndExpression) StatementExpression(org.beetl.core.statement.StatementExpression) NativeCallExpression(org.beetl.core.statement.NativeCallExpression) NegExpression(org.beetl.core.statement.NegExpression) FormatExpression(org.beetl.core.statement.FormatExpression) TernaryExpression(org.beetl.core.statement.TernaryExpression) OrExpression(org.beetl.core.statement.OrExpression) JsonArrayExpression(org.beetl.core.statement.JsonArrayExpression) NotBooleanExpression(org.beetl.core.statement.NotBooleanExpression) TextVarContext(org.beetl.core.parser.BeetlParser.TextVarContext) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) FunctionNsContext(org.beetl.core.parser.BeetlParser.FunctionNsContext) FormatExpression(org.beetl.core.statement.FormatExpression) ConstantsTextStatmentContext(org.beetl.core.parser.BeetlParser.ConstantsTextStatmentContext) TextStatmentContext(org.beetl.core.parser.BeetlParser.TextStatmentContext)

Aggregations

TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1 ConstantsTextStatmentContext (org.beetl.core.parser.BeetlParser.ConstantsTextStatmentContext)1 FunctionNsContext (org.beetl.core.parser.BeetlParser.FunctionNsContext)1 TextStatmentContext (org.beetl.core.parser.BeetlParser.TextStatmentContext)1 TextVarContext (org.beetl.core.parser.BeetlParser.TextVarContext)1 TextformatContext (org.beetl.core.parser.BeetlParser.TextformatContext)1 AndExpression (org.beetl.core.statement.AndExpression)1 ArthExpression (org.beetl.core.statement.ArthExpression)1 CompareExpression (org.beetl.core.statement.CompareExpression)1 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)1 Expression (org.beetl.core.statement.Expression)1 FormatExpression (org.beetl.core.statement.FormatExpression)1 FunctionExpression (org.beetl.core.statement.FunctionExpression)1 IncDecExpression (org.beetl.core.statement.IncDecExpression)1 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)1 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)1 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)1 NegExpression (org.beetl.core.statement.NegExpression)1 NotBooleanExpression (org.beetl.core.statement.NotBooleanExpression)1 OrExpression (org.beetl.core.statement.OrExpression)1