Call() public method

public Call ( LNode target ) : LNode
target LNode
return LNode
Ejemplo n.º 1
0
 static void AddCapture(MMap <Symbol, LNode> captures, LNode cap, Slice_ <LNode> items)
 {
     Debug.Assert(cap.Calls(S.Substitute, 1) && cap.Args.Last.IsId);
     if (items.Count == 1)
     {
         AddCapture(captures, cap.Args.Last.Name, items[0]);
     }
     else
     {
         AddCapture(captures, cap.Args.Last.Name, F.Call(S.Splice, items));
     }
 }
Ejemplo n.º 2
0
        static void AddCapture(MMap <Symbol, LNode> captures, LNode cap, Slice_ <LNode> items)
        {
            LNode capId = GetCaptureIdentifier(cap);

            if (items.Count == 1)
            {
                AddCapture(captures, capId.Name, items[0]);
            }
            else
            {
                AddCapture(captures, capId.Name, F.Call(S.Splice, items));
            }
        }
Ejemplo n.º 3
0
		public CodeGenHelperBase()
		{
			F = new LNodeFactory(EmptySourceFile.Unknown);
			ListType = F.Of(F.Id("List"), F.Id(_T));
			ListInitializer = F.Call(S.New, F.Call(ListType));
		}
Ejemplo n.º 4
0
        public void UnitTest()
        {
            // Testing the injector in isolation (without parser integration) is clunky,
            // so I'm only doing it once.
            //00	{
            //10		// Leading Comment 1
            //20		/* Leading Comment 2 */
            //30		/* Leading Comment 3 */ x = y; // Trailing Comment 1
            //40		/* Trailing Comment 2 */
            //50
            //60		y = z; TheEnd();
            //70	}
            var trivia = new DList <Token> {
                T(TT.Newline, 10, 1, WhitespaceTag.Value),
                T(TT.SLComment, 11, 1, "// Leading Comment 1"),
                T(TT.Newline, 20, 1, WhitespaceTag.Value),
                T(TT.MLComment, 21, 1, "/* Leading Comment 2 */"),
                T(TT.Newline, 30, 1, WhitespaceTag.Value),
                T(TT.MLComment, 31, 1, "/* Leading Comment 3 */"),
                T(TT.SLComment, 39, 1, "// Trailing Comment 1"),
                T(TT.Newline, 40, 1, WhitespaceTag.Value),
                T(TT.MLComment, 41, 1, "/* Trailing Comment 2 */"),
                T(TT.Newline, 50, 1, WhitespaceTag.Value),
                T(TT.Newline, 60, 1, WhitespaceTag.Value),
                T(TT.Newline, 70, 1, WhitespaceTag.Value),
            };
            var root = F.Braces(LNode.List(
                                    F.Call(S.Assign, LNode.List(F.Id("x", 33, 1), F.Id("y", 37, 1)), 33, 37),
                                    F.Call(S.Assign, LNode.List(F.Id("y", 61, 1), F.Id("z", 65, 1)), 61, 65),
                                    F.Call("TheEnd", 66, 67)
                                    ), 0, 71);
            // Expected results
            var expected = Les2LanguageService.Value.Parse(
                @"@[#trivia_SLComment("" Leading Comment 1""),
				  #trivia_MLComment("" Leading Comment 2 ""),
				  #trivia_newline,
				  #trivia_MLComment("" Leading Comment 3 ""),
				  #trivia_trailing(
				    #trivia_SLComment("" Trailing Comment 1""),
				    #trivia_MLComment("" Trailing Comment 2 ""),
				    #trivia_newline)] 
				x = y;
				y = z;
				@[#trivia_appendStatement] TheEnd();"                , preserveComments: false);

            var injector = new StandardTriviaInjector(trivia, F.File, (int)TT.Newline, "/*", "*/", "//");
            {
                var results = injector.Run(root.Args.GetEnumerator()).ToList();
                AreEqual(3, results.Count);
                AreEqual(expected[0].PlusAttrBefore(F.Id(S.TriviaNewline)), results[0]);
                AreEqual(expected[1], results[1]);
                AreEqual(expected[2], results[2]);
            }
            {
                var results = injector.Run(new List <LNode> {
                    root
                }.GetEnumerator()).ToList();
                AreEqual(1, results.Count);
                var result = results[0];
                IsTrue(result.Calls(S.Braces, 3));
                AreEqual(expected[0], result[0]);
                AreEqual(expected[1], result[1]);
                AreEqual(expected[2], result[2]);
            }
        }
Ejemplo n.º 5
0
 private LNode GenerateRandomNode(LNodeFactory Factory, Random Rand, int Depth)
 {
     int index = Rand.Next(5);
     switch (Depth <= 0 && index > 1 ? Rand.Next(2) : index)
     {
         case 0:
             return Factory.Literal(GenerateRandomLiteral(Rand));
         case 1:
             return Factory.Id(GenerateRandomSymbol(Rand));
         case 2:
             return Factory.Attr(GenerateRandomNode(Factory, Rand, Depth - 1), GenerateRandomNode(Factory, Rand, Depth - 1));
         case 3:
             return Factory.Call(GenerateRandomSymbol(Rand), GenerateRandomNodeList(Factory, Rand, Depth - 1));
         default:
             return Factory.Call(GenerateRandomNode(Factory, Rand, Depth - 1), GenerateRandomNodeList(Factory, Rand, Depth - 1));
     }
 }
Ejemplo n.º 6
0
        public void Test_FlattenBinaryOpSeq()
        {
            ExpectList(LNode.FlattenBinaryOpSeq(a, S.Add, null), new[] { a });
            ExpectList(LNode.FlattenBinaryOpSeq(a, S.Add, false), new[] { a });
            ExpectList(LNode.FlattenBinaryOpSeq(a, S.Add, true), new[] { a });
            var expr = F.Call(S.Add, a, b);

            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Add, null), new[] { a, b });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Add, false), new[] { a, b });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Add, true), new[] { a, b });
            var fooCall = F.Call(Foo, c, zero);             // Ensure this is not mistaken for an operator

            expr = F.Call(S.Assign, a, F.Call(S.Assign, b, fooCall));
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Assign, null), new[] { a, b, fooCall });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Assign, false), new[] { a, F.Call(S.Assign, b, fooCall) });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Assign, true), new[] { a, b, fooCall });
            expr = F.Call(S.Mul, F.Call(S.Mul, a, b), F.Call(S.Mul, c, two));
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Mul, null), new[] { a, b, c, two });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Mul, false), new[] { a, b, F.Call(S.Mul, c, two) });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Mul, true), new[] { F.Call(S.Mul, a, b), c, two });
        }