Beispiel #1
0
        private void ParseText(Row Row, Segment CurrentSegment, string Text)
        {
            int  CurrentPosition = 0;
            bool HasComplex      = true;

            while (true)
            {
                ScanResultWord Word = GetNextWord(Text, CurrentSegment, CurrentPosition,
                                                  ref HasComplex);

                if (!Word.HasContent)
                {
                    ParseTools.AddString(Text.Substring(CurrentPosition), Row,
                                         CurrentSegment.BlockType.Style, CurrentSegment);
                    break;
                }
                else
                {
                    ParseTools.AddString(Text.Substring(CurrentPosition, Word.Position -
                                                        CurrentPosition), Row,
                                         CurrentSegment.BlockType.Style, CurrentSegment);
                    ParseTools.AddPatternString(Word.Token, Row, Word.Pattern,
                                                Word.ParentList.Style, CurrentSegment,
                                                false);
                    CurrentPosition = Word.Position + Word.Token.Length;
                }
            }
        }
Beispiel #2
0
        private void InternalParseLine(int index, bool ParseKeywords)
        {
            if (this.mLanguage == null)
            {
                return;
            }

            //
            //			if (ParseKeywords)
            //				return;
            //			ParseKeywords=true;
            SyntaxDocument doc             = Document;
            Row            Row             = doc[index];
            Segment        OldEndSegment   = Row.EndSegment;
            Segment        OldStartSegment = Row.StartSegment;
            bool           Fold            = !Row.IsCollapsed;


            if (Row.IsCollapsedEndPart)
            {
                //Row.Expansion_EndSegment.Expanded = true;
                //Row.Expansion_EndSegment.EndRow = null;
                Row.Expansion_EndSegment.EndWord = null;
            }


            //set startsegment for this row
            if (index > 0)
            {
                Row.StartSegment = Document[index - 1].EndSegment;
            }
            else
            {
                if (Row.StartSegment == null)
                {
                    Row.StartSegment           = new Segment(Row);
                    Row.StartSegment.BlockType = this.mLanguage.MainBlock;
                }
            }

            int     CurrentPosition = 0;
            Segment CurrentSegment  = Row.StartSegment;


            //kör tills vi kommit till slutet av raden..
            Row.EndSegments.Clear();
            Row.StartSegments.Clear();
            Row.Clear();
            //		bool HasEndSegment=false;

            while (true)
            {
                ScanResultSegment ChildSegment = GetNextChildSegment(Row,
                                                                     CurrentSegment, CurrentPosition);
                ScanResultSegment EndSegment = GetEndSegment(Row, CurrentSegment,
                                                             CurrentPosition);

                if ((EndSegment.HasContent && ChildSegment.HasContent &&
                     EndSegment.Position <= ChildSegment.Position) ||
                    (EndSegment.HasContent && ChildSegment.HasContent == false))
                {
                    //this is an end segment

                    if (ParseKeywords)
                    {
                        string Text = Row.Text.Substring(CurrentPosition,
                                                         EndSegment.Position - CurrentPosition);
                        ParseText(Row, CurrentSegment, Text);
                    }

                    Segment oldseg = CurrentSegment;
                    while (CurrentSegment != EndSegment.Segment)
                    {
                        Row.EndSegments.Add(CurrentSegment);
                        CurrentSegment = CurrentSegment.Parent;
                    }
                    Row.EndSegments.Add(CurrentSegment);

                    TextStyle st2 = CurrentSegment.Scope.Style;

                    ParseTools.AddPatternString(EndSegment.Token, Row, EndSegment.Pattern,
                                                st2, CurrentSegment, false);
                    while (oldseg != EndSegment.Segment)
                    {
                        oldseg.EndRow  = Row;
                        oldseg.EndWord = Row[Row.Count - 1];
                        oldseg         = oldseg.Parent;
                    }

                    CurrentSegment.EndRow  = Row;
                    CurrentSegment.EndWord = Row[Row.Count - 1];


                    if (CurrentSegment.Parent != null)
                    {
                        CurrentSegment = CurrentSegment.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=CurrentSegment.BlockType.Style;
                        ParseText(Row, CurrentSegment, Text);
                        //ParseTools.AddString (Text,Row,st,CurrentSegment);
                    }


                    Segment NewSeg = new Segment();
                    NewSeg.Parent    = CurrentSegment;
                    NewSeg.BlockType = ChildSegment.BlockType;
                    NewSeg.Scope     = ChildSegment.Scope;

                    Row.StartSegments.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];


                    CurrentSegment  = NewSeg;
                    CurrentPosition = ChildSegment.Position + ChildSegment.Token.Length;

                    if (ChildSegment.Scope.SpawnBlockOnStart != null)
                    {
                        Segment SpawnSeg = new Segment();
                        SpawnSeg.Parent    = NewSeg;
                        SpawnSeg.BlockType = ChildSegment.Scope.SpawnBlockOnStart;
                        SpawnSeg.Scope     = new Scope();
                        SpawnSeg.StartWord = NewSeg.StartWord;
                        Row.StartSegments.Add(SpawnSeg);
                        CurrentSegment = 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=CurrentSegment.BlockType.Style;
                            ParseText(Row, CurrentSegment, Text);
                            //ParseTools.AddString (Text,Row,st,CurrentSegment);
                        }
                    }
                    break;
                }
            }

            while (!CurrentSegment.BlockType.MultiLine)
            {
                Row.EndSegments.Add(CurrentSegment);
                CurrentSegment = CurrentSegment.Parent;
            }

            Row.EndSegment = CurrentSegment;
            Row.SetExpansionSegment();

            if (ParseKeywords)
            {
                Row.RowState = RowState.AllParsed;
            }
            else
            {
                Row.RowState = RowState.SegmentParsed;
            }

            if (IsSameButDifferent(index, OldStartSegment))
            {
                MakeSame(index);
                //if (!IsSameButDifferent(index))
                //	System.Diagnostics.Debugger.Break();
            }

            if (Row.CanFold)
            {
                Row.Expansion_StartSegment.Expanded = Fold;
            }

            //dont flag next line as needs parsing if only parsing keywords
            if (!ParseKeywords)
            {
                if (OldEndSegment != null)
                {
                    if (Row.EndSegment != OldEndSegment && index <= Document.Count - 2)
                    {
                        //if (Row.CanFold)
                        //	Row.Expansion_StartSegment.Expanded = true;
                        Document[index + 1].AddToParseQueue();
                        Document.NeedResetRows = true;
                    }
                }
                else if (index <= Document.Count - 2)
                {
                    //if (Row.CanFold)
                    //	Row.Expansion_StartSegment.Expanded = true;
                    Document[index + 1].AddToParseQueue();
                    Document.NeedResetRows = true;
                }
            }

            if (OldEndSegment != null)
            {
                //expand segment if this line dont have an end word
                if (OldEndSegment.EndWord == null)
                {
                    OldEndSegment.Expanded = true;
                }
            }
        }