예제 #1
0
        // consume text up to the next directive
        private SyntaxNode LexDisabledText(out bool followedByDirective)
        {
            _start = _charReader.Position;

            int  lastLineStart = _charReader.Position;
            bool allWhitespace = true;

            while (true)
            {
                char ch = _charReader.Current;
                switch (ch)
                {
                case '\0':
                    followedByDirective = false;
                    return(_charReader.Position - _start > 0 ? CreateDisabledText() : null);

                case '#':
                    followedByDirective = true;
                    if (lastLineStart < _charReader.Position && !allWhitespace)
                    {
                        goto default;
                    }

                    _charReader.Reset(lastLineStart);     // reset so directive parser can consume the starting whitespace on this line
                    return(_charReader.Position - _start > 0 ? CreateDisabledText() : null);

                case '\r':
                case '\n':
                    ReadEndOfLine();
                    lastLineStart = _charReader.Position;
                    allWhitespace = true;
                    break;

                default:
                    allWhitespace = allWhitespace && char.IsWhiteSpace(ch);
                    NextChar();
                    break;
                }
            }
        }
예제 #2
0
        public void ResetShouldResetStreamPosition()
        {
            var stream = CharReaderTest.Sentinel.ToStream();
            var reader = new CharReader(stream);

            stream.Position.Should().Be(0);
            reader.Take(3).Should().ContainInOrder('0', '1', '2');
            stream.Position.Should().NotBe(0);

            reader.Reset();
            stream.Position.Should().Be(0);
            reader.Take(3).Should().ContainInOrder('0', '1', '2');
        }