diff options
-rw-r--r-- | llex.c | 58 | ||||
-rw-r--r-- | lzio.h | 3 |
2 files changed, 33 insertions, 28 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.69 2013/08/30 16:01:37 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.70 2013/12/30 20:47:58 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -320,40 +320,39 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) { | |||
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | static void escerror (LexState *ls, int *c, int n, const char *msg) { | 323 | static void escerror (LexState *ls, const char *msg) { |
324 | int i; | 324 | if (ls->current != EOZ) |
325 | luaZ_resetbuffer(ls->buff); /* prepare error message */ | 325 | save_and_next(ls); /* add current to buffer for error message */ |
326 | save(ls, '\\'); | ||
327 | for (i = 0; i < n && c[i] != EOZ; i++) | ||
328 | save(ls, c[i]); | ||
329 | lexerror(ls, msg, TK_STRING); | 326 | lexerror(ls, msg, TK_STRING); |
330 | } | 327 | } |
331 | 328 | ||
332 | 329 | ||
330 | static int gethexa (LexState *ls) { | ||
331 | save_and_next(ls); | ||
332 | if (!lisxdigit(ls->current)) | ||
333 | escerror(ls, "hexadecimal digit expected"); | ||
334 | return luaO_hexavalue(ls->current); | ||
335 | } | ||
336 | |||
337 | |||
333 | static int readhexaesc (LexState *ls) { | 338 | static int readhexaesc (LexState *ls) { |
334 | int c[3], i; /* keep input for error message */ | 339 | int r = gethexa(ls); |
335 | int r = 0; /* result accumulator */ | 340 | r = (r << 4) + gethexa(ls); |
336 | c[0] = 'x'; /* for error message */ | 341 | luaZ_buffremove(ls->buff, 2); /* remove saved chars from buffer */ |
337 | for (i = 1; i < 3; i++) { /* read two hexadecimal digits */ | ||
338 | c[i] = next(ls); | ||
339 | if (!lisxdigit(c[i])) | ||
340 | escerror(ls, c, i + 1, "hexadecimal digit expected"); | ||
341 | r = (r << 4) + luaO_hexavalue(c[i]); | ||
342 | } | ||
343 | return r; | 342 | return r; |
344 | } | 343 | } |
345 | 344 | ||
346 | 345 | ||
347 | static int readdecesc (LexState *ls) { | 346 | static int readdecesc (LexState *ls) { |
348 | int c[3], i; | 347 | int i; |
349 | int r = 0; /* result accumulator */ | 348 | int r = 0; /* result accumulator */ |
350 | for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ | 349 | for (i = 0; i < 3 && lisdigit(ls->current); i++) { /* read up to 3 digits */ |
351 | c[i] = ls->current; | 350 | r = 10*r + ls->current - '0'; |
352 | r = 10*r + c[i] - '0'; | 351 | save_and_next(ls); |
353 | next(ls); | ||
354 | } | 352 | } |
355 | if (r > UCHAR_MAX) | 353 | if (r > UCHAR_MAX) |
356 | escerror(ls, c, i, "decimal escape too large"); | 354 | escerror(ls, "decimal escape too large"); |
355 | luaZ_buffremove(ls->buff, i); /* remove read digits from buffer */ | ||
357 | return r; | 356 | return r; |
358 | } | 357 | } |
359 | 358 | ||
@@ -371,7 +370,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { | |||
371 | break; /* to avoid warnings */ | 370 | break; /* to avoid warnings */ |
372 | case '\\': { /* escape sequences */ | 371 | case '\\': { /* escape sequences */ |
373 | int c; /* final character to be saved */ | 372 | int c; /* final character to be saved */ |
374 | next(ls); /* do not save the `\' */ | 373 | save_and_next(ls); /* keep '\\' for error messages */ |
375 | switch (ls->current) { | 374 | switch (ls->current) { |
376 | case 'a': c = '\a'; goto read_save; | 375 | case 'a': c = '\a'; goto read_save; |
377 | case 'b': c = '\b'; goto read_save; | 376 | case 'b': c = '\b'; goto read_save; |
@@ -387,6 +386,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { | |||
387 | c = ls->current; goto read_save; | 386 | c = ls->current; goto read_save; |
388 | case EOZ: goto no_save; /* will raise an error next loop */ | 387 | case EOZ: goto no_save; /* will raise an error next loop */ |
389 | case 'z': { /* zap following span of spaces */ | 388 | case 'z': { /* zap following span of spaces */ |
389 | luaZ_buffremove(ls->buff, 1); /* remove '\\' */ | ||
390 | next(ls); /* skip the 'z' */ | 390 | next(ls); /* skip the 'z' */ |
391 | while (lisspace(ls->current)) { | 391 | while (lisspace(ls->current)) { |
392 | if (currIsNewline(ls)) inclinenumber(ls); | 392 | if (currIsNewline(ls)) inclinenumber(ls); |
@@ -396,14 +396,18 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { | |||
396 | } | 396 | } |
397 | default: { | 397 | default: { |
398 | if (!lisdigit(ls->current)) | 398 | if (!lisdigit(ls->current)) |
399 | escerror(ls, &ls->current, 1, "invalid escape sequence"); | 399 | escerror(ls, "invalid escape sequence"); |
400 | /* digital escape \ddd */ | 400 | c = readdecesc(ls); /* digital escape \ddd */ |
401 | c = readdecesc(ls); | ||
402 | goto only_save; | 401 | goto only_save; |
403 | } | 402 | } |
404 | } | 403 | } |
405 | read_save: next(ls); /* read next character */ | 404 | read_save: |
406 | only_save: save(ls, c); /* save 'c' */ | 405 | next(ls); |
406 | /* go through */ | ||
407 | only_save: | ||
408 | luaZ_buffremove(ls->buff, 1); /* remove '\\' */ | ||
409 | save(ls, c); | ||
410 | /* go through */ | ||
407 | no_save: break; | 411 | no_save: break; |
408 | } | 412 | } |
409 | default: | 413 | default: |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lzio.h,v 1.26 2011/07/15 12:48:03 roberto Exp roberto $ | 2 | ** $Id: lzio.h,v 1.27 2013/06/07 14:51:10 roberto Exp roberto $ |
3 | ** Buffered streams | 3 | ** Buffered streams |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -32,6 +32,7 @@ typedef struct Mbuffer { | |||
32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) | 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) |
33 | #define luaZ_bufflen(buff) ((buff)->n) | 33 | #define luaZ_bufflen(buff) ((buff)->n) |
34 | 34 | ||
35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) | ||
35 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) |
36 | 37 | ||
37 | 38 | ||