summaryrefslogtreecommitdiff
path: root/llex.c
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 /llex.c
parente43e95553fdb0ebb30ab3c69c227aebd752942dd (diff)
downloadlua-github-d2811e809721e66b57246be23813ae71db224ee7.tar.gz
simpler checking for numbers (strtod does the rest)
Diffstat (limited to 'llex.c')
-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 @@
/*
-** $Id: llex.c,v 2.11 2005/05/16 21:19:00 roberto Exp roberto $
+** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@@ -155,28 +155,23 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
+static int check_next (LexState *ls, const char *set) {
+ if (!strchr(set, ls->current))
+ return 0;
+ save_and_next(ls);
+ return 1;
+}
+
+
/* LUA_NUMBER */
static void read_numeral (LexState *ls, SemInfo *seminfo) {
- while (isdigit(ls->current)) {
+ lua_assert(isdigit(ls->current));
+ do {
save_and_next(ls);
- }
- if (ls->current == '.') {
- save_and_next(ls);
- if (ls->current == '.') {
- save_and_next(ls);
- luaX_lexerror(ls,
- "ambiguous syntax (decimal point x string concatenation)",
- TK_NUMBER);
- }
- }
- while (isdigit(ls->current)) {
- save_and_next(ls);
- }
- if (ls->current == 'e' || ls->current == 'E') {
- save_and_next(ls); /* read `E' */
- if (ls->current == '+' || ls->current == '-')
- save_and_next(ls); /* optional exponent sign */
+ } while (isdigit(ls->current) || ls->current == '.');
+ if (check_next(ls, "Ee")) { /* `E'? */
+ check_next(ls, "+-"); /* optional exponent sign */
while (isdigit(ls->current)) {
save_and_next(ls);
}
@@ -375,12 +370,9 @@ int luaX_lex (LexState *ls, SemInfo *seminfo) {
}
case '.': {
save_and_next(ls);
- if (ls->current == '.') {
- next(ls);
- if (ls->current == '.') {
- next(ls);
+ if (check_next(ls, ".")) {
+ if (check_next(ls, "."))
return TK_DOTS; /* ... */
- }
else return TK_CONCAT; /* .. */
}
else if (!isdigit(ls->current)) return '.';