예제 #1
0
			private RepetitionFormIndex(ParseFormIndex parseIndex, RepetitionForm repetitionForm, bool throwIfNotContained)
				: this()
			{
				//concat concatenates the stretches
				Index = repetitionForm.Concat().IndexOf(parseIndex);
				if (throwIfNotContained)
					Contract.Assert(Index != -1, "The specified parse element is not part of the specified repetition");
			}
예제 #2
0
		public void Add(ReadOnlyCollection<LeafIndex> selectedElements, ParseFormIndex element)
		{
			RepetitionFormIndex repetitionElementIndex = new RepetitionFormIndex(element, Repetition);// 
			Contract.Assert((int)repetitionElementIndex <= selectedLeavesPerParseElement.Count, "Some elements have been skipped in parsing this repetition");

			if ((int)repetitionElementIndex == selectedLeavesPerParseElement.Count)
				selectedLeavesPerParseElement.Add(new List<ReadOnlyCollection<LeafIndex>> { selectedElements });
			else
				selectedLeavesPerParseElement[repetitionElementIndex].Add(selectedElements);
		}
예제 #3
0
			/// <summary> May return an index with value -1. </summary>
			public static RepetitionFormIndex TryCreate(ParseFormIndex parseIndex, RepetitionForm repetitionForm)
			{
				return new RepetitionFormIndex(parseIndex, repetitionForm, false);
			}
예제 #4
0
			public RepetitionFormIndex(ParseFormIndex parseIndex, RepetitionForm repetitionForm)
				: this(parseIndex, repetitionForm, true)
			{
			}
예제 #5
0
		internal void RemoveExtraneous(List<ReadOnlyCollection<LeafIndex>> matchedIndices, int achievedStretchCount, ParseFormIndex stretchStartIndex)
		{
			Contract.Requires(matchedIndices != null);
			Contract.Requires(0 <= achievedStretchCount && achievedStretchCount < MaximumAchievedRepetitionCount);

			//the repetition form index of the first element not to be truncated:
			var untruncatedCount = new RepetitionFormIndex(stretchStartIndex, this.Repetition);

			//asserts that the elements to be truncated have been parsed (that is, their 'selectedLeavesPerParseElement' is populated)
			Contract.Assert(Contract.ForAll(RepetitionFormIndex.ReversedRange(untruncatedCount),
				repetitionToTruncateIndex => selectedLeavesPerParseElement[repetitionToTruncateIndex].Count == this.MaximumAchievedRepetitionCount));

			foreach (var repetitionToTruncateIndex in RepetitionFormIndex.ReversedRange(untruncatedCount))
			{
				foreach (var leafCollectionToRemove in selectedLeavesPerParseElement[repetitionToTruncateIndex].Skip(achievedStretchCount))
				{
					bool removed = matchedIndices.Remove(leafCollectionToRemove);
					Contract.Assert(removed, "It should have been present");
				}
				selectedLeavesPerParseElement[repetitionToTruncateIndex].RemoveRange((int)untruncatedCount);
			}
		}
예제 #6
0
		internal bool Contains(ParseFormIndex i)
		{
			return Repetition.GetStretchStartingAt(i) != null;
		}
예제 #7
0
		internal int GetStretchLength(ParseFormIndex elementStartindex)
		{
			return Repetition.GetStretchLength(elementStartindex);
		}
예제 #8
0
		internal int GetSuccessiveCount(ParseFormIndex i)
		{
			return Repetition.GetStretchLength(i);
		}