public void SimpleTest5() { string expr = ExpressionsForTest.Expr5; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is OperatorNode); }
public void TernaryTest1() { string expr = "a?(b?c:d):e"; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); TernaryNode tNode = ast.Root as TernaryNode; Assert.IsTrue(tNode.TrueValue is TernaryNode); }
public void SimpleTest1() { string expr = ExpressionsForTest.Expr1; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is MethodNode); MethodNode mNode = ast.Root as MethodNode; Assert.IsTrue(mNode.Variable is SimpleNode); }
public object Eval(string expr) { try { _log.Info("Eval expression: [{0}]", expr); ExpressionLanguageAST ast = _cache.Get(expr); if (ast == null) { ast = _i.Parser(expr); _cache.Put(expr, ast); } EvalVisitor v = new EvalVisitor(_ctx); object result = ast.Accept(v); _log.Info("Eval result: [{0}]", result); return(result); } catch (ELParseException parseException) { _policy.Handle(parseException); if (_policy.Throw) { throw; } else { return(_fallbackValue); } } catch (Exception ex) { _policy.Handle(ex); if (_policy.Throw) { throw ex.CreateWrapException <EvalException>(); } else { return(_fallbackValue); } } }
public void SimpleTest3() { string expr = ExpressionsForTest.Expr3; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is IndexerNode); IndexerNode iNode = ast.Root as IndexerNode; Assert.IsTrue(iNode.Variable is SimpleNode); Assert.IsTrue((iNode.Args as ParamListNode).Values.Count == 1); }
public void SimpleTest13() { string expr = ExpressionsForTest.Expr13; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is PropertyNode); PropertyNode pNode = ast.Root as PropertyNode; pNode = pNode.Variable as PropertyNode; Assert.IsTrue(pNode.Variable is IndexerNode); }
public void SimpleTest11() { string expr = ExpressionsForTest.Expr11; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is OperatorNode); OperatorNode opNode = ast.Root as OperatorNode; Assert.IsTrue(opNode.Lhs is UnaryNode); Assert.IsTrue(opNode.Rhs is SimpleNode); }
public void SimpleTest6() { string expr = ExpressionsForTest.Expr6; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is MethodNode); MethodNode mNode = ast.Root as MethodNode; ParamListNode plNode = mNode.Args as ParamListNode; Assert.IsTrue(plNode.Values.Count == 2); }
public void SimpleTest8() { string expr = ExpressionsForTest.Expr8; LexicalParser lp = new LexicalParser(); lp.SetParseContent(expr); List <Token <TokenType> > tokens = lp.Parse(); SymanticParser sp = new SymanticParser(); sp.SetParseContent(tokens); ExpressionLanguageAST ast = sp.Parse(); Assert.IsTrue(ast.Root is TernaryNode); TernaryNode tNode = ast.Root as TernaryNode; Assert.IsTrue(tNode.Condition is OperatorNode); Assert.IsTrue(tNode.TrueValue is IndexerNode); Assert.IsTrue(tNode.FalseValue is SimpleNode); }