aboutsummaryrefslogtreecommitdiff
path: root/lparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'lparser.c')
-rw-r--r--lparser.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/lparser.c b/lparser.c
index ffc3c674..a479d20f 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.99 2011/02/07 17:14:50 roberto Exp roberto $ 2** $Id: lparser.c,v 2.100 2011/02/07 19:00:30 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -68,6 +68,13 @@ static void anchor_token (LexState *ls) {
68} 68}
69 69
70 70
71/* semantic error */
72static void semerror (LexState *ls, const char *msg) {
73 ls->t.token = 0; /* remove 'near to' from final message */
74 luaX_syntaxerror(ls, msg);
75}
76
77
71static void error_expected (LexState *ls, int token) { 78static void error_expected (LexState *ls, int token) {
72 luaX_syntaxerror(ls, 79 luaX_syntaxerror(ls,
73 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token))); 80 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
@@ -105,6 +112,7 @@ static void check (LexState *ls, int c) {
105 error_expected(ls, c); 112 error_expected(ls, c);
106} 113}
107 114
115
108static void checknext (LexState *ls, int c) { 116static void checknext (LexState *ls, int c) {
109 check(ls, c); 117 check(ls, c);
110 luaX_next(ls); 118 luaX_next(ls);
@@ -337,9 +345,9 @@ static void closegoto (LexState *ls, int g, Labeldesc *label) {
337 lua_assert(gt->name == label->name); 345 lua_assert(gt->name == label->name);
338 if (gt->nactvar < label->nactvar) { 346 if (gt->nactvar < label->nactvar) {
339 const char *msg = luaO_pushfstring(ls->L, 347 const char *msg = luaO_pushfstring(ls->L,
340 "<goto> at line %d attemps to jump into the scope of local " LUA_QS, 348 "<goto %s> at line %d jumps into the scope of local " LUA_QS,
341 gt->line, getstr(getlocvar(fs, gt->nactvar)->varname));; 349 getstr(gt->name), gt->line, getstr(getlocvar(fs, gt->nactvar)->varname));
342 luaX_syntaxerror(ls, msg); 350 semerror(ls, msg);
343 } 351 }
344 luaK_patchlist(fs, gt->pc, label->pc); 352 luaK_patchlist(fs, gt->pc, label->pc);
345 /* remove goto from pending list */ 353 /* remove goto from pending list */
@@ -360,8 +368,7 @@ static int findlabel (LexState *ls, int g) {
360 /* check labels in current block for a match */ 368 /* check labels in current block for a match */
361 for (i = bl->firstlabel; i < dyd->label.n; i++) { 369 for (i = bl->firstlabel; i < dyd->label.n; i++) {
362 Labeldesc *lb = &dyd->label.arr[i]; 370 Labeldesc *lb = &dyd->label.arr[i];
363 if (lb->name == gt->name) { 371 if (lb->name == gt->name) { /* correct label? */
364 lua_assert(lb->pc <= gt->pc);
365 if (gt->nactvar > lb->nactvar && 372 if (gt->nactvar > lb->nactvar &&
366 (bl->upval || dyd->label.n > bl->firstlabel)) 373 (bl->upval || dyd->label.n > bl->firstlabel))
367 luaK_patchclose(ls->fs, gt->pc, lb->nactvar); 374 luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
@@ -437,7 +444,7 @@ static void leaveblock (FuncState *fs) {
437 const char *msg = luaO_pushfstring(ls->L, 444 const char *msg = luaO_pushfstring(ls->L,
438 "label " LUA_QS " (<goto> at line %d) undefined", 445 "label " LUA_QS " (<goto> at line %d) undefined",
439 getstr(gt->name), gt->line); 446 getstr(gt->name), gt->line);
440 luaX_syntaxerror(ls, msg); 447 semerror(ls, msg);
441 } 448 }
442 if (bl->previous && bl->upval) { 449 if (bl->previous && bl->upval) {
443 /* create a 'jump to here' to close upvalues */ 450 /* create a 'jump to here' to close upvalues */
@@ -1162,7 +1169,7 @@ static void breakstat (LexState *ls) {
1162 bl = bl->previous; 1169 bl = bl->previous;
1163 } 1170 }
1164 if (!bl) 1171 if (!bl)
1165 luaX_syntaxerror(ls, "no loop to break"); 1172 semerror(ls, "no loop to break");
1166 luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); 1173 luaK_concat(fs, &bl->breaklist, luaK_jump(fs));
1167 if (upval || 1174 if (upval ||
1168 (fs->nactvar > bl->nactvar && 1175 (fs->nactvar > bl->nactvar &&