Search in sources :

Example 41 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testComparisonInFixOp.

@Test
public void testComparisonInFixOp() {
    String inputExpression = "foo >= bar * 10";
    BaseNode infix = parse(inputExpression);
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode in = (InfixOpNode) infix;
    assertThat(in.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(in.getLeft().getText(), is("foo"));
    assertThat(in.getRight(), is(instanceOf(InfixOpNode.class)));
    assertThat(in.getRight().getText(), is("bar * 10"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 42 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELParserTest method testPower1.

@Test
public void testPower1() {
    String inputExpression = "y * 5 ** 3";
    BaseNode infix = parse(inputExpression, mapOf(entry("y", BuiltInType.NUMBER)));
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.NUMBER));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode mult = (InfixOpNode) infix;
    assertThat(mult.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(mult.getLeft().getText(), is("y"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(InfixOpNode.class)));
    assertThat(mult.getRight().getText(), is("5 ** 3"));
    InfixOpNode exp = (InfixOpNode) mult.getRight();
    assertThat(exp.getLeft(), is(instanceOf(NumberNode.class)));
    assertThat(exp.getLeft().getText(), is("5"));
    assertThat(exp.getOperator(), is(InfixOpNode.InfixOperator.POW));
    assertThat(exp.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(exp.getRight().getText(), is("3"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 43 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class ASTBuilderVisitor method visitAddExpression.

@Override
public BaseNode visitAddExpression(FEEL_1_1Parser.AddExpressionContext ctx) {
    BaseNode left = visit(ctx.additiveExpression());
    BaseNode right = visit(ctx.multiplicativeExpression());
    String op = ctx.op.getText();
    return ASTBuilderFactory.newInfixOpNode(ctx, left, op, right);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode)

Example 44 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class ASTBuilderVisitor method visitIterationContext.

@Override
public BaseNode visitIterationContext(FEEL_1_1Parser.IterationContextContext ctx) {
    NameDefNode name = (NameDefNode) visit(ctx.nameDefinition());
    BaseNode expr = visit(ctx.expression().get(0));
    if (ctx.expression().size() == 1) {
        return ASTBuilderFactory.newIterationContextNode(ctx, name, expr);
    } else {
        BaseNode rangeEndExpr = visit(ctx.expression().get(1));
        return ASTBuilderFactory.newIterationContextNode(ctx, name, expr, rangeEndExpr);
    }
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode)

Example 45 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class ASTBuilderVisitor method visitRelExpressionValueList.

@Override
public BaseNode visitRelExpressionValueList(FEEL_1_1Parser.RelExpressionValueListContext ctx) {
    BaseNode value = visit(ctx.val);
    BaseNode list = visit(ctx.expressionList());
    return ASTBuilderFactory.newInNode(ctx, value, list);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode)

Aggregations

BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)84 Test (org.junit.Test)54 ListNode (org.kie.dmn.feel.lang.ast.ListNode)12 InfixOpNode (org.kie.dmn.feel.lang.ast.InfixOpNode)11 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)7 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)7 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)7 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)6 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)6 PathExpressionNode (org.kie.dmn.feel.lang.ast.PathExpressionNode)4 SignedUnaryNode (org.kie.dmn.feel.lang.ast.SignedUnaryNode)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 InNode (org.kie.dmn.feel.lang.ast.InNode)3 InstanceOfNode (org.kie.dmn.feel.lang.ast.InstanceOfNode)3 RangeNode (org.kie.dmn.feel.lang.ast.RangeNode)3 ArrayList (java.util.ArrayList)2 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)2 FunctionDefNode (org.kie.dmn.feel.lang.ast.FunctionDefNode)2 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)2 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)2