diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-02-11 18:56:46 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-02-11 18:56:46 -0200 |
commit | aafa106d108581ab8b259bfde3bcf1166a17c3e9 (patch) | |
tree | f49a41e5175f87fcf186e55196089b05d3f54132 | |
parent | 29b7b8e52cc9ff7ca39869c1aad98a3b7860c09a (diff) | |
download | lua-aafa106d108581ab8b259bfde3bcf1166a17c3e9.tar.gz lua-aafa106d108581ab8b259bfde3bcf1166a17c3e9.tar.bz2 lua-aafa106d108581ab8b259bfde3bcf1166a17c3e9.zip |
implementation of numerical escape sequences in strings ("\12");
better error messages for wrong tokens
-rw-r--r-- | llex.c | 61 |
1 files changed, 41 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.13 1998/01/09 14:44:55 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.14 1998/01/19 20:18:02 roberto Exp roberto $ |
3 | ** Lexical Analizer | 3 | ** Lexical Analizer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -126,7 +126,7 @@ static void ifskip (LexState *LS) | |||
126 | if (LS->current == '\n') | 126 | if (LS->current == '\n') |
127 | inclinenumber(LS); | 127 | inclinenumber(LS); |
128 | else if (LS->current == EOZ) | 128 | else if (LS->current == EOZ) |
129 | luaY_syntaxerror("input ends inside a $if", ""); | 129 | luaY_error("input ends inside a $if"); |
130 | else next(LS); | 130 | else next(LS); |
131 | } | 131 | } |
132 | } | 132 | } |
@@ -218,8 +218,8 @@ static int read_long_string (LexState *LS, YYSTYPE *l) | |||
218 | while (1) { | 218 | while (1) { |
219 | switch (LS->current) { | 219 | switch (LS->current) { |
220 | case EOZ: | 220 | case EOZ: |
221 | save(0); | 221 | luaY_error("unfinished long string"); |
222 | return WRONGTOKEN; | 222 | return 0; /* to avoid warnings */ |
223 | case '[': | 223 | case '[': |
224 | save_and_next(LS); | 224 | save_and_next(LS); |
225 | if (LS->current == '[') { | 225 | if (LS->current == '[') { |
@@ -319,8 +319,8 @@ int luaY_lex (YYSTYPE *l) | |||
319 | switch (LS->current) { | 319 | switch (LS->current) { |
320 | case EOZ: | 320 | case EOZ: |
321 | case '\n': | 321 | case '\n': |
322 | save(0); | 322 | luaY_error("unfinished string"); |
323 | return WRONGTOKEN; | 323 | return 0; /* to avoid warnings */ |
324 | case '\\': | 324 | case '\\': |
325 | next(LS); /* do not save the '\' */ | 325 | next(LS); /* do not save the '\' */ |
326 | switch (LS->current) { | 326 | switch (LS->current) { |
@@ -328,7 +328,29 @@ int luaY_lex (YYSTYPE *l) | |||
328 | case 't': save('\t'); next(LS); break; | 328 | case 't': save('\t'); next(LS); break; |
329 | case 'r': save('\r'); next(LS); break; | 329 | case 'r': save('\r'); next(LS); break; |
330 | case '\n': save('\n'); inclinenumber(LS); break; | 330 | case '\n': save('\n'); inclinenumber(LS); break; |
331 | default : save_and_next(LS); break; | 331 | case '\\': case '"': case '\'': { |
332 | save(LS->current); | ||
333 | next(LS); | ||
334 | break; | ||
335 | } | ||
336 | default : { | ||
337 | if (isdigit(LS->current)) { | ||
338 | int c = 0; | ||
339 | int i = 0; | ||
340 | do { | ||
341 | c = 10*c + (LS->current-'0'); | ||
342 | i++; | ||
343 | next(LS); | ||
344 | } while (i<3 && isdigit(LS->current)); | ||
345 | save(c); | ||
346 | } | ||
347 | else { | ||
348 | save('\\'); | ||
349 | save(LS->current); | ||
350 | luaY_error("invalid escape sequence"); | ||
351 | } | ||
352 | break; | ||
353 | } | ||
332 | } | 354 | } |
333 | break; | 355 | break; |
334 | default: | 356 | default: |
@@ -363,13 +385,13 @@ int luaY_lex (YYSTYPE *l) | |||
363 | case '5': case '6': case '7': case '8': case '9': | 385 | case '5': case '6': case '7': case '8': case '9': |
364 | a=0.0; | 386 | a=0.0; |
365 | do { | 387 | do { |
366 | a=10.0*a+(LS->current-'0'); | 388 | a = 10.0*a + (LS->current-'0'); |
367 | save_and_next(LS); | 389 | save_and_next(LS); |
368 | } while (isdigit(LS->current)); | 390 | } while (isdigit(LS->current)); |
369 | if (LS->current == '.') { | 391 | if (LS->current == '.') { |
370 | save_and_next(LS); | 392 | save_and_next(LS); |
371 | if (LS->current == '.') { | 393 | if (LS->current == '.') { |
372 | save(0); | 394 | save('.'); |
373 | luaY_error( | 395 | luaY_error( |
374 | "ambiguous syntax (decimal point x string concatenation)"); | 396 | "ambiguous syntax (decimal point x string concatenation)"); |
375 | } | 397 | } |
@@ -378,27 +400,27 @@ int luaY_lex (YYSTYPE *l) | |||
378 | { double da=0.1; | 400 | { double da=0.1; |
379 | while (isdigit(LS->current)) | 401 | while (isdigit(LS->current)) |
380 | { | 402 | { |
381 | a+=(LS->current-'0')*da; | 403 | a += (LS->current-'0')*da; |
382 | da/=10.0; | 404 | da /= 10.0; |
383 | save_and_next(LS); | 405 | save_and_next(LS); |
384 | } | 406 | } |
385 | if (toupper(LS->current) == 'E') { | 407 | if (toupper(LS->current) == 'E') { |
386 | int e=0; | 408 | int e = 0; |
387 | int neg; | 409 | int neg; |
388 | double ea; | 410 | double ea; |
389 | save_and_next(LS); | 411 | save_and_next(LS); |
390 | neg=(LS->current=='-'); | 412 | neg = (LS->current=='-'); |
391 | if (LS->current == '+' || LS->current == '-') save_and_next(LS); | 413 | if (LS->current == '+' || LS->current == '-') save_and_next(LS); |
392 | if (!isdigit(LS->current)) { | 414 | if (!isdigit(LS->current)) |
393 | save(0); return WRONGTOKEN; } | 415 | luaY_error("invalid numeral format"); |
394 | do { | 416 | do { |
395 | e=10.0*e+(LS->current-'0'); | 417 | e = 10.0*e + (LS->current-'0'); |
396 | save_and_next(LS); | 418 | save_and_next(LS); |
397 | } while (isdigit(LS->current)); | 419 | } while (isdigit(LS->current)); |
398 | for (ea=neg?0.1:10.0; e>0; e>>=1) | 420 | for (ea=neg?0.1:10.0; e>0; e>>=1) |
399 | { | 421 | { |
400 | if (e & 1) a*=ea; | 422 | if (e & 1) a *= ea; |
401 | ea*=ea; | 423 | ea *= ea; |
402 | } | 424 | } |
403 | } | 425 | } |
404 | l->vReal = a; | 426 | l->vReal = a; |
@@ -406,9 +428,8 @@ int luaY_lex (YYSTYPE *l) | |||
406 | } | 428 | } |
407 | 429 | ||
408 | case EOZ: | 430 | case EOZ: |
409 | save(0); | ||
410 | if (LS->iflevel > 0) | 431 | if (LS->iflevel > 0) |
411 | luaY_syntaxerror("input ends inside a $if", ""); | 432 | luaY_error("input ends inside a $if"); |
412 | return 0; | 433 | return 0; |
413 | 434 | ||
414 | default: | 435 | default: |