Beispiel #1
0
        public virtual int ResetIndentation()
        {
            var scopesToClose = IndentLevels.Count;

            CurrentIndentLevel = 0;
            IndentLevels.Clear();

            return(scopesToClose);
        }
Beispiel #2
0
        public virtual IEnumerable <ScopeState> BalanceScope()
        {
            if (!TrackScopesInCurrentLine)
            {
                return(Enumerable.Empty <ScopeState>());
            }

            if (IndentLevels.Count == 0 || IndentLevels.Peek() < CurrentIndentLevel)
            {
                IndentLevels.Push(CurrentIndentLevel);

                return(new[] { ScopeState.Begin });
            }

            if (IndentLevels.Peek() > CurrentIndentLevel)
            {
                var scopesOpened = IndentLevels.Count;

                do
                {
                    IndentLevels.Pop();

                    if (IndentLevels.Count == 0 || IndentLevels.Peek() < CurrentIndentLevel)
                    {
                        return new[] { ScopeState.Inconsistent }
                    }
                    ;
                }while (IndentLevels.Peek() > CurrentIndentLevel);

                var scopesToClose = scopesOpened - IndentLevels.Count;

                return(Enumerable.Repeat(ScopeState.End, scopesToClose));
            }

            return(Enumerable.Empty <ScopeState>());
        }