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);
}
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);
}
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"));
}
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)\""));
}
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]"));
}
Aggregations