/// <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"); var lexer = new ExpressionLexer(new StringReader(lambdaExpression)); ExpressionParser parser = new SolenoidExpressionParser(lexer); try { parser.lambda(); } catch (TokenStreamRecognitionException ex) { throw new SyntaxErrorException(ex.recog.Message, ex.recog.Line, ex.recog.Column, 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)) { var lexer = new ExpressionLexer(new StringReader(expression)); ExpressionParser parser = new SolenoidExpressionParser(lexer); try { parser.property(); } catch (TokenStreamRecognitionException ex) { throw new SyntaxErrorException(ex.recog.Message, ex.recog.Line, ex.recog.Column, expression); } return((IExpression)parser.getAST()); } return(new Expression()); }