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"); }
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); }
/// <summary> May return an index with value -1. </summary> public static RepetitionFormIndex TryCreate(ParseFormIndex parseIndex, RepetitionForm repetitionForm) { return new RepetitionFormIndex(parseIndex, repetitionForm, false); }
public RepetitionFormIndex(ParseFormIndex parseIndex, RepetitionForm repetitionForm) : this(parseIndex, repetitionForm, true) { }
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); } }
internal bool Contains(ParseFormIndex i) { return Repetition.GetStretchStartingAt(i) != null; }
internal int GetStretchLength(ParseFormIndex elementStartindex) { return Repetition.GetStretchLength(elementStartindex); }
internal int GetSuccessiveCount(ParseFormIndex i) { return Repetition.GetStretchLength(i); }