private void ParseText(Row row, Span currentSpan, string Text) { int CurrentPosition = 0; bool HasComplex = true; while (true) { ScanResultWord Word = GetNextWord(Text, currentSpan, CurrentPosition, ref HasComplex); if (!Word.HasContent) { ParseTools.AddString(Text.Substring(CurrentPosition), row, currentSpan.spanDefinition.Style, currentSpan); break; } ParseTools.AddString(Text.Substring(CurrentPosition, Word.Position - CurrentPosition), row, currentSpan.spanDefinition.Style, currentSpan); ParseTools.AddPatternString(Word.Token, row, Word.Pattern, Word.ParentList.Style, currentSpan, false); CurrentPosition = Word.Position + Word.Token.Length; } }
private void InternalParseLine(int index, bool ParseKeywords) { if (mSyntaxDefinition == null) { return; } // // if (ParseKeywords) // return; // ParseKeywords=true; SyntaxDocument doc = Document; Row Row = doc[index]; Span oldEndSpan = Row.endSpan; Span oldStartSpan = Row.startSpan; bool Fold = !Row.IsCollapsed; if (Row.IsCollapsedEndPart) { //Row.expansion_EndSpan.Expanded = true; //Row.expansion_EndSpan.EndRow = null; Row.expansion_EndSpan.EndWord = null; } //set startsegment for this row if (index > 0) { Row.startSpan = Document[index - 1].endSpan; } else { if (Row.startSpan == null) { Row.startSpan = new Span(Row) { spanDefinition = mSyntaxDefinition.mainSpanDefinition }; } } int CurrentPosition = 0; Span currentSpan = Row.startSpan; //kör tills vi kommit till slutet av raden.. Row.endSpans.Clear(); Row.startSpans.Clear(); Row.Clear(); // bool HasEndSegment=false; while (true) { ScanResultSegment ChildSegment = GetNextChildSegment(Row, currentSpan, CurrentPosition); ScanResultSegment EndSegment = GetEndSegment(Row, currentSpan, CurrentPosition); if ((EndSegment.HasContent && ChildSegment.HasContent && EndSegment.Position <= ChildSegment.Position) || (EndSegment.HasContent && ChildSegment.HasContent == false)) { //this is an end span if (ParseKeywords) { string Text = Row.Text.Substring(CurrentPosition, EndSegment.Position - CurrentPosition); ParseText(Row, currentSpan, Text); } Span oldseg = currentSpan; while (currentSpan != EndSegment.span) { Row.endSpans.Add(currentSpan); currentSpan = currentSpan.Parent; } Row.endSpans.Add(currentSpan); TextStyle st2 = currentSpan.Scope.Style; ParseTools.AddPatternString(EndSegment.Token, Row, EndSegment.Pattern, st2, currentSpan, false); while (oldseg != EndSegment.span) { oldseg.EndRow = Row; oldseg.EndWord = Row[Row.Count - 1]; oldseg = oldseg.Parent; } currentSpan.EndRow = Row; currentSpan.EndWord = Row[Row.Count - 1]; if (currentSpan.Parent != null) { currentSpan = currentSpan.Parent; } CurrentPosition = EndSegment.Position + EndSegment.Token.Length; } else if (ChildSegment.HasContent) { //this is a child block if (ParseKeywords) { string Text = Row.Text.Substring(CurrentPosition, ChildSegment.Position - CurrentPosition); //TextStyle st=currentSpan.spanDefinition.Style; ParseText(Row, currentSpan, Text); //ParseTools.AddString (Text,Row,st,currentSpan); } var NewSeg = new Span { Parent = currentSpan, spanDefinition = ChildSegment.spanDefinition, Scope = ChildSegment.Scope }; Row.startSpans.Add(NewSeg); TextStyle st2 = NewSeg.Scope.Style; ParseTools.AddPatternString(ChildSegment.Token, Row, ChildSegment.Pattern, st2, NewSeg, false); NewSeg.StartRow = Row; NewSeg.StartWord = Row[Row.Count - 1]; currentSpan = NewSeg; CurrentPosition = ChildSegment.Position + ChildSegment.Token.Length; if (ChildSegment.Scope.spawnSpanOnStart != null) { var SpawnSeg = new Span { Parent = NewSeg, spanDefinition = ChildSegment.Scope.spawnSpanOnStart, Scope = new Scope(), StartWord = NewSeg.StartWord }; Row.startSpans.Add(SpawnSeg); currentSpan = SpawnSeg; } } else { if (CurrentPosition < Row.Text.Length) { if (ParseKeywords) { //we did not find a childblock nor an endblock , just output the last pice of text string Text = Row.Text.Substring(CurrentPosition); //TextStyle st=currentSpan.spanDefinition.Style; ParseText(Row, currentSpan, Text); //ParseTools.AddString (Text,Row,st,currentSpan); } } break; } } while (!currentSpan.spanDefinition.MultiLine) { Row.endSpans.Add(currentSpan); currentSpan = currentSpan.Parent; } Row.endSpan = currentSpan; Row.SetExpansionSegment(); Row.RowState = ParseKeywords ? RowState.AllParsed : RowState.SpanParsed; if (IsSameButDifferent(index, oldStartSpan)) { MakeSame(index); //if (!IsSameButDifferent(index)) // System.Diagnostics.Debugger.Break(); } if (Row.CanFold) { Row.expansion_StartSpan.Expanded = Fold; } //dont flag next line as needs parsing if only parsing keywords if (!ParseKeywords) { if (oldEndSpan != null) { if (Row.endSpan != oldEndSpan && index <= Document.Count - 2) { //if (Row.CanFold) // Row.expansion_StartSpan.Expanded = true; Document[index + 1].AddToParseQueue(); Document.NeedResetRows = true; } } else if (index <= Document.Count - 2) { //if (Row.CanFold) // Row.expansion_StartSpan.Expanded = true; Document[index + 1].AddToParseQueue(); Document.NeedResetRows = true; } } if (oldEndSpan != null) { //expand span if this line dont have an end word if (oldEndSpan.EndWord == null) { oldEndSpan.Expanded = true; } } }