/// <summary> /// The parse. /// </summary> private void Parse() { this.State = ParseState.Text; this.index = 0; this.currentfragment = this.CreateFragment(MixedCodeDocumentFragmentType.Text); while (this.index < this.Text.Length) { this.character = this.Text[this.index]; this.IncrementPosition(); switch (this.State) { case ParseState.Text: if (this.index + TokenCodeStart.Length < this.Text.Length) { if (this.Text.Substring(this.index - 1, TokenCodeStart.Length) == TokenCodeStart) { this.State = ParseState.Code; this.currentfragment.Length = this.index - 1 - this.currentfragment.StreamPosition; this.currentfragment = this.CreateFragment(MixedCodeDocumentFragmentType.Code); this.SetPosition(); continue; } } break; case ParseState.Code: if (this.index + TokenCodeEnd.Length < this.Text.Length) { if (this.Text.Substring(this.index - 1, TokenCodeEnd.Length) == TokenCodeEnd) { this.State = ParseState.Text; this.currentfragment.Length = this.index + TokenCodeEnd.Length - this.currentfragment.StreamPosition; this.index += TokenCodeEnd.Length; this.Lineposition += TokenCodeEnd.Length; this.currentfragment = this.CreateFragment(MixedCodeDocumentFragmentType.Text); this.SetPosition(); continue; } } break; } } this.currentfragment.Length = this.index - this.currentfragment.StreamPosition; }
/// <summary> /// Appends a fragment to the list of fragments. /// </summary> /// <param name="newFragment"> /// The fragment to append. May not be null. /// </param> public void Append(MixedCodeDocumentFragment newFragment) { Ensure.IsNotNull(newFragment, "newFragment"); this.codeDocumentFragment.Add(newFragment); }
/// <summary> /// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised. /// </summary> /// <param name="fragment"> /// The fragment to remove. May not be null. /// </param> public void Remove(MixedCodeDocumentFragment fragment) { Ensure.IsNotNull(fragment, "fragment"); int index = this.GetFragmentIndex(fragment); if (index == -1) { throw new IndexOutOfRangeException(); } this.RemoveAt(index); }
/// <summary> /// The get fragment index. /// </summary> /// <param name="fragment">The fragment.</param> /// <returns> /// The fragment index. /// </returns> internal int GetFragmentIndex(MixedCodeDocumentFragment fragment) { Ensure.IsNotNull(fragment, "fragment"); for (int i = 0; i < this.codeDocumentFragment.Count; i++) { if (this.codeDocumentFragment[i] == fragment) { return i; } } return -1; }
/// <summary> /// Prepends a fragment to the list of fragments. /// </summary> /// <param name="newFragment">The fragment to append. May not be null.</param> public void Prepend(MixedCodeDocumentFragment newFragment) { Ensure.IsNotNull(newFragment, "newFragment"); this.codeDocumentFragment.Insert(0, newFragment); }