Search in sources :

Example 31 with BaseNode

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

the class FEELParserTest method parse.

private BaseNode parse(String input, Map<String, Type> inputTypes) {
    FEEL_1_1Parser parser = FEELParser.parse(null, input, inputTypes, Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
    ParseTree tree = parser.expression();
    ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes);
    BaseNode expr = v.visit(tree);
    return expr;
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 32 with BaseNode

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

the class FEELParserTest method testAdd1.

@Test
public void testAdd1() {
    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 add = (InfixOpNode) infix;
    assertThat(add.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(add.getLeft().getText(), is("y"));
    assertThat(add.getOperator(), is(InfixOpNode.InfixOperator.ADD));
    assertThat(add.getRight(), is(instanceOf(InfixOpNode.class)));
    assertThat(add.getRight().getText(), is("5 * 3"));
    InfixOpNode mult = (InfixOpNode) add.getRight();
    assertThat(mult.getLeft(), is(instanceOf(NumberNode.class)));
    assertThat(mult.getLeft().getText(), is("5"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(mult.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 33 with BaseNode

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

the class FEELImpl method compileExpressionList.

public CompiledExpression compileExpressionList(String expression, CompilerContext ctx) {
    FEEL_1_1Parser parser = FEELParser.parse(getEventsManager(ctx.getListeners()), expression, ctx.getInputVariableTypes(), ctx.getInputVariables(), ctx.getFEELFunctions(), profiles);
    ParseTree tree = parser.expressionList();
    ASTBuilderVisitor v = new ASTBuilderVisitor(ctx.getInputVariableTypes());
    BaseNode expr = v.visit(tree);
    CompiledExpression ce = new CompiledExpressionImpl(expr);
    return ce;
}
Also used : ASTBuilderVisitor(org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FEEL_1_1Parser(org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser) ParseTree(org.antlr.v4.runtime.tree.ParseTree) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression)

Example 34 with BaseNode

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

the class FEELParserTest method testBooleanTrueLiteral.

@Test
public void testBooleanTrueLiteral() {
    String inputExpression = "true";
    BaseNode bool = parse(inputExpression);
    assertThat(bool, is(instanceOf(BooleanNode.class)));
    assertThat(bool.getResultType(), is(BuiltInType.BOOLEAN));
    assertLocation(inputExpression, bool);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 35 with BaseNode

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

the class FEELParserTest method testNameReference.

@Test
public void testNameReference() {
    String inputExpression = "someSimpleName";
    BaseNode nameRef = parse(inputExpression, mapOf(entry("someSimpleName", BuiltInType.STRING)));
    assertThat(nameRef, is(instanceOf(NameRefNode.class)));
    assertThat(nameRef.getResultType(), is(BuiltInType.STRING));
    assertLocation(inputExpression, nameRef);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

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