Search in sources :

Example 1 with TypeContext

use of org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser.TypeContext in project drools by kiegroup.

the class ASTBuilderVisitor method visitContextType.

@Override
public BaseNode visitContextType(FEEL_1_1Parser.ContextTypeContext ctx) {
    List<String> pNames = new ArrayList<>();
    for (TerminalNode id : ctx.Identifier()) {
        pNames.add(id.getText());
    }
    if (!pNames.get(0).equals("context")) {
        throw new IllegalStateException("grammar rule changed.");
    } else {
        pNames.remove(0);
    }
    List<TypeNode> pTypes = new ArrayList<>();
    for (TypeContext t : ctx.type()) {
        pTypes.add((TypeNode) visit(t));
    }
    Map<String, TypeNode> gens = new HashMap<>();
    for (int i = 0; i < pNames.size(); i++) {
        gens.put(pNames.get(i), pTypes.get(i));
    }
    return new ContextTypeNode(ctx, gens);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListTypeNode(org.kie.dmn.feel.lang.ast.ListTypeNode) TypeNode(org.kie.dmn.feel.lang.ast.TypeNode) ContextTypeNode(org.kie.dmn.feel.lang.ast.ContextTypeNode) FunctionTypeNode(org.kie.dmn.feel.lang.ast.FunctionTypeNode) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) TypeContext(org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser.TypeContext) ContextTypeNode(org.kie.dmn.feel.lang.ast.ContextTypeNode)

Example 2 with TypeContext

use of org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser.TypeContext in project drools by kiegroup.

the class ASTBuilderVisitor method visitFunctionType.

@Override
public BaseNode visitFunctionType(FEEL_1_1Parser.FunctionTypeContext ctx) {
    List<TypeNode> argTypes = new ArrayList<>();
    for (TypeContext t : ctx.type()) {
        argTypes.add((TypeNode) visit(t));
    }
    TypeNode type = argTypes.remove(argTypes.size() - 1);
    return new FunctionTypeNode(ctx, argTypes, type);
}
Also used : FunctionTypeNode(org.kie.dmn.feel.lang.ast.FunctionTypeNode) ArrayList(java.util.ArrayList) ListTypeNode(org.kie.dmn.feel.lang.ast.ListTypeNode) TypeNode(org.kie.dmn.feel.lang.ast.TypeNode) ContextTypeNode(org.kie.dmn.feel.lang.ast.ContextTypeNode) FunctionTypeNode(org.kie.dmn.feel.lang.ast.FunctionTypeNode) TypeContext(org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser.TypeContext)

Aggregations

ArrayList (java.util.ArrayList)2 ContextTypeNode (org.kie.dmn.feel.lang.ast.ContextTypeNode)2 FunctionTypeNode (org.kie.dmn.feel.lang.ast.FunctionTypeNode)2 ListTypeNode (org.kie.dmn.feel.lang.ast.ListTypeNode)2 TypeNode (org.kie.dmn.feel.lang.ast.TypeNode)2 TypeContext (org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser.TypeContext)2 HashMap (java.util.HashMap)1 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1