@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)\"" ) ); }
public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry) { CharStream input = CharStreams.fromString(source); FEEL_1_1Lexer lexer = new FEEL_1_1Lexer( input ); CommonTokenStream tokens = new CommonTokenStream( lexer ); FEEL_1_1Parser parser = new FEEL_1_1Parser( tokens ); ParserHelper parserHelper = new ParserHelper(eventsManager); additionalFunctions.forEach(f -> parserHelper.getSymbolTable().getBuiltInScope().define(f.getSymbol())); parser.setHelper(parserHelper); parser.setErrorHandler( new FEELErrorHandler() ); parser.removeErrorListeners(); parser.addErrorListener( new FEELParserErrorListener( eventsManager ) ); defineVariables( inputVariableTypes, inputVariables, parser ); if (typeRegistry != null) { parserHelper.setTypeRegistry(typeRegistry); } return parser; }
FEELParser { public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry) { CharStream input = CharStreams.fromString(source); FEEL_1_1Lexer lexer = new FEEL_1_1Lexer( input ); CommonTokenStream tokens = new CommonTokenStream( lexer ); FEEL_1_1Parser parser = new FEEL_1_1Parser( tokens ); ParserHelper parserHelper = new ParserHelper(eventsManager); additionalFunctions.forEach(f -> parserHelper.getSymbolTable().getBuiltInScope().define(f.getSymbol())); parser.setHelper(parserHelper); parser.setErrorHandler( new FEELErrorHandler() ); parser.removeErrorListeners(); parser.addErrorListener( new FEELParserErrorListener( eventsManager ) ); defineVariables( inputVariableTypes, inputVariables, parser ); if (typeRegistry != null) { parserHelper.setTypeRegistry(typeRegistry); } return parser; } }
FEELParser { public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry) { CharStream input = CharStreams.fromString(source); FEEL_1_1Lexer lexer = new FEEL_1_1Lexer( input ); CommonTokenStream tokens = new CommonTokenStream( lexer ); FEEL_1_1Parser parser = new FEEL_1_1Parser( tokens ); ParserHelper parserHelper = new ParserHelper(eventsManager); additionalFunctions.forEach(f -> parserHelper.getSymbolTable().getBuiltInScope().define(f.getSymbol())); parser.setHelper(parserHelper); parser.setErrorHandler( new FEELErrorHandler() ); parser.removeErrorListeners(); parser.addErrorListener( new FEELParserErrorListener( eventsManager ) ); defineVariables( inputVariableTypes, inputVariables, parser ); if (typeRegistry != null) { parserHelper.setTypeRegistry(typeRegistry); } return parser; }  }
FEELParser { public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry) { CharStream input = CharStreams.fromString(source); FEEL_1_1Lexer lexer = new FEEL_1_1Lexer( input ); CommonTokenStream tokens = new CommonTokenStream( lexer ); FEEL_1_1Parser parser = new FEEL_1_1Parser( tokens ); ParserHelper parserHelper = new ParserHelper(eventsManager); additionalFunctions.forEach(f -> parserHelper.getSymbolTable().getBuiltInScope().define(f.getSymbol())); parser.setHelper(parserHelper); parser.setErrorHandler( new FEELErrorHandler() ); parser.removeErrorListeners(); parser.addErrorListener( new FEELParserErrorListener( eventsManager ) ); defineVariables( inputVariableTypes, inputVariables, parser ); if (typeRegistry != null) { parserHelper.setTypeRegistry(typeRegistry); } return parser; }  static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry); static boolean isVariableNamePartValid( String namePart, Scope scope ); static boolean isVariableNameValid( String source ); static List<FEELEvent> checkVariableName( String source ); static void defineVariables(Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, FEEL_1_1Parser parser); }
FEELParser { public static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry) { CharStream input = CharStreams.fromString(source); FEEL_1_1Lexer lexer = new FEEL_1_1Lexer( input ); CommonTokenStream tokens = new CommonTokenStream( lexer ); FEEL_1_1Parser parser = new FEEL_1_1Parser( tokens ); ParserHelper parserHelper = new ParserHelper(eventsManager); additionalFunctions.forEach(f -> parserHelper.getSymbolTable().getBuiltInScope().define(f.getSymbol())); parser.setHelper(parserHelper); parser.setErrorHandler( new FEELErrorHandler() ); parser.removeErrorListeners(); parser.addErrorListener( new FEELParserErrorListener( eventsManager ) ); defineVariables( inputVariableTypes, inputVariables, parser ); if (typeRegistry != null) { parserHelper.setTypeRegistry(typeRegistry); } return parser; }  static FEEL_1_1Parser parse(FEELEventListenersManager eventsManager, String source, Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, Collection<FEELFunction> additionalFunctions, List<FEELProfile> profiles, FEELTypeRegistry typeRegistry); static boolean isVariableNamePartValid( String namePart, Scope scope ); static boolean isVariableNameValid( String source ); static List<FEELEvent> checkVariableName( String source ); static void defineVariables(Map<String, Type> inputVariableTypes, Map<String, Object> inputVariables, FEEL_1_1Parser parser);  }