better control of source name

This commit is contained in:
Roberto Ierusalimschy 2000-06-19 15:05:14 -03:00
parent 8d2baf719c
commit feb2083730
3 changed files with 13 additions and 11 deletions

7
llex.c
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 1.62 2000/05/26 14:04:04 roberto Exp roberto $
** $Id: llex.c,v 1.63 2000/06/12 13:52:05 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -63,7 +63,7 @@ void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) {
void luaX_syntaxerror (LexState *ls, const char *s, const char *token) {
char buff[MAXSRC];
luaL_chunkid(buff, zname(ls->z), sizeof(buff));
luaL_chunkid(buff, ls->source->str, sizeof(buff));
luaL_verror(ls->L, "%.100s;\n last token read: `%.50s' at line %d in %.80s",
s, token, ls->linenumber, buff);
}
@ -132,12 +132,13 @@ static void checkpragma (lua_State *L, LexState *LS) {
}
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z) {
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
LS->L = L;
LS->lookahead.token = TK_EOS; /* no look-ahead token */
LS->z = z;
LS->fs = NULL;
LS->linenumber = 1;
LS->source = source;
next(LS); /* read first char */
if (LS->current == '#') {
do { /* skip first line */

5
llex.h
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.27 2000/05/25 18:59:59 roberto Exp roberto $
** $Id: llex.h,v 1.28 2000/05/26 14:04:04 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -51,11 +51,12 @@ typedef struct LexState {
struct lua_State *L;
struct zio *z; /* input stream */
int linenumber; /* input line counter */
TString *source; /* current source name */
} LexState;
void luaX_init (lua_State *L);
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z);
void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source);
int luaX_lex (LexState *LS);
void luaX_checklimit (LexState *ls, int val, int limit, const char *msg);
void luaX_syntaxerror (LexState *ls, const char *s, const char *token);

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.94 2000/06/05 14:56:18 roberto Exp roberto $
** $Id: lparser.c,v 1.95 2000/06/12 13:52:05 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@ -352,7 +352,7 @@ static void pushclosure (LexState *ls, FuncState *func) {
}
static void open_func (LexState *ls, FuncState *fs, TString *source) {
static void open_func (LexState *ls, FuncState *fs) {
Proto *f = luaF_newproto(ls->L);
fs->prev = ls->fs; /* linked list of funcstates */
fs->ls = ls;
@ -364,7 +364,7 @@ static void open_func (LexState *ls, FuncState *fs, TString *source) {
fs->lastsetline = 0;
fs->bl = NULL;
fs->f = f;
f->source = source;
f->source = ls->source;
fs->pc = 0;
fs->lasttarget = 0;
fs->jlt = NO_JUMP;
@ -398,8 +398,8 @@ static void close_func (LexState *ls) {
Proto *luaY_parser (lua_State *L, ZIO *z) {
struct LexState lexstate;
struct FuncState funcstate;
luaX_setinput(L, &lexstate, z);
open_func(&lexstate, &funcstate, luaS_new(L, zname(z)));
luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z)));
open_func(&lexstate, &funcstate);
next(&lexstate); /* read first token */
chunk(&lexstate);
check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
@ -1128,7 +1128,7 @@ static void parlist (LexState *ls) {
static void body (LexState *ls, int needself, int line) {
/* body -> '(' parlist ')' chunk END */
FuncState new_fs;
open_func(ls, &new_fs, ls->fs->f->source);
open_func(ls, &new_fs);
new_fs.f->lineDefined = line;
check(ls, '(');
if (needself)