예제 #1
0
        public static SourceLocation Advance(SourceLocation location, string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            var tracker = new SourceLocationTracker(location);

            tracker.UpdateLocation(text);
            return(tracker.CurrentLocation);
        }
        public void UpdateLocationAdvancesCorrectlyForMultiLineString()
        {
            // Arrange
            var tracker = new SourceLocationTracker(TestStartLocation);

            // Act
            tracker.UpdateLocation("foo\nbar\rbaz\r\nbox");

            // Assert
            Assert.Equal(26, tracker.CurrentLocation.AbsoluteIndex);
            Assert.Equal(45, tracker.CurrentLocation.LineIndex);
            Assert.Equal(3, tracker.CurrentLocation.CharacterIndex);
        }
예제 #3
0
        public void Accept(ISymbol symbol)
        {
            if (symbol == null)
            {
                return;
            }

            if (Start.Equals(SourceLocation.Undefined))
            {
                throw new InvalidOperationException("SpanBuilder must have a valid location");
            }

            _symbols.Add(symbol);
            _tracker.UpdateLocation(symbol.Content);
        }
        public void Accept(IToken token)
        {
            if (token == null)
            {
                return;
            }

            if (Start.Equals(SourceLocation.Undefined))
            {
                throw new InvalidOperationException("SpanBuilder must have a valid location");
            }

            _tokens.Add(token);
            _tracker.UpdateLocation(token.Content);
        }