Skip to content

Commit

Permalink
Let ExtDS preprocessor and SQL parser handle '\r', '\n' and '\r\n' as…
Browse files Browse the repository at this point in the history
… end of line.

It should fix bug CORE-5783 : execute statement ignores the text of the SQL-query after a comment of the form "-"
  • Loading branch information
hvlad committed Apr 2, 2018
1 parent 07a9515 commit a9b8442
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
55 changes: 36 additions & 19 deletions src/dsql/Parser.cpp
Expand Up @@ -323,30 +323,22 @@ bool Parser::yylexSkipSpaces()
if (lex.ptr >= lex.end)
return false;

c = *lex.ptr++;
if (yylexSkipEol())
continue;

// Process comments

if (c == '\n')
{
lex.lines++;
lex.line_start = lex.ptr;
continue;
}

c = *lex.ptr++;
if (c == '-' && lex.ptr < lex.end && *lex.ptr == '-')
{
// single-line

lex.ptr++;
while (lex.ptr < lex.end)
{
if ((c = *lex.ptr++) == '\n')
{
lex.lines++;
lex.line_start = lex.ptr; // + 1; // CVC: +1 left out.
lex.ptr++;
if (yylexSkipEol())
break;
}
}
if (lex.ptr >= lex.end)
return false;
Expand All @@ -361,17 +353,14 @@ bool Parser::yylexSkipSpaces()
lex.ptr++;
while (lex.ptr < lex.end)
{
if (yylexSkipEol())
continue;

if ((c = *lex.ptr++) == '*')
{
if (*lex.ptr == '/')
break;
}
if (c == '\n')
{
lex.lines++;
lex.line_start = lex.ptr; // + 1; // CVC: +1 left out.

}
}
if (lex.ptr >= lex.end)
{
Expand All @@ -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()
{
thread_db* tdbb = JRD_get_thread_data();
Expand Down
1 change: 1 addition & 0 deletions src/dsql/Parser.h
Expand Up @@ -223,6 +223,7 @@ class Parser : public Firebird::PermanentStorage

int yylex();
bool yylexSkipSpaces();
bool yylexSkipEol(); // returns true if EOL is detected and skipped
int yylexAux();

void yyerror(const TEXT* error_string);
Expand Down
12 changes: 8 additions & 4 deletions src/jrd/extds/ExtDS.cpp
Expand Up @@ -1067,15 +1067,19 @@ static TokenType getToken(const char** begin, const char* end)
case '-':
if (p < end && *p == '-')
{
while (p < end)
while (++p < end)
{
if (*p++ == '\n')
if (*p == '\r')
{
p--;
ret = ttComment;
p++;
if (p < end && *p == '\n')
p++;
break;
}
else if (*p == '\n')
break;
}
ret = ttComment;
}
else {
ret = ttOther;
Expand Down

0 comments on commit a9b8442

Please sign in to comment.