diff options
| -rw-r--r-- | llex.c | 7 | ||||
| -rw-r--r-- | llex.h | 5 | ||||
| -rw-r--r-- | lparser.c | 12 |
3 files changed, 13 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.62 2000/05/26 14:04:04 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.63 2000/06/12 13:52:05 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 | */ |
| @@ -63,7 +63,7 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { | |||
| 63 | 63 | ||
| 64 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { | 64 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token) { |
| 65 | char buff[MAXSRC]; | 65 | char buff[MAXSRC]; |
| 66 | luaL_chunkid(buff, zname(ls->z), sizeof(buff)); | 66 | luaL_chunkid(buff, ls->source->str, sizeof(buff)); |
| 67 | luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", | 67 | luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s", |
| 68 | s, token, ls->linenumber, buff); | 68 | s, token, ls->linenumber, buff); |
| 69 | } | 69 | } |
| @@ -132,12 +132,13 @@ static void checkpragma (lua_State *L, LexState *LS) { | |||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | 134 | ||
| 135 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z) { | 135 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { |
| 136 | LS->L = L; | 136 | LS->L = L; |
| 137 | LS->lookahead.token = TK_EOS; /* no look-ahead token */ | 137 | LS->lookahead.token = TK_EOS; /* no look-ahead token */ |
| 138 | LS->z = z; | 138 | LS->z = z; |
| 139 | LS->fs = NULL; | 139 | LS->fs = NULL; |
| 140 | LS->linenumber = 1; | 140 | LS->linenumber = 1; |
| 141 | LS->source = source; | ||
| 141 | next(LS); /* read first char */ | 142 | next(LS); /* read first char */ |
| 142 | if (LS->current == '#') { | 143 | if (LS->current == '#') { |
| 143 | do { /* skip first line */ | 144 | do { /* skip first line */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.27 2000/05/25 18:59:59 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.28 2000/05/26 14:04:04 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 | */ |
| @@ -51,11 +51,12 @@ typedef struct LexState { | |||
| 51 | struct lua_State *L; | 51 | struct lua_State *L; |
| 52 | struct zio *z; /* input stream */ | 52 | struct zio *z; /* input stream */ |
| 53 | int linenumber; /* input line counter */ | 53 | int linenumber; /* input line counter */ |
| 54 | TString *source; /* current source name */ | ||
| 54 | } LexState; | 55 | } LexState; |
| 55 | 56 | ||
| 56 | 57 | ||
| 57 | void luaX_init (lua_State *L); | 58 | void luaX_init (lua_State *L); |
| 58 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z); | 59 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); |
| 59 | int luaX_lex (LexState *LS); | 60 | int luaX_lex (LexState *LS); |
| 60 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); | 61 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); |
| 61 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token); | 62 | void luaX_syntaxerror (LexState *ls, const char *s, const char *token); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.94 2000/06/05 14:56:18 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.95 2000/06/12 13:52:05 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -352,7 +352,7 @@ static void pushclosure (LexState *ls, FuncState *func) { | |||
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | 354 | ||
| 355 | static void open_func (LexState *ls, FuncState *fs, TString *source) { | 355 | static void open_func (LexState *ls, FuncState *fs) { |
| 356 | Proto *f = luaF_newproto(ls->L); | 356 | Proto *f = luaF_newproto(ls->L); |
| 357 | fs->prev = ls->fs; /* linked list of funcstates */ | 357 | fs->prev = ls->fs; /* linked list of funcstates */ |
| 358 | fs->ls = ls; | 358 | fs->ls = ls; |
| @@ -364,7 +364,7 @@ static void open_func (LexState *ls, FuncState *fs, TString *source) { | |||
| 364 | fs->lastsetline = 0; | 364 | fs->lastsetline = 0; |
| 365 | fs->bl = NULL; | 365 | fs->bl = NULL; |
| 366 | fs->f = f; | 366 | fs->f = f; |
| 367 | f->source = source; | 367 | f->source = ls->source; |
| 368 | fs->pc = 0; | 368 | fs->pc = 0; |
| 369 | fs->lasttarget = 0; | 369 | fs->lasttarget = 0; |
| 370 | fs->jlt = NO_JUMP; | 370 | fs->jlt = NO_JUMP; |
| @@ -398,8 +398,8 @@ static void close_func (LexState *ls) { | |||
| 398 | Proto *luaY_parser (lua_State *L, ZIO *z) { | 398 | Proto *luaY_parser (lua_State *L, ZIO *z) { |
| 399 | struct LexState lexstate; | 399 | struct LexState lexstate; |
| 400 | struct FuncState funcstate; | 400 | struct FuncState funcstate; |
| 401 | luaX_setinput(L, &lexstate, z); | 401 | luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z))); |
| 402 | open_func(&lexstate, &funcstate, luaS_new(L, zname(z))); | 402 | open_func(&lexstate, &funcstate); |
| 403 | next(&lexstate); /* read first token */ | 403 | next(&lexstate); /* read first token */ |
| 404 | chunk(&lexstate); | 404 | chunk(&lexstate); |
| 405 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); | 405 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); |
| @@ -1128,7 +1128,7 @@ static void parlist (LexState *ls) { | |||
| 1128 | static void body (LexState *ls, int needself, int line) { | 1128 | static void body (LexState *ls, int needself, int line) { |
| 1129 | /* body -> '(' parlist ')' chunk END */ | 1129 | /* body -> '(' parlist ')' chunk END */ |
| 1130 | FuncState new_fs; | 1130 | FuncState new_fs; |
| 1131 | open_func(ls, &new_fs, ls->fs->f->source); | 1131 | open_func(ls, &new_fs); |
| 1132 | new_fs.f->lineDefined = line; | 1132 | new_fs.f->lineDefined = line; |
| 1133 | check(ls, '('); | 1133 | check(ls, '('); |
| 1134 | if (needself) | 1134 | if (needself) |
