Esempio n. 1
0
        internal static Scope BuildBackgroundScope(SetOfSyntaxItems topItems)
        {
            Scope backgroundScope = new Scope();

            backgroundScope.SyntaxItem = BackgroundItem.Instance;
            backgroundScope.ActiveSyntaxItems = topItems;

            backgroundScope.PosStart = 0;
            backgroundScope.PosAfter = int.MaxValue;
            backgroundScope.PosHighlightStart = 0;
            backgroundScope.PosAfterHighlight = int.MaxValue;

            return backgroundScope;
        }
Esempio n. 2
0
 internal void StartNextGroup(Scope nextGroupScope)
 {
     this.m_scopeStack.Add(nextGroupScope);
 }
Esempio n. 3
0
        internal void PushScope(Scope newScope)
        {
            SyntaxItem newTopItem = newScope.SyntaxItem;

            bool previouslyExtending = this.TopScope.Extend;
            bool previouslyWithinKeepEnd = this.TopScope.IsWithinKeepEnd;

            if (this.TopScope.SyntaxItem is NextGroup) {
                this.m_scopeStack[this.m_scopeStack.Count - 1] = newScope;
            } else {
                this.m_scopeStack.Add(newScope);
            }

            this.TopScope.Extend |= previouslyExtending && !previouslyWithinKeepEnd;
            this.TopScope.IsWithinKeepEnd |= !this.TopScope.Extend && previouslyWithinKeepEnd;

            if (!newTopItem.IsTransparent || newScope.IsRegionWithMatchGroupEnd) {
                this.BuildHighlightModes(newScope.PosHighlightStart);
            }
        }
Esempio n. 4
0
        private Scope BuildNewScope(Scope currentTopScope)
        {
            Scope scope = new Scope();

            scope.PosAfter = int.MaxValue;
            scope.PosAfterHighlight = int.MaxValue;

            scope.SyntaxItem = this;
            scope.AsRegion = this;
            scope.Extend = this.Extend;
            scope.IsWithinKeepEnd = this.KeepEnd;

            scope.ActiveSyntaxItems = this.GetMatchableItems(currentTopScope);

            scope.IsRegion = true;
            scope.AsRegion = this;
            scope.IsRegionWithMatchGroupEnd = false;

            for (int i = 0; i < this.m_endPatterns.Count; i++) {
                if (this.m_endPatterns[i].HasHighlightMode) {
                    scope.IsRegionWithMatchGroupEnd = true;
                    break;
                }
            }

            return scope;
        }
Esempio n. 5
0
        internal bool TrySkips(Scanner s, Scope scope, int posMatchAt)
        {
            if (posMatchAt <= scope.PosEndSkippedUntil || scope.PosAfter != int.MaxValue) {
                return false;
            }

            MatchResult result = new MatchResult();
            result.MatchType = MatchType.RegionSkip;

            for (int i = 0; i < this.m_skipPatterns.Count; i++) {
                this.m_skipPatterns[i].Match(s, posMatchAt, scope.ExternalCaptures, ref result);

                if (result.Success) {
                    if (result.PosAfterMatch <= s.PosWindowEnd) {
                        if ('\n' == s[result.PosAfterMatch]) {
                            result.PosAfterMatch++;
                        }
                    }

                    scope.PosEndSkippedUntil = result.PosAfterMatch - 1;
                    return true;
                }
            }

            return false;
        }
Esempio n. 6
0
        internal bool TryEnding(Scanner s, Scope scope)
        {
            int posMatchAt = s.Reader.PosCurrent;

            if (posMatchAt <= scope.PosEndSkippedUntil || scope.PosAfter != int.MaxValue) {
                return false;
            }

            if (this.TrySkips(s, scope, posMatchAt)) {
                return false;
            }

            MatchResult result = new MatchResult();
            result.MatchType = MatchType.RegionEnd;

            for (int i = 0; i < this.m_endPatterns.Count; i++) {
                this.m_endPatterns[i].Match(s, posMatchAt, scope.ExternalCaptures, ref result);

                if (result.Success) {
                    scope.PosAfter = result.PosAfterMatch;

                    bool hasHighlightMode = this.m_endPatterns[i].HasHighlightMode;

                    if (0 == result.PosAfterRegion && hasHighlightMode) {
                        result.PosAfterRegion = result.PosMatchStart;
                    }

                    if (0 == result.PosAfterHighlight) {
                        result.PosAfterHighlight = result.PosAfterMatch;
                    }

                    if (hasHighlightMode && result.PosAfterRegion < result.PosAfterHighlight) {
                        s.SendMode(this.m_endPatterns[i].HighlightMode, result.PosAfterRegion);
                    }

                    if (result.PosAfterHighlight < result.PosAfterMatch) {
                        s.BuildHighlightModes(result.PosAfterHighlight);
                    }

                    return true;
                }
            }

            return false;
        }
Esempio n. 7
0
        internal SetOfSyntaxItems GetMatchableItems(Scope currentTopScope)
        {
            if (this.m_inheritActiveItemsFromTopScope) {
                return currentTopScope.ActiveSyntaxItems;
            }

            return this.m_containedItems;
        }
Esempio n. 8
0
        private Scope BuildNewScope(MatchResult result, Scope currentTopScope)
        {
            Scope scope = new Scope();

            scope.PosMatchedAt = result.PosMatchedAt;
            scope.PosStart = result.PosMatchStart;
            scope.PosAfter = result.PosAfterMatch;

            scope.PosHighlightStart = result.PosHighlightStart;
            scope.PosAfterHighlight = result.PosAfterHighlight;

            scope.SyntaxItem = this;
            scope.Extend = this.Extend;
            scope.EatNewLineInRegion = this.Pattern.EatNewLine;

            scope.ActiveSyntaxItems = this.GetMatchableItems(currentTopScope);

            return scope;
        }