diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-09-04 17:00:28 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-09-04 17:00:28 -0300 |
| commit | 30e51f09b93eefc058fe8c42cacd5e0e158ae7f9 (patch) | |
| tree | 47b8c565c6cb871404ffbd7b6ed8b6e57a1b0242 | |
| parent | 994a37c8e88d090421afb7ca639f01f868708452 (diff) | |
| download | lua-30e51f09b93eefc058fe8c42cacd5e0e158ae7f9.tar.gz lua-30e51f09b93eefc058fe8c42cacd5e0e158ae7f9.tar.bz2 lua-30e51f09b93eefc058fe8c42cacd5e0e158ae7f9.zip | |
some changes in error reporting
| -rw-r--r-- | llex.c | 54 |
1 files changed, 24 insertions, 30 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.123 2003/08/28 14:38:46 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.124 2003/08/29 16:48:14 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 | */ |
| @@ -77,42 +77,37 @@ static void luaX_error (LexState *ls, const char *s, const char *token) { | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | void luaX_syntaxerror (LexState *ls, const char *msg) { | 80 | const char *luaX_token2str (LexState *ls, int token) { |
| 81 | const char *lasttoken; | 81 | if (token < FIRST_RESERVED) { |
| 82 | switch (ls->t.token) { | 82 | lua_assert(token == (unsigned char)token); |
| 83 | return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : | ||
| 84 | luaO_pushfstring(ls->L, "%c", token); | ||
| 85 | } | ||
| 86 | else | ||
| 87 | return token2string[token-FIRST_RESERVED]; | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | static const char *txtToken (LexState *ls, int token) { | ||
| 92 | switch (token) { | ||
| 83 | case TK_NAME: | 93 | case TK_NAME: |
| 84 | lasttoken = getstr(ls->t.seminfo.ts); | ||
| 85 | break; | ||
| 86 | case TK_STRING: | 94 | case TK_STRING: |
| 87 | case TK_NUMBER: | 95 | case TK_NUMBER: |
| 88 | save(ls, '\0'); | 96 | save(ls, '\0'); |
| 89 | lasttoken = luaZ_buffer(ls->buff); | 97 | return luaZ_buffer(ls->buff); |
| 90 | break; | ||
| 91 | default: | 98 | default: |
| 92 | lasttoken = luaX_token2str(ls, ls->t.token); | 99 | return luaX_token2str(ls, token); |
| 93 | break; | ||
| 94 | } | 100 | } |
| 95 | luaX_error(ls, msg, lasttoken); | ||
| 96 | } | 101 | } |
| 97 | 102 | ||
| 98 | 103 | ||
| 99 | const char *luaX_token2str (LexState *ls, int token) { | 104 | static void luaX_lexerror (LexState *ls, const char *msg, int token) { |
| 100 | if (token < FIRST_RESERVED) { | 105 | luaX_error(ls, msg, txtToken(ls, token)); |
| 101 | lua_assert(token == (unsigned char)token); | ||
| 102 | return luaO_pushfstring(ls->L, "%c", token); | ||
| 103 | } | ||
| 104 | else | ||
| 105 | return token2string[token-FIRST_RESERVED]; | ||
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | static void luaX_lexerror (LexState *ls, const char *s, int token) { | 109 | void luaX_syntaxerror (LexState *ls, const char *msg) { |
| 110 | if (token == TK_EOS) | 110 | luaX_lexerror(ls, msg, ls->t.token); |
| 111 | luaX_error(ls, s, luaX_token2str(ls, token)); | ||
| 112 | else { | ||
| 113 | save(ls, '\0'); | ||
| 114 | luaX_error(ls, s, luaZ_buffer(ls->buff)); | ||
| 115 | } | ||
| 116 | } | 111 | } |
| 117 | 112 | ||
| 118 | 113 | ||
| @@ -406,14 +401,13 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) { | |||
| 406 | luaZ_bufflen(ls->buff)); | 401 | luaZ_bufflen(ls->buff)); |
| 407 | if (ts->tsv.reserved > 0) /* reserved word? */ | 402 | if (ts->tsv.reserved > 0) /* reserved word? */ |
| 408 | return ts->tsv.reserved - 1 + FIRST_RESERVED; | 403 | return ts->tsv.reserved - 1 + FIRST_RESERVED; |
| 409 | seminfo->ts = ts; | 404 | else { |
| 410 | return TK_NAME; | 405 | seminfo->ts = ts; |
| 406 | return TK_NAME; | ||
| 407 | } | ||
| 411 | } | 408 | } |
| 412 | else { | 409 | else { |
| 413 | int c = ls->current; | 410 | int c = ls->current; |
| 414 | if (iscntrl(c)) | ||
| 415 | luaX_error(ls, "invalid control char", | ||
| 416 | luaO_pushfstring(ls->L, "char(%d)", c)); | ||
| 417 | next(ls); | 411 | next(ls); |
| 418 | return c; /* single-char tokens (+ - / ...) */ | 412 | return c; /* single-char tokens (+ - / ...) */ |
| 419 | } | 413 | } |
