aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-02-07 15:49:18 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2007-02-07 15:49:18 -0200
commit92dc64e1216ad9559827bdcce7bb9b0cf5d7c0ef (patch)
tree231badb92c29835ebcb320944f58f0df08480e27
parent593bfc96685bd518978d2622671412d1862881e6 (diff)
downloadlua-92dc64e1216ad9559827bdcce7bb9b0cf5d7c0ef.tar.gz
lua-92dc64e1216ad9559827bdcce7bb9b0cf5d7c0ef.tar.bz2
lua-92dc64e1216ad9559827bdcce7bb9b0cf5d7c0ef.zip
more regularity in the use of quotes in error messages
-rw-r--r--llex.c24
-rw-r--r--llex.h10
-rw-r--r--lparser.c8
3 files changed, 21 insertions, 21 deletions
diff --git a/llex.c b/llex.c
index 176e6566..4bbe6cfb 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.22 2006/08/30 13:19:58 roberto Exp roberto $ 2** $Id: llex.c,v 2.23 2006/09/18 16:06:41 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*/
@@ -34,14 +34,13 @@
34 34
35 35
36/* ORDER RESERVED */ 36/* ORDER RESERVED */
37const char *const luaX_tokens [] = { 37static const char *const luaX_tokens [] = {
38 "and", "break", "do", "else", "elseif", 38 "and", "break", "do", "else", "elseif",
39 "end", "false", "for", "function", "if", 39 "end", "false", "for", "function", "if",
40 "in", "local", "nil", "not", "or", "repeat", 40 "in", "local", "nil", "not", "or", "repeat",
41 "return", "then", "true", "until", "while", 41 "return", "then", "true", "until", "while",
42 "..", "...", "==", ">=", "<=", "~=", 42 "..", "...", "==", ">=", "<=", "~=", "<eof>",
43 "<number>", "<name>", "<string>", "<eof>", 43 "<number>", "<name>", "<string>"
44 NULL
45}; 44};
46 45
47 46
@@ -79,10 +78,15 @@ const char *luaX_token2str (LexState *ls, int token) {
79 if (token < FIRST_RESERVED) { 78 if (token < FIRST_RESERVED) {
80 lua_assert(token == cast(unsigned char, token)); 79 lua_assert(token == cast(unsigned char, token));
81 return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : 80 return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
82 luaO_pushfstring(ls->L, "%c", token); 81 luaO_pushfstring(ls->L, LUA_QL("%c"), token);
82 }
83 else {
84 const char *s = luaX_tokens[token - FIRST_RESERVED];
85 if (token < TK_EOS)
86 return luaO_pushfstring(ls->L, LUA_QS, s);
87 else
88 return s;
83 } 89 }
84 else
85 return luaX_tokens[token-FIRST_RESERVED];
86} 90}
87 91
88 92
@@ -92,7 +96,7 @@ static const char *txtToken (LexState *ls, int token) {
92 case TK_STRING: 96 case TK_STRING:
93 case TK_NUMBER: 97 case TK_NUMBER:
94 save(ls, '\0'); 98 save(ls, '\0');
95 return luaZ_buffer(ls->buff); 99 return luaO_pushfstring(ls->L, LUA_QS, luaZ_buffer(ls->buff));
96 default: 100 default:
97 return luaX_token2str(ls, token); 101 return luaX_token2str(ls, token);
98 } 102 }
@@ -104,7 +108,7 @@ void luaX_lexerror (LexState *ls, const char *msg, int token) {
104 luaO_chunkid(buff, getstr(ls->source), MAXSRC); 108 luaO_chunkid(buff, getstr(ls->source), MAXSRC);
105 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); 109 msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
106 if (token) 110 if (token)
107 luaO_pushfstring(ls->L, "%s near " LUA_QS, msg, txtToken(ls, token)); 111 luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token));
108 luaD_throw(ls->L, LUA_ERRSYNTAX); 112 luaD_throw(ls->L, LUA_ERRSYNTAX);
109} 113}
110 114
diff --git a/llex.h b/llex.h
index cbe88403..fedcbc9e 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.57 2005/12/07 15:43:05 roberto Exp roberto $ 2** $Id: llex.h,v 1.58 2006/03/23 18:23:32 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*/
@@ -28,18 +28,14 @@ enum RESERVED {
28 TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 28 TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
29 TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 29 TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
30 /* other terminal symbols */ 30 /* other terminal symbols */
31 TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 31 TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_EOS,
32 TK_NAME, TK_STRING, TK_EOS 32 TK_NUMBER, TK_NAME, TK_STRING
33}; 33};
34 34
35/* number of reserved words */ 35/* number of reserved words */
36#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 36#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
37 37
38 38
39/* array with token `names' */
40LUAI_DATA const char *const luaX_tokens [];
41
42
43typedef union { 39typedef union {
44 lua_Number r; 40 lua_Number r;
45 TString *ts; 41 TString *ts;
diff --git a/lparser.c b/lparser.c
index 12face39..2d3720ce 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.49 2006/10/24 13:31:48 roberto Exp roberto $ 2** $Id: lparser.c,v 2.50 2006/11/22 11:02:03 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*/
@@ -64,7 +64,7 @@ static void anchor_token (LexState *ls) {
64 64
65static void error_expected (LexState *ls, int token) { 65static void error_expected (LexState *ls, int token) {
66 luaX_syntaxerror(ls, 66 luaX_syntaxerror(ls,
67 luaO_pushfstring(ls->L, LUA_QS " expected", luaX_token2str(ls, token))); 67 luaO_pushfstring(ls->L, "%s expected", luaX_token2str(ls, token)));
68} 68}
69 69
70 70
@@ -109,7 +109,7 @@ static void check_match (LexState *ls, int what, int who, int where) {
109 error_expected(ls, what); 109 error_expected(ls, what);
110 else { 110 else {
111 luaX_syntaxerror(ls, luaO_pushfstring(ls->L, 111 luaX_syntaxerror(ls, luaO_pushfstring(ls->L,
112 LUA_QS " expected (to close " LUA_QS " at line %d)", 112 "%s expected (to close %s at line %d)",
113 luaX_token2str(ls, what), luaX_token2str(ls, who), where)); 113 luaX_token2str(ls, what), luaX_token2str(ls, who), where));
114 } 114 }
115 } 115 }
@@ -734,7 +734,7 @@ static void primaryexp (LexState *ls, expdesc *v) {
734 734
735 735
736static void simpleexp (LexState *ls, expdesc *v) { 736static void simpleexp (LexState *ls, expdesc *v) {
737 /* simpleexp -> NUMBER | STRING | NIL | true | false | ... | 737 /* simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
738 constructor | FUNCTION body | primaryexp */ 738 constructor | FUNCTION body | primaryexp */
739 switch (ls->t.token) { 739 switch (ls->t.token) {
740 case TK_NUMBER: { 740 case TK_NUMBER: {