Search in sources :

Example 1 with DirectiveStatement

use of org.beetl.core.statement.DirectiveStatement in project beetl2.0 by javamonkey.

the class AntlrProgramBuilder method parseDirectiveStatement.

/**
 * directive dynamic xxx,yy
 * @param node
 * @return
 */
protected DirectiveStatement parseDirectiveStatement(DirectiveStContext node) {
    DirectiveStContext stContext = (DirectiveStContext) node;
    DirectiveExpContext direExp = stContext.directiveExp();
    Token token = direExp.Identifier().getSymbol();
    String directive = token.getText().toLowerCase().intern();
    TerminalNode value = direExp.StringLiteral();
    List<TerminalNode> idNodeList = null;
    DirectiveExpIDListContext directExpidLisCtx = direExp.directiveExpIDList();
    if (directExpidLisCtx != null) {
        idNodeList = directExpidLisCtx.Identifier();
    }
    Set<String> idList = null;
    DirectiveStatement ds = null;
    if (value != null) {
        String idListValue = this.getStringValue(value.getText());
        idList = new HashSet(Arrays.asList(idListValue.split(",")));
        ds = new DirectiveStatement(directive, idList, this.getBTToken(token));
    } else if (idNodeList != null) {
        idList = new HashSet<String>();
        for (TerminalNode t : idNodeList) {
            idList.add(t.getText());
        }
        ds = new DirectiveStatement(directive, idList, this.getBTToken(token));
    } else {
        ds = new DirectiveStatement(directive, Collections.EMPTY_SET, this.getBTToken(token));
    }
    if (directive.equals("dynamic")) {
        if (ds.getIdList().size() == 0) {
            data.allDynamic = true;
        } else {
            data.dynamicObjectSet = ds.getIdList();
        }
        ds = new DirectiveStatement(directive, Collections.EMPTY_SET, this.getBTToken(token));
        return ds;
    } else if (directive.equalsIgnoreCase("safe_output_open".intern())) {
        this.pbCtx.isSafeOutput = true;
        return ds;
    } else if (directive.equalsIgnoreCase("safe_output_close".intern())) {
        this.pbCtx.isSafeOutput = false;
        return ds;
    } else {
        return ds;
    }
}
Also used : DirectiveStContext(org.beetl.core.parser.BeetlParser.DirectiveStContext) DirectiveExpIDListContext(org.beetl.core.parser.BeetlParser.DirectiveExpIDListContext) Token(org.antlr.v4.runtime.Token) GrammarToken(org.beetl.core.statement.GrammarToken) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) DirectiveExpContext(org.beetl.core.parser.BeetlParser.DirectiveExpContext) DirectiveStatement(org.beetl.core.statement.DirectiveStatement) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Token (org.antlr.v4.runtime.Token)1 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1 DirectiveExpContext (org.beetl.core.parser.BeetlParser.DirectiveExpContext)1 DirectiveExpIDListContext (org.beetl.core.parser.BeetlParser.DirectiveExpIDListContext)1 DirectiveStContext (org.beetl.core.parser.BeetlParser.DirectiveStContext)1 DirectiveStatement (org.beetl.core.statement.DirectiveStatement)1 GrammarToken (org.beetl.core.statement.GrammarToken)1