@@ -123,7 +123,7 @@ Parser::Parser(thread_db* tdbb, MemoryPool& pool, DsqlCompilerScratch* aScratch,
123123 yylexemes = 0 ;
124124
125125 lex.start = string;
126- lex.line_start = lex.last_token = lex.ptr = string;
126+ lex.line_start = lex.last_token = lex.ptr = lex. leadingPtr = string;
127127 lex.end = string + length;
128128 lex.lines = 1 ;
129129 lex.att_charset = characterSet;
@@ -242,11 +242,12 @@ void Parser::transformString(const char* start, unsigned length, string& dest)
242242// Make a substring from the command text being parsed.
243243string Parser::makeParseStr (const Position& p1, const Position& p2)
244244{
245- const char * start = p1.firstPos ;
246- const char * end = p2.lastPos ;
245+ const char * start = p1.leadingFirstPos ;
246+ const char * end = p2.trailingLastPos ;
247247
248248 string str;
249249 transformString (start, end - start, str);
250+ str.trim (" \t\r\n " );
250251
251252 string ret;
252253
@@ -278,16 +279,19 @@ void Parser::yyReducePosn(YYPOSN& ret, YYPOSN* termPosns, YYSTYPE* /*termVals*/,
278279 // Accessing termPosns[-1] seems to be the only way to get correct positions in this case.
279280 ret.firstLine = ret.lastLine = termPosns[termNo - 1 ].lastLine ;
280281 ret.firstColumn = ret.lastColumn = termPosns[termNo - 1 ].lastColumn ;
281- ret.firstPos = ret.lastPos = termPosns[termNo - 1 ].lastPos ;
282+ ret.firstPos = ret.lastPos = ret.trailingLastPos = termPosns[termNo - 1 ].trailingLastPos ;
283+ ret.leadingFirstPos = termPosns[termNo - 1 ].lastPos ;
282284 }
283285 else
284286 {
285287 ret.firstLine = termPosns[0 ].firstLine ;
286288 ret.firstColumn = termPosns[0 ].firstColumn ;
287289 ret.firstPos = termPosns[0 ].firstPos ;
290+ ret.leadingFirstPos = termPosns[0 ].leadingFirstPos ;
288291 ret.lastLine = termPosns[termNo - 1 ].lastLine ;
289292 ret.lastColumn = termPosns[termNo - 1 ].lastColumn ;
290293 ret.lastPos = termPosns[termNo - 1 ].lastPos ;
294+ ret.trailingLastPos = termPosns[termNo - 1 ].trailingLastPos ;
291295 }
292296
293297 /* ** This allows us to see colored output representing the position reductions.
@@ -308,29 +312,24 @@ int Parser::yylex()
308312 yyposn.firstLine = lex.lines ;
309313 yyposn.firstColumn = lex.ptr - lex.line_start ;
310314 yyposn.firstPos = lex.ptr - 1 ;
315+ yyposn.leadingFirstPos = lex.leadingPtr ;
311316
312317 lex.prev_keyword = yylexAux ();
313318
314- const TEXT* ptr = lex.ptr ;
315- const TEXT* last_token = lex.last_token ;
316- const TEXT* line_start = lex.line_start ;
317- const SLONG lines = lex.lines ;
319+ yyposn.lastPos = lex.ptr ;
320+ lex.leadingPtr = lex.ptr ;
318321
319322 // Lets skip spaces before store lastLine/lastColumn. This is necessary to avoid yyReducePosn
320323 // produce invalid line/column information - CORE-4381.
321- yylexSkipSpaces ();
324+ bool spacesSkipped = yylexSkipSpaces ();
322325
323326 yyposn.lastLine = lex.lines ;
324327 yyposn.lastColumn = lex.ptr - lex.line_start ;
325328
326- lex.ptr = ptr;
327- lex.last_token = last_token;
328- lex.line_start = line_start;
329- lex.lines = lines;
329+ if (spacesSkipped)
330+ --lex.ptr ;
330331
331- // But the correct value for lastPos is the old (before the second yyLexSkipSpaces)
332- // value of lex.ptr.
333- yyposn.lastPos = ptr;
332+ yyposn.trailingLastPos = lex.ptr ;
334333
335334 return lex.prev_keyword ;
336335}
@@ -1269,7 +1268,7 @@ int Parser::yylexAux()
12691268}
12701269
12711270
1272- void Parser::yyerror_detailed (const TEXT* /* error_string*/ , int yychar, YYSTYPE&, YYPOSN&)
1271+ void Parser::yyerror_detailed (const TEXT* /* error_string*/ , int yychar, YYSTYPE&, YYPOSN& posn )
12731272{
12741273/* *************************************
12751274 *
@@ -1281,29 +1280,21 @@ void Parser::yyerror_detailed(const TEXT* /*error_string*/, int yychar, YYSTYPE&
12811280 * Print a syntax error.
12821281 *
12831282 **************************************/
1284- const TEXT* line_start = lex.line_start ;
1285- SLONG lines = lex.lines ;
1286- if (lex.last_token < line_start)
1287- {
1288- line_start = lex.line_start_bk ;
1289- lines--;
1290- }
1291-
12921283 if (yychar < 1 )
12931284 {
12941285 ERRD_post (Arg::Gds (isc_sqlerr) << Arg::Num (-104 ) <<
12951286 // Unexpected end of command
1296- Arg::Gds (isc_command_end_err2) << Arg::Num (lines ) <<
1297- Arg::Num (lex. last_token - line_start + 1 ));
1287+ Arg::Gds (isc_command_end_err2) << Arg::Num (posn. firstLine ) <<
1288+ Arg::Num (posn. firstColumn ));
12981289 }
12991290 else
13001291 {
13011292 ERRD_post (Arg::Gds (isc_sqlerr) << Arg::Num (-104 ) <<
13021293 // Token unknown - line %d, column %d
1303- Arg::Gds (isc_dsql_token_unk_err) << Arg::Num (lines ) <<
1304- Arg::Num (lex. last_token - line_start + 1 ) << // CVC: +1
1294+ Arg::Gds (isc_dsql_token_unk_err) << Arg::Num (posn. firstLine ) <<
1295+ Arg::Num (posn. firstColumn ) <<
13051296 // Show the token
1306- Arg::Gds (isc_random) << Arg::Str (string (lex. last_token , lex. ptr - lex. last_token )));
1297+ Arg::Gds (isc_random) << Arg::Str (string (posn. firstPos , posn. lastPos - posn. firstPos )));
13071298 }
13081299}
13091300
@@ -1317,15 +1308,12 @@ void Parser::yyerror(const TEXT* error_string)
13171308 yyerror_detailed (error_string, -1 , errt_value, errt_posn);
13181309}
13191310
1320- void Parser::yyerrorIncompleteCmd ()
1311+ void Parser::yyerrorIncompleteCmd (const YYPOSN& pos )
13211312{
1322- const TEXT* line_start = lex.line_start ;
1323- SLONG lines = lex.lines ;
1324-
13251313 ERRD_post (Arg::Gds (isc_sqlerr) << Arg::Num (-104 ) <<
13261314 // Unexpected end of command
1327- Arg::Gds (isc_command_end_err2) << Arg::Num (lines ) <<
1328- Arg::Num (lex. ptr - line_start + 1 ));
1315+ Arg::Gds (isc_command_end_err2) << Arg::Num (pos. lastLine ) <<
1316+ Arg::Num (pos. lastColumn + 1 ));
13291317}
13301318
13311319void Parser::check_bound (const char * const to, const char * const string)
0 commit comments