public void UpdateLocationDoesNotAdvanceLineIndexOnNonNewlineCharacter() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('f', () => 'o'); // Assert Assert.AreEqual(42, tracker.CurrentLocation.LineIndex); }
public void UpdateLocationAdvancesAbsoluteIndexOnSlashN() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\n', () => 'o'); // Assert Assert.AreEqual(11, tracker.CurrentLocation.AbsoluteIndex); }
public void UpdateLocationAdvancesLineIndexOnSlashN() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\n', 'o'); // Assert Assert.Equal(43, tracker.CurrentLocation.LineIndex); }
public void UpdateLocationAdvancesCharacterIndexOnNonNewlineCharacter() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('f', 'o'); // Assert Assert.Equal(46, tracker.CurrentLocation.CharacterIndex); }
public void UpdateLocationAdvancesCorrectlyForMultiLineString() { // Arrange SourceLocationTracker 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); }
protected virtual void NextCharacter() { int prevChar = CurrentCharacter; if (prevChar == -1) { return; // We're at the end of the source } if (Buffering) { if (_currentBufferPosition >= Buffer.Length - 1) { // If there are no more lookaheads (thus no need to continue with the buffer) we can just clean up the buffer if (_backtrackStack.Count == 0) { // Reset the buffer Buffer.Length = 0; _currentBufferPosition = 0; Buffering = false; } else if (!ExpandBuffer()) { // Failed to expand the buffer, because we're at the end of the source _currentBufferPosition = Buffer.Length; // Force the position past the end of the buffer } } else { // Not at the end yet, just advance the buffer pointer _currentBufferPosition++; } } else { // Just act like normal InnerReader.Read(); // Don't care about the return value, Peek() is used to get characters from the source } UpdateCurrentCharacter(); _locationTracker.UpdateLocation((char)prevChar, () => (char)CurrentCharacter); }
public override int Read() { int read = InnerBuffer.Read(); if (read != -1) { _tracker.UpdateLocation((char)read, () => { int i = Peek(); if (i == -1) { return('\0'); } else { return((char)i); } }); } return(read); }
public void UpdateLocationResetsCharacterIndexOnSlashN() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\n', 'o'); // Assert Assert.Equal(0, tracker.CurrentLocation.CharacterIndex); }
public void UpdateLocationAdvancesCharacterIndexOnSlashRFollowedBySlashN() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\r', '\n'); // Assert Assert.Equal(46, tracker.CurrentLocation.CharacterIndex); }
public void UpdateLocationAdvancesAbsoluteIndexOnSlashRFollowedByNonNewlineCharacter() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\r', 'o'); // Assert Assert.Equal(11, tracker.CurrentLocation.AbsoluteIndex); }
public void ChangeStart(SourceLocation newStart) { _start = newStart; Span current = this; SourceLocationTracker tracker = new SourceLocationTracker(newStart); tracker.UpdateLocation(Content); while ((current = current.Next) != null) { current._start = tracker.CurrentLocation; tracker.UpdateLocation(current.Content); } }
private void UpdateOffset() { SourceLocationTracker tracker = new SourceLocationTracker(); tracker.UpdateLocation(Content); Offset = tracker.CurrentLocation; }
public void UpdateLocationDoesNotAdvanceLineIndexOnSlashRFollowedBySlashN() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\r', () => '\n'); // Assert Assert.AreEqual(42, tracker.CurrentLocation.LineIndex); }
public void UpdateLocationResetsCharacterIndexOnSlashRFollowedByNonNewlineCharacter() { // Arrange SourceLocationTracker tracker = new SourceLocationTracker(TestStartLocation); // Act tracker.UpdateLocation('\r', () => 'o'); // Assert Assert.AreEqual(0, tracker.CurrentLocation.CharacterIndex); }
private void HandleWhitespaceRewriting() { Debug.Assert(!String.IsNullOrEmpty(_nextSpanToOutput.Content)); // Check the last span for trailing whitespace int endOfWhitespaceToCapture = _nextSpanToOutput.Content.Length; for (int i = _nextSpanToOutput.Content.Length - 1; i >= 0; i--) { char c = _nextSpanToOutput.Content[i]; if (CharUtils.IsNewLine(c)) { break; } else if (!Char.IsWhiteSpace(c)) { return; // Saw non-whitespace before newline, markup owns this whitespace so don't touch it } else { endOfWhitespaceToCapture = i; } } // Ok, endOfWhitespaceToCapture is now at the offset of the first whitespace character after the newline string oldContent = _nextSpanToOutput.Content; _nextSpanToOutput.Content = oldContent.Substring(0, endOfWhitespaceToCapture); SourceLocationTracker tracker = new SourceLocationTracker(); tracker.CurrentLocation = _nextSpanToOutput.Start; tracker.UpdateLocation(_nextSpanToOutput.Content); Span whitespaceSpan = new CodeSpan(tracker.CurrentLocation, oldContent.Substring(endOfWhitespaceToCapture)); Visitor.VisitSpan(_nextSpanToOutput); _nextSpanToOutput = whitespaceSpan; }