Пример #1
0
        private ScanResultSegment GetNextChildSegment(Row Row, Span
                                                      currentSpan, int StartPos)
        {
            //this row has no text , just bail out...
            if (StartPos >= Row.Text.Length)
            {
                return(new ScanResultSegment());
            }


            var Result = new ScanResultSegment {
                HasContent = false, IsEndSegment = false
            };


            foreach (SpanDefinition ChildBlock in currentSpan.spanDefinition.childSpanDefinitions)
            {
                //scan each scope in each childblock
                foreach (Scope Scope in ChildBlock.ScopePatterns)
                {
                    PatternScanResult psr = Scope.Start.IndexIn(Row.Text, StartPos,
                                                                Scope.CaseSensitive, Separators);
                    int CurrentPosition = psr.Index;
                    if ((!Result.HasContent || CurrentPosition < Result.Position) &&
                        /*psr.Token != ""*/ psr.Index >= 0)     //VVV - allow empty match
                    {
                        //we found a better match
                        //store this new match
                        Result.Pattern        = Scope.Start;
                        Result.Position       = CurrentPosition;
                        Result.Token          = psr.Token;
                        Result.HasContent     = true;
                        Result.spanDefinition = ChildBlock;
                        Result.Scope          = Scope;

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


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

            return(Result);
        }
Пример #2
0
        private ScanResultSegment GetEndSegment(Row Row, Span currentSpan,
                                                int StartPos)
        {
            //this row has no text , just bail out...
            //VVV
            //if (StartPos >= Row.Text.Length || currentSpan.Scope == null)
            if (StartPos > Row.Text.Length || currentSpan.Scope == null)
            {
                return(new ScanResultSegment());
            }

            var Result = new ScanResultSegment {
                HasContent = false, IsEndSegment = false
            };


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

            Span seg = currentSpan;

            while (seg != null)
            {
                if (seg == currentSpan || seg.spanDefinition.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 ((end.IsComplex && psr.Index >= 0) || (!end.IsComplex && !string.IsNullOrEmpty(psr.Token))) //VVV - allow empty match for complex (regex) end
                        {
                            //if ((psr.Index < Result.Position && Result.HasContent) ||
                            //   !Result.HasContent)
                            if (!Result.HasContent || psr.Index < Result.Position)
                            {
                                //we found a better match
                                //store this new match
                                Result.Pattern    = end;
                                Result.Position   = CurrentPosition;
                                Result.Token      = psr.Token;
                                Result.HasContent = true;
                                Result.span       = 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 ScanResultSegment();
            if (!Result.HasContent)
            {
                return(new ScanResultSegment());
            }

            return(Result);
        }
Пример #3
0
        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;
                }
            }
        }