8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 01:23:03 +01:00

Let ExtDS preprocessor and SQL parser handle '\r', '\n' and '\r\n' as end of line.

It should fix bug CORE-5783 : execute statement ignores the text of the SQL-query after a comment of the form "-"
This commit is contained in:
hvlad 2018-04-03 01:03:36 +03:00
parent 07a95159c9
commit a9b8442b22
3 changed files with 45 additions and 23 deletions

View File

@ -323,17 +323,12 @@ bool Parser::yylexSkipSpaces()
if (lex.ptr >= lex.end) if (lex.ptr >= lex.end)
return false; return false;
c = *lex.ptr++; if (yylexSkipEol())
continue;
// Process comments // Process comments
if (c == '\n') c = *lex.ptr++;
{
lex.lines++;
lex.line_start = lex.ptr;
continue;
}
if (c == '-' && lex.ptr < lex.end && *lex.ptr == '-') if (c == '-' && lex.ptr < lex.end && *lex.ptr == '-')
{ {
// single-line // single-line
@ -341,12 +336,9 @@ bool Parser::yylexSkipSpaces()
lex.ptr++; lex.ptr++;
while (lex.ptr < lex.end) while (lex.ptr < lex.end)
{ {
if ((c = *lex.ptr++) == '\n') lex.ptr++;
{ if (yylexSkipEol())
lex.lines++;
lex.line_start = lex.ptr; // + 1; // CVC: +1 left out.
break; break;
}
} }
if (lex.ptr >= lex.end) if (lex.ptr >= lex.end)
return false; return false;
@ -361,17 +353,14 @@ bool Parser::yylexSkipSpaces()
lex.ptr++; lex.ptr++;
while (lex.ptr < lex.end) while (lex.ptr < lex.end)
{ {
if (yylexSkipEol())
continue;
if ((c = *lex.ptr++) == '*') if ((c = *lex.ptr++) == '*')
{ {
if (*lex.ptr == '/') if (*lex.ptr == '/')
break; break;
} }
if (c == '\n')
{
lex.lines++;
lex.line_start = lex.ptr; // + 1; // CVC: +1 left out.
}
} }
if (lex.ptr >= lex.end) if (lex.ptr >= lex.end)
{ {
@ -395,6 +384,34 @@ bool Parser::yylexSkipSpaces()
} }
bool Parser::yylexSkipEol()
{
bool eol = false;
const TEXT c = *lex.ptr;
if (c == '\r')
{
lex.ptr++;
if (lex.ptr < lex.end && *lex.ptr == '\n')
lex.ptr++;
eol = true;
}
else if (c == '\n')
{
lex.ptr++;
eol = true;
}
if (eol)
{
lex.lines++;
lex.line_start = lex.ptr; // + 1; // CVC: +1 left out.
}
return eol;
}
int Parser::yylexAux() int Parser::yylexAux()
{ {
thread_db* tdbb = JRD_get_thread_data(); thread_db* tdbb = JRD_get_thread_data();

View File

@ -223,6 +223,7 @@ private:
int yylex(); int yylex();
bool yylexSkipSpaces(); bool yylexSkipSpaces();
bool yylexSkipEol(); // returns true if EOL is detected and skipped
int yylexAux(); int yylexAux();
void yyerror(const TEXT* error_string); void yyerror(const TEXT* error_string);

View File

@ -1067,15 +1067,19 @@ static TokenType getToken(const char** begin, const char* end)
case '-': case '-':
if (p < end && *p == '-') if (p < end && *p == '-')
{ {
while (p < end) while (++p < end)
{ {
if (*p++ == '\n') if (*p == '\r')
{ {
p--; p++;
ret = ttComment; if (p < end && *p == '\n')
p++;
break; break;
} }
else if (*p == '\n')
break;
} }
ret = ttComment;
} }
else { else {
ret = ttOther; ret = ttOther;