Esempio n. 1
0
        public void BasicCallTwoArguments()
        {
            string content = @"foo(12.34, -56.78);";
            Parser parser  = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("foo", root.Identifier);
            Assert.AreEqual(4, root.StartPoint.X);
            Assert.AreEqual(0, root.StartPoint.Y);
            Assert.AreEqual(17, root.EndPoint.X);
            Assert.AreEqual(0, root.EndPoint.Y);

            FunctionCallPart secondPart = root.GetIntersectionPart(15, 0);

            Assert.AreNotEqual(null, secondPart);
            Assert.AreNotEqual(null, secondPart.ParentPart);
            Assert.AreEqual("foo", secondPart.ParentPart.Identifier);
            Assert.AreEqual(10, secondPart.StartPoint.X);
            Assert.AreEqual(0, secondPart.StartPoint.Y);
            Assert.AreEqual(17, secondPart.EndPoint.X);
            Assert.AreEqual(0, secondPart.EndPoint.Y);
        }
Esempio n. 2
0
 void CommonMathOperator(FunctionCallPart part)
 {
     if (la.kind == 45)
     {
         Get();
     }
     else if (la.kind == 12)
     {
         Get();
     }
     else if (la.kind == 46)
     {
         Get();
     }
     else if (la.kind == 47)
     {
         Get();
     }
     else if (la.kind == 48)
     {
         Get();
     }
     else
     {
         SynErr(61);
     }
 }
Esempio n. 3
0
 void CommonTernaryOperation(FunctionCallPart part)
 {
     Expect(51);
     CommonExpression(part);
     Expect(52);
     CommonExpression(part);
 }
Esempio n. 4
0
 void CommonRangeExpression(FunctionCallPart part)
 {
     CommonArithmeticExpression(part);
     if (la.kind == 21)
     {
         Get();
         CommonArithmeticExpression(part);
         if (la.kind == 21)
         {
             Get();
             if (la.kind == 43 || la.kind == 44)
             {
                 if (la.kind == 43)
                 {
                     Get();
                 }
                 else
                 {
                     Get();
                 }
             }
             CommonArithmeticExpression(part);
         }
     }
 }
Esempio n. 5
0
 void CommonNegativeExpression(FunctionCallPart part)
 {
     if (la.kind == 12)
     {
         Get();
         part.AppendIdentifier(t);
     }
     if (la.kind == 2 || la.kind == 3)
     {
         if (la.kind == 2)
         {
             Get();
         }
         else
         {
             Get();
         }
         part.AppendIdentifier(t);
     }
     else if (la.kind == 1 || la.kind == 53)
     {
         CommonIdentifierList(part);
     }
     else
     {
         SynErr(62);
     }
 }
Esempio n. 6
0
 void CommonFunctionCall(FunctionCallPart part)
 {
     CommonIdentifier(part);
     while (la.kind == 9)
     {
         CommonArguments(part);
     }
 }
Esempio n. 7
0
 void CommonArithmeticExpression(FunctionCallPart part)
 {
     CommonTerm(part);
     while (StartOf(3))
     {
         CommonMathOperator(part);
         CommonTerm(part);
     }
 }
Esempio n. 8
0
 void CommonComparisonExpression(FunctionCallPart part)
 {
     CommonRangeExpression(part);
     while (StartOf(2))
     {
         CommonComparisonOperator(part);
         CommonRangeExpression(part);
     }
 }
Esempio n. 9
0
 void CommonLogicalExpression(FunctionCallPart part)
 {
     CommonComparisonExpression(part);
     while (la.kind == 49 || la.kind == 50)
     {
         CommonLogicalOperator(part);
         CommonComparisonExpression(part);
     }
 }
Esempio n. 10
0
        void CommonIdentifierList(FunctionCallPart part)
        {
            string partName = string.Empty;

            CommonNameReference(part);
            partName = part.Identifier;
            while (la.kind == 6)
            {
                Get();
                CommonNameReference(part);
                string newPartName = part.Identifier;
                part.Identifier = partName + "." + newPartName;
                partName        = part.Identifier;
            }
        }
Esempio n. 11
0
 void CommonExpression(FunctionCallPart part)
 {
     if (StartOf(1))
     {
         CommonLogicalExpression(part);
     }
     else if (la.kind == 51)
     {
         CommonTernaryOperation(part);
     }
     else
     {
         SynErr(57);
     }
 }
Esempio n. 12
0
 void CommonLogicalOperator(FunctionCallPart part)
 {
     if (la.kind == 49)
     {
         Get();
     }
     else if (la.kind == 50)
     {
         Get();
     }
     else
     {
         SynErr(58);
     }
 }
Esempio n. 13
0
        void CommonTerm(FunctionCallPart part)
        {
            switch (la.kind)
            {
            case 40: {
                Get();
                break;
            }

            case 41: {
                Get();
                break;
            }

            case 42: {
                Get();
                break;
            }

            case 5: {
                CommonCharacter(part);
                break;
            }

            case 4: {
                CommonString(part);
                break;
            }

            case 1:
            case 2:
            case 3:
            case 12:
            case 53: {
                CommonNegativeExpression(part);
                break;
            }

            case 11: {
                Get();
                CommonTerm(part);
                break;
            }

            default: SynErr(60); break;
            }
        }
Esempio n. 14
0
        public void MultilineNestedIncomplete01()
        {
            string content = @"
    foo     (       bar     (           ";

            Parser parser = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("foo", root.Identifier);

            // Before the first open bracket.
            FunctionCallPart intersection = root.GetIntersectionPart(12, 1);

            Assert.AreEqual(null, intersection);

            // Right after the first open bracket.
            intersection = root.GetIntersectionPart(13, 1);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("bar", intersection.Identifier); // Argument 0 of "foo"
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right before the second open bracket.
            intersection = root.GetIntersectionPart(28, 1);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("bar", intersection.Identifier); // Argument 0 of "foo"
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the second open bracket.
            intersection = root.GetIntersectionPart(29, 1);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("", intersection.Identifier); // Argument 0 of "bar"
            Assert.AreEqual("bar", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // At EOL after the second open bracket.
            intersection = root.GetIntersectionPart(40, 1);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("", intersection.Identifier); // Argument 0 of "bar"
            Assert.AreEqual("bar", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));
        }
Esempio n. 15
0
        public void ArrayIndexedFunctionCall01()
        {
            string content = @"first[3][-2.3].second[4][5][6].foo(12, false);";

            Parser parser = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("first[3][-2.3].second[4][5][6].foo", root.Identifier);

            // Before the first open bracket.
            FunctionCallPart intersection = root.GetIntersectionPart(34, 0);

            Assert.AreEqual(null, intersection);

            // After the first open bracket.
            intersection = root.GetIntersectionPart(35, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual(root, intersection.ParentPart);
            Assert.AreEqual(0, root.GetArgumentIndex(intersection));

            // Right before the comma.
            intersection = root.GetIntersectionPart(37, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual(root, intersection.ParentPart);
            Assert.AreEqual(0, root.GetArgumentIndex(intersection));

            // Right after the comma.
            intersection = root.GetIntersectionPart(38, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual(root, intersection.ParentPart);
            Assert.AreEqual(1, root.GetArgumentIndex(intersection));

            // Right before the closing bracket.
            intersection = root.GetIntersectionPart(44, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual(root, intersection.ParentPart);
            Assert.AreEqual(1, root.GetArgumentIndex(intersection));

            // After the closing bracket.
            intersection = root.GetIntersectionPart(46, 0);
            Assert.AreEqual(null, intersection);
        }
Esempio n. 16
0
 void CommonArrayExpression(FunctionCallPart part)
 {
     Expect(53);
     part.SetStartPoint(t, false);
     if (StartOf(4))
     {
         FunctionCallPart elementPart = new FunctionCallPart();
         CommonExpression(elementPart);
         part.AddArgumentPart(elementPart);
         while (la.kind == 54)
         {
             Get();
             elementPart = new FunctionCallPart();
             CommonExpression(elementPart);
             part.AddArgumentPart(elementPart);
         }
     }
     Expect(55);
     part.SetEndPoint(t, true);
 }
Esempio n. 17
0
        public void BasicCallTwoNestingLevels()
        {
            string content = @"foo(12.34, bar(-87.65, 43.21), -56.78);";
            Parser parser  = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("foo", root.Identifier);
            Assert.AreEqual(4, root.StartPoint.X);
            Assert.AreEqual(0, root.StartPoint.Y);
            Assert.AreEqual(37, root.EndPoint.X);
            Assert.AreEqual(0, root.EndPoint.Y);

            // This is a position right after "43" (second arg of "bar").
            FunctionCallPart innerPart = root.GetIntersectionPart(25, 0);

            Assert.AreNotEqual(null, innerPart);
            Assert.AreNotEqual(null, innerPart.ParentPart);
            Assert.AreNotEqual(null, innerPart.ParentPart.ParentPart);
            Assert.AreEqual("bar", innerPart.ParentPart.Identifier);
            Assert.AreEqual("foo", innerPart.ParentPart.ParentPart.Identifier);

            Assert.AreEqual(22, innerPart.StartPoint.X);
            Assert.AreEqual(0, innerPart.StartPoint.Y);
            Assert.AreEqual(28, innerPart.EndPoint.X);
            Assert.AreEqual(0, innerPart.EndPoint.Y);

            innerPart = root.GetIntersectionPart(34, 0);
            Assert.AreNotEqual(null, innerPart);
            Assert.AreNotEqual(null, innerPart.ParentPart);
            Assert.AreEqual(null, innerPart.ParentPart.ParentPart);
            Assert.AreEqual("foo", innerPart.ParentPart.Identifier);

            // Parameter "-56.78" of function "foo".
            Assert.AreEqual(30, innerPart.StartPoint.X);
            Assert.AreEqual(0, innerPart.StartPoint.Y);
            Assert.AreEqual(37, innerPart.EndPoint.X);
            Assert.AreEqual(0, innerPart.EndPoint.Y);
        }
Esempio n. 18
0
        void CommonArguments(FunctionCallPart part)
        {
            Expect(9);
            part.SetStartPoint(t, false);
            part.SetEndPoint(la, true);
            System.Drawing.Point openBracket = PointFromToken(t, false);

            if (StartOf(4))
            {
                FunctionCallPart parentCallPart = part;
                part = new FunctionCallPart();
                part.SetStartPoint(t, false);

                CommonExpression(part);
                part.SetEndPoint(t, false);
                parentCallPart.AddArgumentPart(part);
                part = parentCallPart;

                while (WeakSeparator(54, 4, 5))
                {
                    parentCallPart = part;
                    part           = new FunctionCallPart();
                    part.SetStartPoint(t, false);

                    CommonExpression(part);
                    part.SetEndPoint(la, true);
                    parentCallPart.AddArgumentPart(part);
                    part = parentCallPart;
                }
            }
            if (part.HasArgument == false)
            {
                // See "AddDefaultArgument" for details.
                System.Drawing.Point closeBracket = PointFromToken(la, true);
                part.AddDefaultArgument(openBracket, closeBracket);
            }

            Expect(10);
            part.SetEndPoint(t, true);
        }
Esempio n. 19
0
 void CommonNameReference(FunctionCallPart part)
 {
     if (la.kind == 1)
     {
         CommonFunctionCall(part);
     }
     else if (la.kind == 53)
     {
         CommonArrayExpression(part);
     }
     else
     {
         SynErr(63);
     }
     if (la.kind == 7)
     {
         Get();
         part.AppendIdentifier(t); part.SetEndPoint(t, false);
         if (StartOf(4))
         {
             CommonExpression(part);
             part.SetEndPoint(t, false);
         }
         Expect(8);
         part.AppendIdentifier(t); part.SetEndPoint(t, false);
         while (la.kind == 7)
         {
             Get();
             part.AppendIdentifier(t); part.SetEndPoint(t, false);
             if (StartOf(4))
             {
                 CommonExpression(part);
                 part.SetEndPoint(t, false);
             }
             Expect(8);
             part.AppendIdentifier(t); part.SetEndPoint(t, false);
         }
     }
 }
Esempio n. 20
0
        public void BasicCallOneArgument()
        {
            string content = @"foo(12.34);";
            Parser parser  = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("foo", root.Identifier);
            Assert.AreEqual(4, root.StartPoint.X);
            Assert.AreEqual(0, root.StartPoint.Y);
            Assert.AreEqual(9, root.EndPoint.X);
            Assert.AreEqual(0, root.EndPoint.Y);

            FunctionCallPart part = root.GetIntersectionPart(6, 0);

            Assert.AreNotEqual(null, part);
            Assert.AreEqual(4, part.StartPoint.X);
            Assert.AreEqual(0, part.StartPoint.Y);
            Assert.AreEqual(9, part.EndPoint.X);
            Assert.AreEqual(0, part.EndPoint.Y);
        }
Esempio n. 21
0
        void CommonComparisonOperator(FunctionCallPart part)
        {
            switch (la.kind)
            {
            case 15: {
                Get();
                break;
            }

            case 17: {
                Get();
                break;
            }

            case 14: {
                Get();
                break;
            }

            case 16: {
                Get();
                break;
            }

            case 18: {
                Get();
                break;
            }

            case 19: {
                Get();
                break;
            }

            default: SynErr(59); break;
            }
        }
Esempio n. 22
0
 void FunctionCallParser()
 {
     rootFunctionCallPart = new FunctionCallPart();
     CommonExpression(rootFunctionCallPart);
 }
Esempio n. 23
0
        public void FunctionsWithinArrayExpression()
        {
            string content = @"foo( 789, { 12, First.ByLuck(34, 56), Second.ByChance( }, -321 );";

            Parser parser = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("foo", root.Identifier);

            // Right after "foo" before the open bracket.
            FunctionCallPart intersection = root.GetIntersectionPart(3, 0);

            Assert.AreEqual(null, intersection);

            // Right after the open bracket of "foo".
            intersection = root.GetIntersectionPart(4, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("789", intersection.Identifier);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the first comma.
            intersection = root.GetIntersectionPart(9, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(1, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after "ByLuck" before the open bracket.
            intersection = root.GetIntersectionPart(28, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(1, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the open bracket of "ByLuck" call.
            intersection = root.GetIntersectionPart(29, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("First.ByLuck", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right before the close bracket of "ByLuck" call.
            intersection = root.GetIntersectionPart(35, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("First.ByLuck", intersection.ParentPart.Identifier);
            Assert.AreEqual(1, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the close bracket of "ByLuck" call.
            intersection = root.GetIntersectionPart(36, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(1, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right before the open bracket of "ByChance" call.
            intersection = root.GetIntersectionPart(53, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(1, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the open bracket of "ByChance" call.
            intersection = root.GetIntersectionPart(54, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("Second.ByChance", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right before the close curly bracket.
            intersection = root.GetIntersectionPart(55, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("Second.ByChance", intersection.ParentPart.Identifier);
            Assert.AreEqual(0, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the close curly bracket.
            intersection = root.GetIntersectionPart(56, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(1, intersection.ParentPart.GetArgumentIndex(intersection));

            // Right after the comma after close curly bracket.
            intersection = root.GetIntersectionPart(57, 0);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("-321", intersection.Identifier);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);
            Assert.AreEqual(2, intersection.ParentPart.GetArgumentIndex(intersection));
        }
Esempio n. 24
0
 void CommonCharacter(FunctionCallPart part)
 {
     Expect(5);
 }
Esempio n. 25
0
 void CommonString(FunctionCallPart part)
 {
     Expect(4);
 }
Esempio n. 26
0
        public void MultilineIntersection()
        {
            string content = @"
foo(12.34,
    bar(-87.65, 43.21),
    bleh(abc, def, ghi),
    -56.78);";

            Parser parser = CreateParserFromText(content);

            parser.Parse();

            FunctionCallPart root = parser.RootFunctionCallPart;

            Assert.AreEqual("foo", root.Identifier);

            // Before the first line.
            FunctionCallPart intersection = root.GetIntersectionPart(8, 0);

            Assert.AreEqual(null, intersection);

            // Beyond the last line.
            intersection = root.GetIntersectionPart(8, 5);
            Assert.AreEqual(null, intersection);

            // On the first line, before open bracket.
            intersection = root.GetIntersectionPart(3, 1);
            Assert.AreEqual(null, intersection);

            // On the last line, after the close bracket.
            intersection = root.GetIntersectionPart(11, 4);
            Assert.AreEqual(null, intersection);

            // On the first line, after the open bracket.
            intersection = root.GetIntersectionPart(32, 1);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("bar", intersection.Identifier);

            // On the last line, before the close bracket.
            intersection = root.GetIntersectionPart(0, 4);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("-56.78", intersection.Identifier);
            Assert.AreEqual("foo", intersection.ParentPart.Identifier);

            // In a middle line, before "bar" function.
            intersection = root.GetIntersectionPart(0, 2);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("bar", intersection.Identifier);

            // In a middle line, after the "bar" function.
            intersection = root.GetIntersectionPart(32, 2);
            Assert.AreNotEqual(null, intersection);
            Assert.AreEqual("bleh", intersection.Identifier);

            // In a middle line, within the "bar" function.
            intersection = root.GetIntersectionPart(12, 2);
            Assert.AreNotEqual(null, intersection);
            Assert.AreNotEqual(null, intersection.ParentPart);
            Assert.AreEqual("-87.65", intersection.Identifier);
            Assert.AreEqual("bar", intersection.ParentPart.Identifier);
        }
Esempio n. 27
0
 void CommonIdentifier(FunctionCallPart part)
 {
     Expect(1);
     part.Identifier = t.val;
 }