diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-07 14:36:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-07 14:36:56 -0300 |
commit | dea6b6da9422f34ad91c8f6ad9ad3ed650e95713 (patch) | |
tree | 3016b2fbcd67d75c71ee1b190aff2c24ada9b168 /lparser.c | |
parent | 71144e3ff0cb81bd9b8bb56d94dc76074c638c64 (diff) | |
download | lua-dea6b6da9422f34ad91c8f6ad9ad3ed650e95713.tar.gz lua-dea6b6da9422f34ad91c8f6ad9ad3ed650e95713.tar.bz2 lua-dea6b6da9422f34ad91c8f6ad9ad3ed650e95713.zip |
new function `lua_vpushstr' to replace uses of `sprintf'
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 37 |
1 files changed, 16 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.177 2002/04/22 14:38:52 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.178 2002/04/24 20:07:46 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 | */ |
@@ -66,10 +66,8 @@ static void lookahead (LexState *ls) { | |||
66 | 66 | ||
67 | 67 | ||
68 | static void error_expected (LexState *ls, int token) { | 68 | static void error_expected (LexState *ls, int token) { |
69 | char buff[30], t[TOKEN_LEN]; | 69 | luaX_syntaxerror(ls, |
70 | luaX_token2str(token, t); | 70 | luaO_pushstr(ls->L, "`%s' expected", luaX_token2str(ls, token))); |
71 | sprintf(buff, "`%.10s' expected", t); | ||
72 | luaK_error(ls, buff); | ||
73 | } | 71 | } |
74 | 72 | ||
75 | 73 | ||
@@ -80,7 +78,7 @@ static void check (LexState *ls, int c) { | |||
80 | } | 78 | } |
81 | 79 | ||
82 | 80 | ||
83 | #define check_condition(ls,c,msg) { if (!(c)) luaK_error(ls, msg); } | 81 | #define check_condition(ls,c,msg) { if (!(c)) luaX_syntaxerror(ls, msg); } |
84 | 82 | ||
85 | 83 | ||
86 | static int optional (LexState *ls, int c) { | 84 | static int optional (LexState *ls, int c) { |
@@ -97,13 +95,9 @@ static void check_match (LexState *ls, int what, int who, int where) { | |||
97 | if (where == ls->linenumber) | 95 | if (where == ls->linenumber) |
98 | error_expected(ls, what); | 96 | error_expected(ls, what); |
99 | else { | 97 | else { |
100 | char buff[70]; | 98 | luaX_syntaxerror(ls, luaO_pushstr(ls->L, |
101 | char t_what[TOKEN_LEN], t_who[TOKEN_LEN]; | 99 | "`%s' expected (to close `%s' at line %d)", |
102 | luaX_token2str(what, t_what); | 100 | luaX_token2str(ls, what), luaX_token2str(ls, who), where)); |
103 | luaX_token2str(who, t_who); | ||
104 | sprintf(buff, "`%.10s' expected (to close `%.10s' at line %d)", | ||
105 | t_what, t_who, where); | ||
106 | luaK_error(ls, buff); | ||
107 | } | 101 | } |
108 | } | 102 | } |
109 | next(ls); | 103 | next(ls); |
@@ -256,7 +250,7 @@ static int singlevar_aux (FuncState *fs, TString *n, expdesc *var, int nd) { | |||
256 | if (var->k == VGLOBAL) { | 250 | if (var->k == VGLOBAL) { |
257 | if (k == VNIL && nd && fs->defaultglob != NO_REG) { | 251 | if (k == VNIL && nd && fs->defaultglob != NO_REG) { |
258 | if (fs->defaultglob == NO_REG1) | 252 | if (fs->defaultglob == NO_REG1) |
259 | luaK_error(fs->ls, "undeclared global"); | 253 | luaX_syntaxerror(fs->ls, "undeclared global"); |
260 | init_exp(var, VLOCAL, fs->defaultglob); | 254 | init_exp(var, VLOCAL, fs->defaultglob); |
261 | k = VGLOBAL; /* now there is a declaration */ | 255 | k = VGLOBAL; /* now there is a declaration */ |
262 | } | 256 | } |
@@ -479,7 +473,7 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
479 | switch (ls->t.token) { | 473 | switch (ls->t.token) { |
480 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ | 474 | case '(': { /* funcargs -> `(' [ explist1 ] `)' */ |
481 | if (line != ls->lastline) | 475 | if (line != ls->lastline) |
482 | luaK_error(ls, "ambiguous syntax (function call x new statement)"); | 476 | luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); |
483 | next(ls); | 477 | next(ls); |
484 | if (ls->t.token == ')') /* arg list is empty? */ | 478 | if (ls->t.token == ')') /* arg list is empty? */ |
485 | args.k = VVOID; | 479 | args.k = VVOID; |
@@ -500,7 +494,7 @@ static void funcargs (LexState *ls, expdesc *f) { | |||
500 | break; | 494 | break; |
501 | } | 495 | } |
502 | default: { | 496 | default: { |
503 | luaK_error(ls, "function arguments expected"); | 497 | luaX_syntaxerror(ls, "function arguments expected"); |
504 | return; | 498 | return; |
505 | } | 499 | } |
506 | } | 500 | } |
@@ -657,9 +651,10 @@ static void prefixexp (LexState *ls, expdesc *v) { | |||
657 | /* prefixexp -> NAME | '(' expr ')' */ | 651 | /* prefixexp -> NAME | '(' expr ')' */ |
658 | switch (ls->t.token) { | 652 | switch (ls->t.token) { |
659 | case '(': { | 653 | case '(': { |
654 | int line = ls->linenumber; | ||
660 | next(ls); | 655 | next(ls); |
661 | expr(ls, v); | 656 | expr(ls, v); |
662 | check(ls, ')'); | 657 | check_match(ls, ')', '(', line); |
663 | luaK_dischargevars(ls->fs, v); | 658 | luaK_dischargevars(ls->fs, v); |
664 | return; | 659 | return; |
665 | } | 660 | } |
@@ -676,7 +671,7 @@ static void prefixexp (LexState *ls, expdesc *v) { | |||
676 | return; | 671 | return; |
677 | } | 672 | } |
678 | default: { | 673 | default: { |
679 | luaK_error(ls, "unexpected symbol"); | 674 | luaX_syntaxerror(ls, "unexpected symbol"); |
680 | return; | 675 | return; |
681 | } | 676 | } |
682 | } | 677 | } |
@@ -1070,7 +1065,7 @@ static void forstat (LexState *ls, int line) { | |||
1070 | switch (ls->t.token) { | 1065 | switch (ls->t.token) { |
1071 | case '=': fornum(ls, varname, line); break; | 1066 | case '=': fornum(ls, varname, line); break; |
1072 | case ',': case TK_IN: forlist(ls, varname); break; | 1067 | case ',': case TK_IN: forlist(ls, varname); break; |
1073 | default: luaK_error(ls, "`=' or `in' expected"); | 1068 | default: luaX_syntaxerror(ls, "`=' or `in' expected"); |
1074 | } | 1069 | } |
1075 | check_match(ls, TK_END, TK_FOR, line); | 1070 | check_match(ls, TK_END, TK_FOR, line); |
1076 | leaveblock(fs); | 1071 | leaveblock(fs); |
@@ -1245,7 +1240,7 @@ static void breakstat (LexState *ls) { | |||
1245 | bl = bl->previous; | 1240 | bl = bl->previous; |
1246 | } | 1241 | } |
1247 | if (!bl) | 1242 | if (!bl) |
1248 | luaK_error(ls, "no loop to break"); | 1243 | luaX_syntaxerror(ls, "no loop to break"); |
1249 | if (upval) | 1244 | if (upval) |
1250 | luaK_codeABC(fs, OP_CLOSE, bl->nactloc, 0, 0); | 1245 | luaK_codeABC(fs, OP_CLOSE, bl->nactloc, 0, 0); |
1251 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); | 1246 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); |
@@ -1314,7 +1309,7 @@ static void parlist (LexState *ls) { | |||
1314 | switch (ls->t.token) { | 1309 | switch (ls->t.token) { |
1315 | case TK_DOTS: dots = 1; break; | 1310 | case TK_DOTS: dots = 1; break; |
1316 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; | 1311 | case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break; |
1317 | default: luaK_error(ls, "<name> or `...' expected"); | 1312 | default: luaX_syntaxerror(ls, "<name> or `...' expected"); |
1318 | } | 1313 | } |
1319 | next(ls); | 1314 | next(ls); |
1320 | } while (!dots && optional(ls, ',')); | 1315 | } while (!dots && optional(ls, ',')); |