Alsing.SourceCode.SyntaxDocumentParsers.DefaultParser.GetEndSegment C# (CSharp) Метод

GetEndSegment() приватный Метод

private GetEndSegment ( Row Row, Span currentSpan, int StartPos ) : ScanResultSegment
Row Row
currentSpan Span
StartPos int
Результат ScanResultSegment
        private ScanResultSegment GetEndSegment(Row Row, Span currentSpan,
                                                int StartPos)
        {
            //this row has no text , just bail out...
            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 ((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.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;
        }