Ejemplo n.º 1
0
        private ScanResult_Segment GetNextChildSegment(Row Row, Segment CurrentSegment, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length)
            {
                return(new ScanResult_Segment());
            }



            ScanResult_Segment Result = new ScanResult_Segment();

            Result.HasContent   = false; //make sure we have no content in this object
            Result.IsEndSegment = false; //nope , were looking for start blocks here

            BlockType ChildBlock;
            //foreach (BlockType ChildBlock in CurrentSegment.BlockType.ChildBlocks)

            BlockTypeCollection blocks = CurrentSegment.BlockType.ChildBlocks;

            for (int i = 0; i < blocks.Count; i++)
            {
                ChildBlock = blocks[i];
                //scan each scope in each childblock
                //foreach (Scope Scope in ChildBlock.ScopePatterns)
                Scope           Scope;
                ScopeCollection scopeColl = ChildBlock.ScopePatterns;
                for (int j = 0; j < scopeColl.Count; j++)
                {
                    Scope = scopeColl[j];

                    PatternScanResult psr = Scope.Start.IndexIn(Row.Text, StartPos, Scope.CaseSensitive, Separators);
                    int CurrentPosition   = psr.Index;
                    if ((!Result.HasContent || CurrentPosition < Result.Position) && psr.Token != "")
                    {
                        //we found a better match
                        //store this new match
                        Result.Pattern    = Scope.Start;
                        Result.Position   = CurrentPosition;
                        Result.Token      = psr.Token;
                        Result.HasContent = true;
                        Result.BlockType  = ChildBlock;
                        Result.Scope      = Scope;

                        if (Scope.NormalizeCase)
                        {
                            if (!Scope.Start.IsComplex)
                            {
                                Result.Token = Scope.Start.StringPattern;
                            }
                        }
                    }
                }
            }



            //no result ,  new ScanResult_Segment();
            if (!Result.HasContent)
            {
                return(new ScanResult_Segment());
            }

            return(Result);
        }
Ejemplo n.º 2
0
        private ScanResult_Segment GetEndSegment(Row Row, Segment CurrentSegment, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length || CurrentSegment.Scope == null)
            {
                return(new ScanResult_Segment());
            }

            ScanResult_Segment Result = new ScanResult_Segment();

            Result.HasContent   = false; //make sure we have no content in this object
            Result.IsEndSegment = false; //nope , were looking for start blocks here


            //--------------------------------------------------------------------------------
            //scan for childblocks
            //scan each scope in each childblock

            Segment seg = CurrentSegment;

            while (seg != null)
            {
                if (seg == CurrentSegment || seg.BlockType.TerminateChildren)
                {
                    foreach (Pattern end in seg.Scope.EndPatterns)
                    {
                        PatternScanResult psr = end.IndexIn(Row.Text, StartPos, seg.Scope.CaseSensitive, Separators);
                        int CurrentPosition   = psr.Index;
                        if (psr.Token != "")
                        {
                            if ((psr.Index < Result.Position && Result.HasContent) || !Result.HasContent)
                            {
                                //we found a better match
                                //store this new match
                                Result.Pattern    = end;
                                Result.Position   = CurrentPosition;
                                Result.Token      = psr.Token;
                                Result.HasContent = true;
                                Result.Segment    = seg;
                                Result.Scope      = null;


                                if (!end.IsComplex)
                                {
                                    if (seg.Scope.NormalizeCase)
                                    {
                                        if (!seg.Scope.Start.IsComplex)
                                        {
                                            Result.Token = end.StringPattern;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                seg = seg.Parent;
            }

            //no result , return new ScanResult_Segment();
            if (!Result.HasContent)
            {
                return(new ScanResult_Segment());
            }

            return(Result);
        }
Ejemplo n.º 3
0
        private ScanResult_Segment GetNextChildSegment(Row Row, Segment CurrentSegment, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length)
                return new ScanResult_Segment();



            ScanResult_Segment Result = new ScanResult_Segment();
            Result.HasContent = false; //make sure we have no content in this object
            Result.IsEndSegment = false; //nope , were looking for start blocks here

            BlockType ChildBlock;
            //foreach (BlockType ChildBlock in CurrentSegment.BlockType.ChildBlocks)

            BlockTypeCollection blocks = CurrentSegment.BlockType.ChildBlocks;

            for (int i = 0; i < blocks.Count; i++)
            {
                ChildBlock = blocks[i];
                //scan each scope in each childblock
                //foreach (Scope Scope in ChildBlock.ScopePatterns)
                Scope Scope;
                ScopeCollection scopeColl = ChildBlock.ScopePatterns;
                for (int j = 0; j < scopeColl.Count; j++)
                {
                    Scope = scopeColl[j];

                    PatternScanResult psr = Scope.Start.IndexIn(Row.Text, StartPos, Scope.CaseSensitive, Separators);
                    int CurrentPosition = psr.Index;
                    if ((!Result.HasContent || CurrentPosition < Result.Position) && psr.Token != "")
                    {
                        //we found a better match
                        //store this new match
                        Result.Pattern = Scope.Start;
                        Result.Position = CurrentPosition;
                        Result.Token = psr.Token;
                        Result.HasContent = true;
                        Result.BlockType = ChildBlock;
                        Result.Scope = Scope;

                        if (Scope.NormalizeCase)
                            if (!Scope.Start.IsComplex)
                                Result.Token = Scope.Start.StringPattern;
                    }
                }
            }






            //no result ,  new ScanResult_Segment();
            if (!Result.HasContent)
                return new ScanResult_Segment();

            return Result;
        }
Ejemplo n.º 4
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)
            {
                ScanResult_Segment ChildSegment = GetNextChildSegment(Row, CurrentSegment, CurrentPosition);
                ScanResult_Segment 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;
                }
            }
        }
Ejemplo n.º 5
0
        private ScanResult_Segment GetEndSegment(Row Row, Segment CurrentSegment, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length || CurrentSegment.Scope == null)
                return new ScanResult_Segment();

            ScanResult_Segment Result = new ScanResult_Segment();
            Result.HasContent = false; //make sure we have no content in this object
            Result.IsEndSegment = false; //nope , were looking for start blocks here


            //--------------------------------------------------------------------------------
            //scan for childblocks
            //scan each scope in each childblock

            Segment seg = CurrentSegment;

            while (seg != null)
            {
                if (seg == CurrentSegment || seg.BlockType.TerminateChildren)
                {
                    foreach (Pattern end in seg.Scope.EndPatterns)
                    {
                        PatternScanResult psr = end.IndexIn(Row.Text, StartPos, seg.Scope.CaseSensitive, Separators);
                        int CurrentPosition = psr.Index;
                        if (psr.Token != "")
                        {
                            if ((psr.Index < Result.Position && Result.HasContent) || !Result.HasContent)
                            {
                                //we found a better match
                                //store this new match
                                Result.Pattern = end;
                                Result.Position = CurrentPosition;
                                Result.Token = psr.Token;
                                Result.HasContent = true;
                                Result.Segment = seg;
                                Result.Scope = null;


                                if (!end.IsComplex)
                                {
                                    if (seg.Scope.NormalizeCase)
                                        if (!seg.Scope.Start.IsComplex)
                                            Result.Token = end.StringPattern;
                                }
                            }
                        }
                    }
                }
                seg = seg.Parent;
            }

            //no result , return new ScanResult_Segment();
            if (!Result.HasContent)
                return new ScanResult_Segment();

            return Result;
        }