示例#1
0
        public bool            Inline;      //If true then at least one pair is defined in this line already

        public void Reset()
        {
            CurrentPair     = null;
            State           = ParserStateEnum.Indent;
            ChainingStarted = false;
            Inline          = false;
        }
示例#2
0
        private int GetIndent(int currentIndent, MappedPair mlPair, out bool endedByComment)
        {
            int begin = -1, end = -2, indentCounter = 1, indentSum = 0;

            endedByComment = false;
            while (_input.Next != -1)
            {
                if (_input.Next.IsSpaceCharacter())
                {
                    if (_indentSymbol == 0) //First indent defines indent standard for the whole file.
                    {
                        _indentSymbol = (char)_input.Next;
                        if (mlPair != null)
                        {
                            _indentMultiplicity = 1;                 //Calculating indent for mlPair.
                        }
                    }
                    if (mlPair == null || indentCounter <= currentIndent + _indentMultiplicity)
                    {
                        indentCounter++;
                        indentSum += _input.Next;
                        _input.Consume();
                        if (begin == -1)
                        {
                            begin = _input.Index;
                        }
                        end = _input.Index;
                    }
                    else
                    {
                        _input.Consume();
                        if (mlPair.ValueInterval == null || mlPair.ValueInterval.Begin.Index == -1)
                        {
                            mlPair.ValueInterval = new Interval(new CharLocation(_input), new CharLocation(_input));
                        }
                    }
                }
                else if (_input.ConsumeNewLine() ||
                         mlPair == null && _input.ConsumeComments(_pairFactory, _pairStack.Peek().Pair))
                {
                    indentSum     = 0;
                    indentCounter = 1;
                    begin         = -1;
                    end           = -2;
                }
                else if (mlPair != null && end - begin < currentIndent &&
                         _input.ConsumeComments(_pairFactory, _pairStack.Peek().Pair))
                {
                    //consuming less indented comments and storing comment indent (for mlPair only)
                    endedByComment = true;
                }
                else
                {
                    break;
                }
            }
            var indent = end - begin + 1;

            if (_indentMultiplicity == 0 && _input.Next != -1 && indent > 0)
            {
                _indentMultiplicity = indent;
            }
            CheckIndentErrors(indent, indentSum);
            return(indent);
        }