Search in sources :

Example 1 with NameDefNode

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

the class ASTBuilderVisitor method visitNamedParameter.

@Override
public BaseNode visitNamedParameter(FEEL_1_1Parser.NamedParameterContext ctx) {
    NameDefNode name = (NameDefNode) visit(ctx.name);
    BaseNode value = visit(ctx.value);
    return ASTBuilderFactory.newNamedParameterNode(ctx, name, value);
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode)

Example 2 with NameDefNode

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

the class ASTBuilderVisitor method visitFormalParameter.

@Override
public BaseNode visitFormalParameter(FEEL_1_1Parser.FormalParameterContext ctx) {
    NameDefNode name = (NameDefNode) visit(ctx.nameDefinition());
    TypeNode type = ctx.type() != null ? (TypeNode) visit(ctx.type()) : null;
    return ASTBuilderFactory.newFormalParameter(ctx, name, type);
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) 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)

Example 3 with NameDefNode

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

the class FEELParserTest method testNestedContexts2.

@Test
public void testNestedContexts2() {
    String inputExpression = "{ an applicant : { " + "    home address : {" + "        street name: \"broadway st\"," + "        city : \"New York\" " + "    } " + " },\n " + " street : an applicant.home address.street name \n" + "}";
    BaseNode ctxbase = parse(inputExpression);
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(2));
    ContextEntryNode entry = ctx.getEntries().get(1);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.STRING));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getText(), is("street"));
    assertThat(entry.getValue(), is(instanceOf(QualifiedNameNode.class)));
    QualifiedNameNode qnn = (QualifiedNameNode) entry.getValue();
    assertThat(qnn.getParts().get(0).getText(), is("an applicant"));
    assertThat(qnn.getParts().get(1).getText(), is("home address"));
    assertThat(qnn.getParts().get(2).getText(), is("street name"));
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Example 4 with NameDefNode

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

the class FEELParserTest method testExternalFunctionDefinition.

@Test
public void testExternalFunctionDefinition() {
    String inputExpression = "{ trigonometric cosine : function( angle ) external {" + "    java : {" + "        class : \"java.lang.Math\"," + "        method signature : \"cos(double)\"" + "    }" + "}}";
    BaseNode ctxbase = parse(inputExpression);
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(1));
    ContextEntryNode entry = ctx.getEntries().get(0);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getText(), is("trigonometric cosine"));
    assertThat(entry.getValue(), is(instanceOf(FunctionDefNode.class)));
    assertThat(entry.getValue().getText(), is("function( angle ) external {" + "    java : {" + "        class : \"java.lang.Math\"," + "        method signature : \"cos(double)\"" + "    }" + "}"));
    FunctionDefNode cos = (FunctionDefNode) entry.getValue();
    assertThat(cos.getFormalParameters().size(), is(1));
    assertThat(cos.getFormalParameters().get(0).getText(), is("angle"));
    assertThat(cos.isExternal(), is(true));
    assertThat(cos.getBody(), is(instanceOf(ContextNode.class)));
    ContextNode body = (ContextNode) cos.getBody();
    assertThat(body.getEntries().size(), is(1));
    ContextEntryNode java = body.getEntries().get(0);
    assertThat(java.getName().getText(), is("java"));
    assertThat(java.getValue(), is(instanceOf(ContextNode.class)));
    ContextNode def = (ContextNode) java.getValue();
    assertThat(def.getEntries().size(), is(2));
    assertThat(def.getEntries().get(0).getName().getText(), is("class"));
    assertThat(def.getEntries().get(0).getValue(), is(instanceOf(StringNode.class)));
    assertThat(def.getEntries().get(0).getValue().getText(), is("\"java.lang.Math\""));
    assertThat(def.getEntries().get(1).getName().getText(), is("method signature"));
    assertThat(def.getEntries().get(1).getValue(), is(instanceOf(StringNode.class)));
    assertThat(def.getEntries().get(1).getValue().getText(), is("\"cos(double)\""));
}
Also used : FunctionDefNode(org.kie.dmn.feel.lang.ast.FunctionDefNode) NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Example 5 with NameDefNode

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

the class FEELParserTest method testContextWithMultipleEntries.

@Test
public void testContextWithMultipleEntries() {
    String inputExpression = "{ \"a string key\" : 10," + " a non-string key : foo+bar," + " a key.with + /' odd chars : [10..50] }";
    BaseNode ctxbase = parse(inputExpression, mapOf(entry("foo", BuiltInType.NUMBER), entry("bar", BuiltInType.NUMBER)));
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(3));
    ContextEntryNode entry = ctx.getEntries().get(0);
    assertThat(entry.getName(), is(instanceOf(StringNode.class)));
    StringNode nameNode = (StringNode) entry.getName();
    assertThat(nameNode.getText(), is(notNullValue()));
    // Reference String literal test, BaseNode#getText() return the FEEL equivalent expression, in this case quoted.
    assertThat(nameNode.getText(), is("\"a string key\""));
    assertThat(entry.getValue(), is(instanceOf(NumberNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.NUMBER));
    assertThat(entry.getValue().getText(), is("10"));
    entry = ctx.getEntries().get(1);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getParts(), is(notNullValue()));
    assertThat(name.getParts().size(), is(5));
    assertThat(entry.getName().getText(), is("a non-string key"));
    assertThat(entry.getValue(), is(instanceOf(InfixOpNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.NUMBER));
    assertThat(entry.getValue().getText(), is("foo+bar"));
    entry = ctx.getEntries().get(2);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    name = (NameDefNode) entry.getName();
    assertThat(name.getParts(), is(notNullValue()));
    assertThat(name.getParts().size(), is(9));
    assertThat(entry.getName().getText(), is("a key.with + /' odd chars"));
    assertThat(entry.getValue(), is(instanceOf(RangeNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.RANGE));
    assertThat(entry.getValue().getText(), is("[10..50]"));
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) StringNode(org.kie.dmn.feel.lang.ast.StringNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Aggregations

NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)9 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)8 Test (org.junit.Test)6 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)6 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)6 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)6 FunctionDefNode (org.kie.dmn.feel.lang.ast.FunctionDefNode)2 ContextTypeNode (org.kie.dmn.feel.lang.ast.ContextTypeNode)1 FunctionTypeNode (org.kie.dmn.feel.lang.ast.FunctionTypeNode)1 ListTypeNode (org.kie.dmn.feel.lang.ast.ListTypeNode)1 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)1 StringNode (org.kie.dmn.feel.lang.ast.StringNode)1 TypeNode (org.kie.dmn.feel.lang.ast.TypeNode)1