@@ -101,7 +101,7 @@ Parser::Parser(MemoryPool& pool, DsqlCompilerScratch* aScratch, USHORT aClientDi
101101 yylexemes = 0 ;
102102
103103 lex.start = string;
104- lex.line_start = lex.last_token = lex.ptr = string;
104+ lex.line_start = lex.last_token = lex.ptr = lex. leadingPtr = string;
105105 lex.end = string + length;
106106 lex.lines = 1 ;
107107 lex.att_charset = characterSet;
@@ -217,11 +217,12 @@ void Parser::transformString(const char* start, unsigned length, string& dest)
217217// Make a substring from the command text being parsed.
218218string Parser::makeParseStr (const Position& p1, const Position& p2)
219219{
220- const char * start = p1.firstPos ;
221- const char * end = p2.lastPos ;
220+ const char * start = p1.leadingFirstPos ;
221+ const char * end = p2.trailingLastPos ;
222222
223223 string str;
224224 transformString (start, end - start, str);
225+ str.trim (" \t\r\n " );
225226
226227 string ret;
227228
@@ -254,15 +255,18 @@ void Parser::yyReducePosn(YYPOSN& ret, YYPOSN* termPosns, YYSTYPE* /*termVals*/,
254255 ret.firstLine = ret.lastLine = termPosns[termNo - 1 ].lastLine ;
255256 ret.firstColumn = ret.lastColumn = termPosns[termNo - 1 ].lastColumn ;
256257 ret.firstPos = ret.lastPos = termPosns[termNo - 1 ].lastPos ;
258+ ret.leadingFirstPos = ret.trailingLastPos = termPosns[termNo - 1 ].trailingLastPos ;
257259 }
258260 else
259261 {
260262 ret.firstLine = termPosns[0 ].firstLine ;
261263 ret.firstColumn = termPosns[0 ].firstColumn ;
262264 ret.firstPos = termPosns[0 ].firstPos ;
265+ ret.leadingFirstPos = termPosns[0 ].leadingFirstPos ;
263266 ret.lastLine = termPosns[termNo - 1 ].lastLine ;
264267 ret.lastColumn = termPosns[termNo - 1 ].lastColumn ;
265268 ret.lastPos = termPosns[termNo - 1 ].lastPos ;
269+ ret.trailingLastPos = termPosns[termNo - 1 ].trailingLastPos ;
266270 }
267271
268272 /* ** This allows us to see colored output representing the position reductions.
@@ -283,29 +287,24 @@ int Parser::yylex()
283287 yyposn.firstLine = lex.lines ;
284288 yyposn.firstColumn = lex.ptr - lex.line_start ;
285289 yyposn.firstPos = lex.ptr - 1 ;
290+ yyposn.leadingFirstPos = lex.leadingPtr ;
286291
287292 lex.prev_keyword = yylexAux ();
288293
289- const TEXT* ptr = lex.ptr ;
290- const TEXT* last_token = lex.last_token ;
291- const TEXT* line_start = lex.line_start ;
292- const SLONG lines = lex.lines ;
294+ yyposn.lastPos = lex.ptr ;
295+ lex.leadingPtr = lex.ptr ;
293296
294297 // Lets skip spaces before store lastLine/lastColumn. This is necessary to avoid yyReducePosn
295298 // produce invalid line/column information - CORE-4381.
296- yylexSkipSpaces ();
299+ bool spacesSkipped = yylexSkipSpaces ();
297300
298301 yyposn.lastLine = lex.lines ;
299302 yyposn.lastColumn = lex.ptr - lex.line_start ;
300303
301- lex.ptr = ptr;
302- lex.last_token = last_token;
303- lex.line_start = line_start;
304- lex.lines = lines;
304+ if (spacesSkipped)
305+ --lex.ptr ;
305306
306- // But the correct value for lastPos is the old (before the second yyLexSkipSpaces)
307- // value of lex.ptr.
308- yyposn.lastPos = ptr;
307+ yyposn.trailingLastPos = lex.ptr ;
309308
310309 return lex.prev_keyword ;
311310}
@@ -1138,7 +1137,7 @@ int Parser::yylexAux()
11381137}
11391138
11401139
1141- void Parser::yyerror_detailed (const TEXT* /* error_string*/ , int yychar, YYSTYPE&, YYPOSN&)
1140+ void Parser::yyerror_detailed (const TEXT* /* error_string*/ , int yychar, YYSTYPE&, YYPOSN& posn )
11421141{
11431142/* *************************************
11441143 *
@@ -1150,29 +1149,21 @@ void Parser::yyerror_detailed(const TEXT* /*error_string*/, int yychar, YYSTYPE&
11501149 * Print a syntax error.
11511150 *
11521151 **************************************/
1153- const TEXT* line_start = lex.line_start ;
1154- SLONG lines = lex.lines ;
1155- if (lex.last_token < line_start)
1156- {
1157- line_start = lex.line_start_bk ;
1158- lines--;
1159- }
1160-
11611152 if (yychar < 1 )
11621153 {
11631154 ERRD_post (Arg::Gds (isc_sqlerr) << Arg::Num (-104 ) <<
11641155 // Unexpected end of command
1165- Arg::Gds (isc_command_end_err2) << Arg::Num (lines ) <<
1166- Arg::Num (lex. last_token - line_start + 1 ));
1156+ Arg::Gds (isc_command_end_err2) << Arg::Num (posn. firstLine ) <<
1157+ Arg::Num (posn. firstColumn ));
11671158 }
11681159 else
11691160 {
11701161 ERRD_post (Arg::Gds (isc_sqlerr) << Arg::Num (-104 ) <<
11711162 // Token unknown - line %d, column %d
1172- Arg::Gds (isc_dsql_token_unk_err) << Arg::Num (lines ) <<
1173- Arg::Num (lex. last_token - line_start + 1 ) << // CVC: +1
1163+ Arg::Gds (isc_dsql_token_unk_err) << Arg::Num (posn. firstLine ) <<
1164+ Arg::Num (posn. firstColumn ) << // CVC: +1
11741165 // Show the token
1175- Arg::Gds (isc_random) << Arg::Str (string (lex. last_token , lex. ptr - lex. last_token )));
1166+ Arg::Gds (isc_random) << Arg::Str (string (posn. firstPos , posn. lastPos - posn. firstPos )));
11761167 }
11771168}
11781169
@@ -1186,15 +1177,12 @@ void Parser::yyerror(const TEXT* error_string)
11861177 yyerror_detailed (error_string, -1 , errt_value, errt_posn);
11871178}
11881179
1189- void Parser::yyerrorIncompleteCmd ()
1180+ void Parser::yyerrorIncompleteCmd (const YYPOSN& pos )
11901181{
1191- const TEXT* line_start = lex.line_start ;
1192- SLONG lines = lex.lines ;
1193-
11941182 ERRD_post (Arg::Gds (isc_sqlerr) << Arg::Num (-104 ) <<
11951183 // Unexpected end of command
1196- Arg::Gds (isc_command_end_err2) << Arg::Num (lines ) <<
1197- Arg::Num (lex. ptr - line_start + 1 ));
1184+ Arg::Gds (isc_command_end_err2) << Arg::Num (pos. lastLine ) <<
1185+ Arg::Num (pos. lastColumn + 1 ));
11981186}
11991187
12001188void Parser::check_bound (const char * const to, const char * const string)
0 commit comments