/// <summary> /// Registers lambda expression under the specified <paramref name="functionName"/>. /// </summary> /// <param name="functionName">Function name to register expression as.</param> /// <param name="lambdaExpression">Lambda expression to register.</param> /// <param name="variables">Variables dictionary that the function will be registered in.</param> public static void RegisterFunction(string functionName, string lambdaExpression, IDictionary variables) { AssertUtils.ArgumentHasText(functionName, "functionName"); AssertUtils.ArgumentHasText(lambdaExpression, "lambdaExpression"); ExpressionLexer lexer = new ExpressionLexer(new StringReader(lambdaExpression)); ExpressionParser parser = new SpringExpressionParser(lexer); try { parser.lambda(); } catch (TokenStreamRecognitionException ex) { throw new SyntaxErrorException(ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), lambdaExpression); } variables[functionName] = parser.getAST(); }
/// <summary> /// Initializes a new instance of the <see cref="Expression"/> class /// by parsing specified property expression string. /// </summary> /// <param name="expression">Property expression to parse.</param> internal static IExpression ParseProperty(string expression) { if (StringUtils.HasText(expression)) { ExpressionLexer lexer = new ExpressionLexer(new StringReader(expression)); ExpressionParser parser = new SpringExpressionParser(lexer); try { parser.property(); } catch (TokenStreamRecognitionException ex) { throw new SyntaxErrorException(ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression); } return((IExpression)parser.getAST()); } else { return(new Expression()); } }
/// <summary> /// Initializes a new instance of the <see cref="Expression"/> class /// by parsing specified property expression string. /// </summary> /// <param name="expression">Property expression to parse.</param> internal static IExpression ParseProperty( string expression ) { if (StringUtils.HasText( expression )) { ExpressionLexer lexer = new ExpressionLexer( new StringReader( expression ) ); ExpressionParser parser = new SpringExpressionParser( lexer ); try { parser.property(); } catch (TokenStreamRecognitionException ex) { throw new SyntaxErrorException( ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), expression ); } return (IExpression)parser.getAST(); } else { return new Expression(); } }
/// <summary> /// Registers lambda expression under the specified <paramref name="functionName"/>. /// </summary> /// <param name="functionName">Function name to register expression as.</param> /// <param name="lambdaExpression">Lambda expression to register.</param> /// <param name="variables">Variables dictionary that the function will be registered in.</param> public static void RegisterFunction( string functionName, string lambdaExpression, IDictionary variables ) { AssertUtils.ArgumentHasText( functionName, "functionName" ); AssertUtils.ArgumentHasText( lambdaExpression, "lambdaExpression" ); ExpressionLexer lexer = new ExpressionLexer( new StringReader( lambdaExpression ) ); ExpressionParser parser = new SpringExpressionParser( lexer ); try { parser.lambda(); } catch (TokenStreamRecognitionException ex) { throw new SyntaxErrorException( ex.recog.Message, ex.recog.getLine(), ex.recog.getColumn(), lambdaExpression ); } variables[functionName] = parser.getAST(); }