mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
* Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * ported new BatchParser * added BatchParser tests * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests * changed env path for lab mode * added env variable to appveyor * testing env variable for appveyor * fixed lab build * debug appveyor build * testing changes for appveyor * changed trace env path * debugging appveyor build * changed baseline env path * debugging * debugging * debugging * switched on trace flag * debugging * debugging * changed build config * changed baseline files * checking baseline output * changed baseline files * debug baseline tests * debugging baseline * debugging * debugging * debug * debugging * testing baseline format * debug * debug * debug * debug * debug * newline debug * changed baseline file * debug * test * try new way to read * added execution engine tests * change test * testing file encoding * moved execution engine tests to integration * try compare without spaces * removed no op test * added env variable for travis * put batch parser tests to integration too * put batch parser in integration * try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * ported new BatchParser * added BatchParser tests * Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests changed env path for lab mode added env variable to appveyor testing env variable for appveyor fixed lab build debug appveyor build testing changes for appveyor changed trace env path debugging appveyor build changed baseline env path debugging debugging debugging switched on trace flag debugging debugging changed build config changed baseline files checking baseline output changed baseline files debug baseline tests debugging baseline debugging debugging debug debugging testing baseline format debug debug debug debug debug newline debug changed baseline file debug test try new way to read added execution engine tests change test testing file encoding moved execution engine tests to integration try compare without spaces removed no op test added env variable for travis * put batch parser tests to integration too * put batch parser in integration try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * fixed filestream writer test * added localization string * added localization string * generated new string files again * code review changes
187 lines
4.9 KiB
C#
187 lines
4.9 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.BatchParser
|
|
{
|
|
/// <summary>
|
|
/// Lexer input class used by lexer in SMO Batch Parser
|
|
/// </summary>
|
|
internal sealed class LexerInput : IDisposable
|
|
{
|
|
private readonly string filename;
|
|
private TextReader input;
|
|
private int currentLine;
|
|
private int currentColumn;
|
|
private int bufferStartOffset;
|
|
private int currentSbOffset;
|
|
private StringBuilder buffer;
|
|
|
|
/// <summary>
|
|
/// Constructor method for the LexerInput class
|
|
/// </summary>
|
|
public LexerInput(TextReader reader, string filename)
|
|
{
|
|
input = reader;
|
|
this.filename = filename;
|
|
currentLine = 1;
|
|
currentColumn = 1;
|
|
bufferStartOffset = 0;
|
|
currentSbOffset = 0;
|
|
buffer = new StringBuilder();
|
|
EnsureBytes(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get filename associated with lexer input
|
|
/// </summary>
|
|
public string Filename
|
|
{
|
|
get { return filename; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get current line associated with lexer input
|
|
/// </summary>
|
|
public int CurrentLine
|
|
{
|
|
get { return currentLine; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get current column associated with lexer input
|
|
/// </summary>
|
|
public int CurrentColumn
|
|
{
|
|
get { return currentColumn; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Consume token used by lexer input
|
|
/// </summary>
|
|
public void Consume()
|
|
{
|
|
bool newLineWithCR = false;
|
|
|
|
char? ch = Lookahead();
|
|
if (ch == null)
|
|
{
|
|
// end of stream
|
|
return;
|
|
}
|
|
else if (ch == '\r')
|
|
{
|
|
newLineWithCR = true;
|
|
}
|
|
else if (ch == '\n')
|
|
{
|
|
currentLine++;
|
|
currentColumn = 0;
|
|
}
|
|
|
|
int count = EnsureBytes(1);
|
|
if (count == 0)
|
|
{
|
|
// end of stream
|
|
return;
|
|
}
|
|
currentSbOffset++;
|
|
|
|
if (newLineWithCR && Lookahead() != '\n')
|
|
{
|
|
currentLine++;
|
|
currentColumn = 0;
|
|
}
|
|
currentColumn++;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (input != null)
|
|
{
|
|
input.Dispose();
|
|
input = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get current offset for the lexer input
|
|
/// </summary>
|
|
public int CurrentOffset
|
|
{
|
|
get { return bufferStartOffset + currentSbOffset; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ensure correct number of bytes to buffer
|
|
/// </summary>
|
|
public int EnsureBytes(int bytesToBuffer)
|
|
{
|
|
if (currentSbOffset + bytesToBuffer > buffer.Length)
|
|
{
|
|
if (input == null)
|
|
{
|
|
return buffer.Length - currentSbOffset;
|
|
}
|
|
int chArrayLength = bytesToBuffer - (buffer.Length - currentSbOffset) + 128;
|
|
char[] chArray = new char[chArrayLength];
|
|
int count = input.ReadBlock(chArray, 0, chArrayLength);
|
|
buffer.Append(chArray, 0, count);
|
|
if (count < chArrayLength)
|
|
{
|
|
input.Dispose();
|
|
input = null;
|
|
}
|
|
return buffer.Length - currentSbOffset;
|
|
}
|
|
return bytesToBuffer;
|
|
}
|
|
|
|
/// <summary>
|
|
/// look ahead bytes in lexer input
|
|
/// </summary>
|
|
public char? Lookahead()
|
|
{
|
|
int count = EnsureBytes(1);
|
|
if (count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
return buffer[currentSbOffset];
|
|
}
|
|
|
|
/// <summary>
|
|
/// look ahead bytes in lexer input
|
|
/// </summary>
|
|
public char? Lookahead(int lookahead)
|
|
{
|
|
int count = EnsureBytes(lookahead + 1);
|
|
if (count < lookahead + 1)
|
|
{
|
|
return null;
|
|
}
|
|
return buffer[currentSbOffset + lookahead];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flush buffered text in lexer input
|
|
/// </summary>
|
|
public string FlushBufferedText()
|
|
{
|
|
string text;
|
|
|
|
text = buffer.ToString(0, currentSbOffset);
|
|
bufferStartOffset += currentSbOffset;
|
|
buffer.Remove(0, currentSbOffset);
|
|
currentSbOffset = 0;
|
|
|
|
return text;
|
|
}
|
|
}
|
|
}
|