コード例 #1
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest13()
        {
            string        expr = ExpressionsForTest.Expr13;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("person", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("[", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("index", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[2].TokenType);
            Assert.AreEqual("]", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[3].TokenType);
            Assert.AreEqual(".", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[4].TokenType);
            Assert.AreEqual("Name", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[5].TokenType);
            Assert.AreEqual(".", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[6].TokenType);
            Assert.AreEqual("Last", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[7].TokenType);
        }
コード例 #2
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest1()
        {
            string        expr = ExpressionsForTest.Expr1;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("DateTime", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual(".", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[1].TokenType);
            Assert.AreEqual("Parse", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[2].TokenType);
            Assert.AreEqual("(", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[3].TokenType);
            Assert.AreEqual("2000-1-1", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[4].TokenType);
            Assert.AreEqual(")", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[5].TokenType);

            Assert.AreEqual(0, tokens[0].Position);
            Assert.AreEqual(8, tokens[1].Position);
            Assert.AreEqual(15, tokens[4].Position);
        }
コード例 #3
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest12()
        {
            string        expr = ExpressionsForTest.Expr12;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("-", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[0].TokenType);
            Assert.AreEqual("a", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[1].TokenType);
            Assert.AreEqual("+", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[2].TokenType);
            Assert.AreEqual("7", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[3].TokenType);
            Assert.AreEqual("/", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[4].TokenType);
            Assert.AreEqual("(", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[5].TokenType);
            Assert.AreEqual("-", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[6].TokenType);
            Assert.AreEqual("5", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[7].TokenType);
            Assert.AreEqual(")", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[8].TokenType);
        }
コード例 #4
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest9()
        {
            string        expr = ExpressionsForTest.Expr9;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("(", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[0].TokenType);
            Assert.AreEqual("a", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[1].TokenType);
            Assert.AreEqual("+", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[2].TokenType);
            Assert.AreEqual("b", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[3].TokenType);
            Assert.AreEqual(">", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.CompareOperator, tokens[4].TokenType);
            Assert.AreEqual("0", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[5].TokenType);
            Assert.AreEqual(")", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[6].TokenType);
            Assert.AreEqual("?", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.QuestionMark, tokens[7].TokenType);
            Assert.AreEqual("T", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[8].TokenType);
            Assert.AreEqual(":", tokens[9].TokenValue);
            Assert.AreEqual(TokenType.Colon, tokens[9].TokenType);
            Assert.AreEqual("F", tokens[10].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[10].TokenType);
        }
コード例 #5
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest10()
        {
            string expr = ExpressionsForTest.Expr10;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("GetData", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("(", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[1].TokenType);
            Assert.AreEqual("rex", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
            Assert.AreEqual(")", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[3].TokenType);
            Assert.AreEqual(".", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[4].TokenType);
            Assert.AreEqual("Name", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[5].TokenType);
            Assert.AreEqual(".", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[6].TokenType);
            Assert.AreEqual("ToString", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[7].TokenType);
            Assert.AreEqual("(", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[8].TokenType);
            Assert.AreEqual(")", tokens[9].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[9].TokenType);

            Assert.AreEqual(15, tokens[5].Position);
            Assert.AreEqual(20, tokens[7].Position);
        }
コード例 #6
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest10()
        {
            string        expr = ExpressionsForTest.Expr10;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("GetData", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("(", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[1].TokenType);
            Assert.AreEqual("rex", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
            Assert.AreEqual(")", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[3].TokenType);
            Assert.AreEqual(".", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[4].TokenType);
            Assert.AreEqual("Name", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[5].TokenType);
            Assert.AreEqual(".", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[6].TokenType);
            Assert.AreEqual("ToString", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[7].TokenType);
            Assert.AreEqual("(", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[8].TokenType);
            Assert.AreEqual(")", tokens[9].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[9].TokenType);

            Assert.AreEqual(15, tokens[5].Position);
            Assert.AreEqual(20, tokens[7].Position);
        }
コード例 #7
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest14()
        {
            string        expr = ExpressionsForTest.Expr14;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual(TokenType.Regex, tokens[0].TokenType);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
            Assert.AreEqual(@"^\d3*$", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[3].TokenType);
        }
コード例 #8
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest16()
        {
            string        expr = ExpressionsForTest.Expr16;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual(TokenType.Array, tokens[0].TokenType);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("4", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Colon, tokens[3].TokenType);
            Assert.AreEqual("7", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[5].TokenType);
        }
コード例 #9
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest5()
        {
            string        expr = ExpressionsForTest.Expr5;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("1.2", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.Decimal, tokens[0].TokenType);
            Assert.AreEqual("+", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[1].TokenType);
            Assert.AreEqual("$", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
        }
コード例 #10
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #13
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest3()
        {
            string        expr = ExpressionsForTest.Expr3;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("_table", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("[", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("key", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
            Assert.AreEqual("]", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[3].TokenType);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest15()
        {
            string        expr = ExpressionsForTest.Expr15;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual(TokenType.Hash, tokens[0].TokenType);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual(TokenType.ID, tokens[2].TokenType);
            Assert.AreEqual(TokenType.Colon, tokens[3].TokenType);
            Assert.AreEqual("1", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[5].TokenType);
            Assert.AreEqual(TokenType.ID, tokens[6].TokenType);
            Assert.AreEqual(TokenType.Colon, tokens[7].TokenType);
            Assert.AreEqual("5", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[9].TokenType);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest6()
        {
            string        expr = ExpressionsForTest.Expr6;
            LexicalParser lp   = new LexicalParser();

            lp.SetParseContent(expr);
            List <Token <TokenType> > tokens = lp.Parse();

            Assert.AreEqual("Update", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("(", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[1].TokenType);
            Assert.AreEqual("1", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[2].TokenType);
            Assert.AreEqual(",", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[3].TokenType);
            Assert.AreEqual("true", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Boolean, tokens[4].TokenType);
            Assert.AreEqual(")", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[5].TokenType);
        }
コード例 #23
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest11()
        {
            string expr = ExpressionsForTest.Expr11;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("-", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[0].TokenType);
            Assert.AreEqual("(", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[1].TokenType);
            Assert.AreEqual("a", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[2].TokenType);
            Assert.AreEqual("+", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[3].TokenType);
            Assert.AreEqual("7", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[4].TokenType);
            Assert.AreEqual(")", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[5].TokenType);
            Assert.AreEqual("/", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[6].TokenType);
            Assert.AreEqual("7", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[7].TokenType);
        }
コード例 #24
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest1()
        {
            string expr = ExpressionsForTest.Expr1;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("DateTime", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual(".", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[1].TokenType);
            Assert.AreEqual("Parse", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[2].TokenType);
            Assert.AreEqual("(", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[3].TokenType);
            Assert.AreEqual("2000-1-1", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[4].TokenType);
            Assert.AreEqual(")", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[5].TokenType);

            Assert.AreEqual(0, tokens[0].Position);
            Assert.AreEqual(8, tokens[1].Position);
            Assert.AreEqual(15, tokens[4].Position);
        }
コード例 #25
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #26
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #27
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest9()
        {
            string expr = ExpressionsForTest.Expr9;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("(", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[0].TokenType);
            Assert.AreEqual("a", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[1].TokenType);
            Assert.AreEqual("+", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[2].TokenType);
            Assert.AreEqual("b", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[3].TokenType);
            Assert.AreEqual(">", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.CompareOperator, tokens[4].TokenType);
            Assert.AreEqual("0", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[5].TokenType);
            Assert.AreEqual(")", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[6].TokenType);
            Assert.AreEqual("?", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.QuestionMark, tokens[7].TokenType);
            Assert.AreEqual("T", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[8].TokenType);
            Assert.AreEqual(":", tokens[9].TokenValue);
            Assert.AreEqual(TokenType.Colon, tokens[9].TokenType);
            Assert.AreEqual("F", tokens[10].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[10].TokenType);
        }
コード例 #28
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest6()
        {
            string expr = ExpressionsForTest.Expr6;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("Update", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("(", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Parenthesis, tokens[1].TokenType);
            Assert.AreEqual("1", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Long, tokens[2].TokenType);
            Assert.AreEqual(",", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[3].TokenType);
            Assert.AreEqual("true", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Boolean, tokens[4].TokenType);
            Assert.AreEqual(")", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.Right_Parenthesis, tokens[5].TokenType);
        }
コード例 #29
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest5()
        {
            string expr = ExpressionsForTest.Expr5;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("1.2", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.Decimal, tokens[0].TokenType);
            Assert.AreEqual("+", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.ArithmeticOperator, tokens[1].TokenType);
            Assert.AreEqual("$", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
        }
コード例 #30
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest3()
        {
            string expr = ExpressionsForTest.Expr3;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("_table", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("[", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("key", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
            Assert.AreEqual("]", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[3].TokenType);
        }
コード例 #31
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest17()
        {
            string expr = ExpressionsForTest.Expr17;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual(TokenType.Array, tokens[0].TokenType);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("1", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[3].TokenType);
            Assert.AreEqual("1", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[5].TokenType);
            Assert.AreEqual("2", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[7].TokenType);
            Assert.AreEqual("3", tokens[8].TokenValue);
            Assert.AreEqual(TokenType.Comma, tokens[9].TokenType);
            Assert.AreEqual("5", tokens[10].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[11].TokenType);
        }
コード例 #32
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest16()
        {
            string expr = ExpressionsForTest.Expr16;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual(TokenType.Array, tokens[0].TokenType);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("4", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Colon, tokens[3].TokenType);
            Assert.AreEqual("7", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[5].TokenType);
        }
コード例 #33
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest14()
        {
            string expr = ExpressionsForTest.Expr14;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual(TokenType.Regex, tokens[0].TokenType);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual(TokenType.String, tokens[2].TokenType);
            Assert.AreEqual(@"^\d3*$", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[3].TokenType);
        }
コード例 #34
0
ファイル: LexicalTest.cs プロジェクト: rexzh/RexToy
        public void SimpleTest13()
        {
            string expr = ExpressionsForTest.Expr13;
            LexicalParser lp = new LexicalParser();
            lp.SetParseContent(expr);
            List<Token<TokenType>> tokens = lp.Parse();

            Assert.AreEqual("person", tokens[0].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[0].TokenType);
            Assert.AreEqual("[", tokens[1].TokenValue);
            Assert.AreEqual(TokenType.Left_Square_Bracket, tokens[1].TokenType);
            Assert.AreEqual("index", tokens[2].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[2].TokenType);
            Assert.AreEqual("]", tokens[3].TokenValue);
            Assert.AreEqual(TokenType.Right_Square_Bracket, tokens[3].TokenType);
            Assert.AreEqual(".", tokens[4].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[4].TokenType);
            Assert.AreEqual("Name", tokens[5].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[5].TokenType);
            Assert.AreEqual(".", tokens[6].TokenValue);
            Assert.AreEqual(TokenType.Dot, tokens[6].TokenType);
            Assert.AreEqual("Last", tokens[7].TokenValue);
            Assert.AreEqual(TokenType.ID, tokens[7].TokenType);
        }
コード例 #35
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #36
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #37
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }
コード例 #38
0
ファイル: SemanticTest.cs プロジェクト: rexzh/RexToy
        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);
        }