aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-11-08 17:45:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-11-08 17:45:14 -0200
commitd2811e809721e66b57246be23813ae71db224ee7 (patch)
tree08871631edd8ba2e03b1e856f17c9c381383e58b
parente43e95553fdb0ebb30ab3c69c227aebd752942dd (diff)
downloadlua-d2811e809721e66b57246be23813ae71db224ee7.tar.gz
lua-d2811e809721e66b57246be23813ae71db224ee7.tar.bz2
lua-d2811e809721e66b57246be23813ae71db224ee7.zip
simpler checking for numbers (strtod does the rest)
-rw-r--r--llex.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/llex.c b/llex.c
index f964610d..f636c368 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.11 2005/05/16 21:19:00 roberto Exp roberto $ 2** $Id: llex.c,v 2.12 2005/05/17 19:49:15 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*/
@@ -155,28 +155,23 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
155 155
156 156
157 157
158static int check_next (LexState *ls, const char *set) {
159 if (!strchr(set, ls->current))
160 return 0;
161 save_and_next(ls);
162 return 1;
163}
164
165
158 166
159/* LUA_NUMBER */ 167/* LUA_NUMBER */
160static void read_numeral (LexState *ls, SemInfo *seminfo) { 168static void read_numeral (LexState *ls, SemInfo *seminfo) {
161 while (isdigit(ls->current)) { 169 lua_assert(isdigit(ls->current));
170 do {
162 save_and_next(ls); 171 save_and_next(ls);
163 } 172 } while (isdigit(ls->current) || ls->current == '.');
164 if (ls->current == '.') { 173 if (check_next(ls, "Ee")) { /* `E'? */
165 save_and_next(ls); 174 check_next(ls, "+-"); /* optional exponent sign */
166 if (ls->current == '.') {
167 save_and_next(ls);
168 luaX_lexerror(ls,
169 "ambiguous syntax (decimal point x string concatenation)",
170 TK_NUMBER);
171 }
172 }
173 while (isdigit(ls->current)) {
174 save_and_next(ls);
175 }
176 if (ls->current == 'e' || ls->current == 'E') {
177 save_and_next(ls); /* read `E' */
178 if (ls->current == '+' || ls->current == '-')
179 save_and_next(ls); /* optional exponent sign */
180 while (isdigit(ls->current)) { 175 while (isdigit(ls->current)) {
181 save_and_next(ls); 176 save_and_next(ls);
182 } 177 }
@@ -375,12 +370,9 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) {
375 } 370 }
376 case '.': { 371 case '.': {
377 save_and_next(ls); 372 save_and_next(ls);
378 if (ls->current == '.') { 373 if (check_next(ls, ".")) {
379 next(ls); 374 if (check_next(ls, "."))
380 if (ls->current == '.') {
381 next(ls);
382 return TK_DOTS; /* ... */ 375 return TK_DOTS; /* ... */
383 }
384 else return TK_CONCAT; /* .. */ 376 else return TK_CONCAT; /* .. */
385 } 377 }
386 else if (!isdigit(ls->current)) return '.'; 378 else if (!isdigit(ls->current)) return '.';