mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Simplify lexer a bit.
This commit is contained in:
parent
28a6284642
commit
3a32bbc7cb
24
src/lj_lex.c
24
src/lj_lex.c
@ -58,14 +58,6 @@ static void save(LexState *ls, int c)
|
|||||||
ls->sb.buf[ls->sb.n++] = cast(char, c);
|
ls->sb.buf[ls->sb.n++] = cast(char, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_next(LexState *ls, const char *set)
|
|
||||||
{
|
|
||||||
if (!strchr(set, ls->current))
|
|
||||||
return 0;
|
|
||||||
save_and_next(ls);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void inclinenumber(LexState *ls)
|
static void inclinenumber(LexState *ls)
|
||||||
{
|
{
|
||||||
int old = ls->current;
|
int old = ls->current;
|
||||||
@ -85,8 +77,12 @@ static void read_numeral(LexState *ls, TValue *tv)
|
|||||||
do {
|
do {
|
||||||
save_and_next(ls);
|
save_and_next(ls);
|
||||||
} while (lj_ctype_isdigit(ls->current) || ls->current == '.');
|
} while (lj_ctype_isdigit(ls->current) || ls->current == '.');
|
||||||
if (check_next(ls, "Ee")) /* `E'? */
|
if (ls->current == 'e' || ls->current == 'E' ||
|
||||||
check_next(ls, "+-"); /* optional exponent sign */
|
ls->current == 'p' || ls->current == 'P') {
|
||||||
|
save_and_next(ls);
|
||||||
|
if (ls->current == '+' || ls->current == '-')
|
||||||
|
save_and_next(ls);
|
||||||
|
}
|
||||||
while (lj_ctype_isident(ls->current))
|
while (lj_ctype_isident(ls->current))
|
||||||
save_and_next(ls);
|
save_and_next(ls);
|
||||||
save(ls, '\0');
|
save(ls, '\0');
|
||||||
@ -277,10 +273,12 @@ static int llex(LexState *ls, TValue *tv)
|
|||||||
return TK_string;
|
return TK_string;
|
||||||
case '.':
|
case '.':
|
||||||
save_and_next(ls);
|
save_and_next(ls);
|
||||||
if (check_next(ls, ".")) {
|
if (ls->current == '.') {
|
||||||
if (check_next(ls, "."))
|
next(ls);
|
||||||
|
if (ls->current == '.') {
|
||||||
|
next(ls);
|
||||||
return TK_dots; /* ... */
|
return TK_dots; /* ... */
|
||||||
else
|
}
|
||||||
return TK_concat; /* .. */
|
return TK_concat; /* .. */
|
||||||
} else if (!lj_ctype_isdigit(ls->current)) {
|
} else if (!lj_ctype_isdigit(ls->current)) {
|
||||||
return '.';
|
return '.';
|
||||||
|
Loading…
Reference in New Issue
Block a user