in src/Microsoft.SqlTools.ManagedBatchParser/BatchParser/Lexer.cs [468:578]
private bool RuleText()
{
char? ch = Lookahead();
if (ch.HasValue == false)
{
SetToken(LexerTokenType.Eof);
return true;
}
if (ch.HasValue)
{
if (IsNewLineChar(ch.Value))
{
AcceptNewLine();
SetState(RuleLine);
return true;
}
else if (textRuleFlags.HasFlag(TextRuleFlags.ReportWhitespace) && IsWhitespaceChar(ch.Value))
{
AcceptWhitespace();
return true;
}
else if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeBlockComment) || textRuleFlags.HasFlag(TextRuleFlags.RecognizeLineComment))
{
char? ch2 = Lookahead(1);
if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeBlockComment) && ch == '/' && ch2 == '*')
{
AcceptBlockComment();
return true;
}
else if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeLineComment) && ch == '-' && ch2 == '-')
{
AcceptLineComment();
return true;
}
}
}
while (ch.HasValue)
{
bool consumed = false;
switch (ch.Value)
{
case ' ':
case '\t':
if (textRuleFlags.HasFlag(TextRuleFlags.ReportWhitespace))
{
SetToken(LexerTokenType.Text);
return true;
}
break;
case '\r':
case '\n':
SetToken(LexerTokenType.Text);
return true;
case '"':
if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeDoubleQuotedString))
{
AcceptQuotedText('"');
consumed = true;
}
break;
case '\'':
if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeSingleQuotedString))
{
AcceptEscapableQuotedText('\'');
consumed = true;
}
break;
case '[':
if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeBrace))
{
AcceptEscapableQuotedText(']');
consumed = true;
}
break;
case '-':
if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeLineComment))
{
char? ch2 = Lookahead(1);
if (ch.HasValue && ch2 == '-')
{
SetToken(LexerTokenType.Text);
return true;
}
}
break;
case '/':
if (textRuleFlags.HasFlag(TextRuleFlags.RecognizeBlockComment))
{
char? ch2 = Lookahead(1);
if (ch.HasValue && ch2 == '*')
{
SetToken(LexerTokenType.Text);
return true;
}
}
break;
default:
break;
}
if (consumed == false)
{
Consume();
}
ch = Lookahead();
}
SetToken(LexerTokenType.Text);
return true;
}