@@ -235,20 +235,23 @@ bool is_numeric(char buffer[])
235
235
236
236
void skip_whitespace (void )
237
237
{
238
+ int pos = SOURCE -> size ;
238
239
while (true) {
239
- if (is_linebreak (next_char )) {
240
- SOURCE -> size += 2 ;
241
- next_char = SOURCE -> elements [SOURCE -> size ];
240
+ /* Handle backslash-newline (line continuation) using local pos */
241
+ if (next_char == '\\' && SOURCE -> elements [pos + 1 ] == '\n' ) {
242
+ pos += 2 ;
243
+ next_char = SOURCE -> elements [pos ];
242
244
continue ;
243
245
}
244
246
if (is_whitespace (next_char ) ||
245
247
(skip_newline && is_newline (next_char ))) {
246
- SOURCE -> size ++ ;
247
- next_char = SOURCE -> elements [SOURCE -> size ];
248
+ pos ++ ;
249
+ next_char = SOURCE -> elements [pos ];
248
250
continue ;
249
251
}
250
252
break ;
251
253
}
254
+ SOURCE -> size = pos ;
252
255
}
253
256
254
257
char read_char (bool is_skip_space )
@@ -296,27 +299,42 @@ token_t lex_token_internal(bool aliasing)
296
299
/* C-style comments */
297
300
if (next_char == '*' ) {
298
301
/* in a comment, skip until end */
302
+ int pos = SOURCE -> size ;
299
303
do {
300
- read_char (false);
304
+ /* advance one char */
305
+ pos ++ ;
306
+ next_char = SOURCE -> elements [pos ];
301
307
if (next_char == '*' ) {
302
- read_char (false);
308
+ /* look ahead */
309
+ pos ++ ;
310
+ next_char = SOURCE -> elements [pos ];
303
311
if (next_char == '/' ) {
304
- read_char (true);
312
+ /* consume closing '/', then commit and skip trailing
313
+ * whitespaces
314
+ */
315
+ pos ++ ;
316
+ next_char = SOURCE -> elements [pos ];
317
+ SOURCE -> size = pos ;
318
+ skip_whitespace ();
305
319
return lex_token_internal (aliasing );
306
320
}
307
321
}
308
322
} while (next_char );
309
323
324
+ SOURCE -> size = pos ;
310
325
if (!next_char )
311
326
error ("Unenclosed C-style comment" );
312
327
return lex_token_internal (aliasing );
313
328
}
314
329
315
330
/* C++-style comments */
316
331
if (next_char == '/' ) {
332
+ int pos = SOURCE -> size ;
317
333
do {
318
- read_char (false);
334
+ pos ++ ;
335
+ next_char = SOURCE -> elements [pos ];
319
336
} while (next_char && !is_newline (next_char ));
337
+ SOURCE -> size = pos ;
320
338
return lex_token_internal (aliasing );
321
339
}
322
340
0 commit comments