Exemple #1
0
        public void New_Space_Succeeds()
        {
            var result = ScanToken.Space(" \t", Start);

            using (new AssertionScope())
            {
                result.Type.Should().Be(ScanTokenType.Space);
                result.Text.Should().Be(" \t");
                result.Start.Should().BeEquivalentTo(Start);
                result.End.Should().BeEquivalentTo(Start + 2);
                result.ToString().Should().Be("s( \\t)");
            }
        }
Exemple #2
0
            private IEnumerable <ScanToken> ReadWhitespace()
            {
                var position = CurrentPosition;

                var whitespace = string.Empty;
                var newline    = string.Empty;

                do
                {
                    switch (_candidate)
                    {
                    case '\r':
                        if (newline.Length > 0)
                        {
                            whitespace += '\r';
                        }
                        else
                        {
                            newline = "\r";
                        }
                        break;

                    case '\n':
                        if (whitespace.Length > 0)
                        {
                            yield return(ScanToken.Space(whitespace, position));
                        }
                        yield return(ScanToken.Newline(newline + "\n", position + (uint)whitespace.Length));

                        _column = -1;
                        _row++;
                        Next();
                        yield break;

                    default:
                        whitespace += newline + _candidate;
                        newline     = string.Empty;
                        break;
                    }
                } while (Next() && IsWhitespaceCharacter(_candidate));

                yield return(ScanToken.Space(whitespace + newline, position));
            }
 private static ScanToken Space(string text, uint absolutePosition, uint row, uint column) =>
 ScanToken.Space(text, new ScanPosition(absolutePosition, row, column));