예제 #1
0
        private static bool ListMatches(VList <LNode> candidates, VList <LNode> patterns, ref MMap <Symbol, LNode> captures, ref VList <LNode> unmatchedAttrs)
        {
            if (patterns.Count != candidates.Count && !patterns.Any(IsParamsCapture))
            {
                return(false);
            }

            // Scan from the end of the list to the beginning (RVLists is good at this),
            // matching args one-by-one. Use MatchThenParams() in case of $(params capture).
            while (!patterns.IsEmpty)
            {
                LNode pArg = patterns.Pop();
                if (IsParamsCapture(pArg))
                {
                    return(MatchThenParams(candidates, patterns, pArg, ref captures, ref unmatchedAttrs));
                }
                if (candidates.IsEmpty)
                {
                    return(false);
                }
                if (!MatchesPatternNested(candidates.Pop(), pArg, ref captures, ref unmatchedAttrs))
                {
                    return(false);
                }
            }
            return(true);
        }
        protected override VList <LNode> AttachTriviaTo(ref LNode node, IListSource <Token> trivia, TriviaLocation loc, LNode parent, int indexInParent)
        {
            VList <LNode> newAttrs = VList <LNode> .Empty;
            int           i        = 0;

            if (loc == TriviaLocation.Leading)
            {
                // leading trivia
                if (parent == null ? indexInParent > 0 : HasImplicitLeadingNewline(node, parent, indexInParent))
                {
                    // ignore expected leading newline
                    if (trivia.Count > 0 && trivia[0].TypeInt == NewlineTypeInt)
                    {
                        i++;
                    }
                    else
                    {
                        newAttrs.Add(_trivia_appendStatement);
                    }
                }
            }
            bool  justAddedSLComment = false;
            LNode attr = null;

            for (; i < trivia.Count; i++)
            {
                var t = trivia[i];
                // ignore first newline after single-line comment
                if (t.TypeInt == NewlineTypeInt && justAddedSLComment)
                {
                    justAddedSLComment = false;
                    continue;
                }
                if ((attr = MakeTriviaAttribute(t)) != null)
                {
                    justAddedSLComment = attr.Calls(S.TriviaSLComment);
                    newAttrs.Add(attr);
                }
            }
            // Suppress newline before closing brace or at EOF
            if (loc == TriviaLocation.TrailingExtra && newAttrs.Count > 0 && newAttrs.Last == _trivia_newline)
            {
                if (parent == null || parent.Calls(S.Braces))
                {
                    newAttrs.Pop();                     // Printers add a newline here anyway
                }
            }
            return(newAttrs);
        }
예제 #3
0
 // Converts the list of remaining nodes from an implicit sublist of
 // OldAndRemainingNodes into an explicit queue, if it wasn't done yet.
 public void MaybeCreateNodeQueue(int maxExpansions, ref DList <Pair <LNode, int> > nodeQueue)
 {
     //Debug.Assert(!IsTarget); should be true except that IsTarget may not have been set yet
     if (nodeQueue == null)
     {
         // Transfer OldAndRemainingNodes into NodeQueue
         nodeQueue = new DList <Pair <LNode, int> >();
         if (!DropRemainingNodesIfRequested())
         {
             for (int left = OldAndRemainingNodes.Count - (CurrentNodeIndex + 1); left > 0; left--)
             {
                 nodeQueue.PushFirst(Pair.Create(OldAndRemainingNodes.Pop(), maxExpansions));
             }
         }
         OldAndRemainingNodes = LNode.List();
         _remainingNodes      = null;
     }
 }
예제 #4
0
파일: LNodeExt.cs 프로젝트: qwertie/ecsharp
		private static bool ListMatches(VList<LNode> candidates, VList<LNode> patterns, ref MMap<Symbol, LNode> captures, ref VList<LNode> unmatchedAttrs)
		{
			if (patterns.Count != candidates.Count && !patterns.Any(IsParamsCapture))
				return false;

			// Scan from the end of the list to the beginning (RVLists is good at this),
			// matching args one-by-one. Use MatchThenParams() in case of $(params capture).
			while (!patterns.IsEmpty)
			{
				LNode pArg = patterns.Pop();
				if (IsParamsCapture(pArg))
					return MatchThenParams(candidates, patterns, pArg, ref captures, ref unmatchedAttrs);
				if (candidates.IsEmpty)
					return false;
				if (!MatchesPatternNested(candidates.Pop(), pArg, ref captures, ref unmatchedAttrs))
					return false;
			}
			return true;
		}
예제 #5
0
		public void TestInsertRemove()
		{
			VList<int> list = new VList<int>(9);
			VList<int> list2 = new VList<int>(10, 11);
			list.Insert(0, 12);
			list.Insert(1, list2[1]);
			list.Insert(2, list2[0]);
			ExpectList(list, 12, 11, 10, 9);
			for (int i = 0; i < 9; i++)
				list.Insert(4, i);
			ExpectList(list, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);

			list2 = list;
			for (int i = 1; i <= 6; i++)
				list2.RemoveAt(i);
			ExpectList(list2, 12, 10, 8, 6, 4, 2, 0);
			ExpectList(list, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); // unchanged

			Assert.AreEqual(0, list2.Pop());
			list2.Insert(5, -2);
			ExpectList(list2, 12, 10, 8, 6, 4, -2, 2);
			list2.Insert(5, -1);
			ExpectList(list2, 12, 10, 8, 6, 4, -1, -2, 2);

			// Test changing items
			list = list2;
			for (int i = 0; i < list.Count; i++)
				list[i] = i;
			ExpectList(list, 0, 1, 2, 3, 4, 5, 6, 7);
			ExpectList(list2, 12, 10, 8, 6, 4, -1, -2, 2);

			list2.Clear();
			ExpectList(list2);
			Assert.AreEqual(5, list[5]);
		}