int luaX_lex (LexState *LS, SemInfo *seminfo) { for (;;) { switch (LS->current) { case ' ': case '\t': case '\r': /* `\r' to avoid problems with DOS */ next(LS); continue; case '\n': inclinenumber(LS); continue; case '$': luaX_error(LS, "unexpected `$' (pragmas are no longer supported)", '$'); break; case '-': next(LS); if (LS->current != '-') return '-'; do { next(LS); } while (LS->current != '\n' && LS->current != EOZ); continue; case '[': next(LS); if (LS->current != '[') return '['; else { read_long_string(LS, seminfo); return TK_STRING; } case '=': next(LS); if (LS->current != '=') return '='; else { next(LS); return TK_EQ; } case '<': next(LS); if (LS->current != '=') return '<'; else { next(LS); return TK_LE; } case '>': next(LS); if (LS->current != '=') return '>'; else { next(LS); return TK_GE; } case '~': next(LS); if (LS->current != '=') return '~'; else { next(LS); return TK_NE; } case '"': case '\'': read_string(LS, LS->current, seminfo); return TK_STRING; case '.': next(LS); if (LS->current == '.') { next(LS); if (LS->current == '.') { next(LS); return TK_DOTS; /* ... */ } else return TK_CONCAT; /* .. */ } else if (!isdigit(LS->current)) return '.'; else { read_number(LS, 1, seminfo); return TK_NUMBER; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': read_number(LS, 0, seminfo); return TK_NUMBER; case EOZ: return TK_EOS; case '_': goto tname; default: if (!isalpha(LS->current)) { int c = LS->current; if (iscntrl(c)) luaX_invalidchar(LS, c); next(LS); return c; } tname: { /* identifier or reserved word */ TString *ts = luaS_new(LS->L, readname(LS)); if (ts->marked >= RESERVEDMARK) /* reserved word? */ return ts->marked-RESERVEDMARK+FIRST_RESERVED; seminfo->ts = ts; return TK_NAME; } } } }
int luaX_lex (LexState *LS) { luaL_resetbuffer(); for (;;) { switch (LS->current) { case ' ': case '\t': case '\r': /* CR: to avoid problems with DOS */ next(LS); continue; case '\n': inclinenumber(LS); continue; case '-': save_and_next(LS); if (LS->current != '-') return '-'; do { next(LS); } while (LS->current != '\n' && LS->current != EOZ); luaL_resetbuffer(); continue; case '[': save_and_next(LS); if (LS->current != '[') return '['; else { save_and_next(LS); /* pass the second '[' */ return read_long_string(LS); } case '=': save_and_next(LS); if (LS->current != '=') return '='; else { save_and_next(LS); return EQ; } case '<': save_and_next(LS); if (LS->current != '=') return '<'; else { save_and_next(LS); return LE; } case '>': save_and_next(LS); if (LS->current != '=') return '>'; else { save_and_next(LS); return GE; } case '~': save_and_next(LS); if (LS->current != '=') return '~'; else { save_and_next(LS); return NE; } case '"': case '\'': { int del = LS->current; save_and_next(LS); while (LS->current != del) { switch (LS->current) { case EOZ: case '\n': luaX_error(LS, "unfinished string"); return EOS; /* to avoid warnings */ case '\\': next(LS); /* do not save the '\' */ switch (LS->current) { case 'a': save('\a'); next(LS); break; case 'b': save('\b'); next(LS); break; case 'f': save('\f'); next(LS); break; case 'n': save('\n'); next(LS); break; case 'r': save('\r'); next(LS); break; case 't': save('\t'); next(LS); break; case 'v': save('\v'); next(LS); break; case '\n': save('\n'); inclinenumber(LS); break; default : { if (isdigit(LS->current)) { int c = 0; int i = 0; do { c = 10*c + (LS->current-'0'); next(LS); } while (++i<3 && isdigit(LS->current)); if (c != (unsigned char)c) luaX_error(LS, "escape sequence too large"); save(c); } else { /* handles \, ", ', and ? */ save(LS->current); next(LS); } break; } } break; default: save_and_next(LS); } } save_and_next(LS); /* skip delimiter */ LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+1), L->Mbuffnext-L->Mbuffbase-2); return STRING; } case '.': save_and_next(LS); if (LS->current == '.') { save_and_next(LS); if (LS->current == '.') { save_and_next(LS); return DOTS; /* ... */ } else return CONC; /* .. */ } else if (!isdigit(LS->current)) return '.'; goto fraction; /* LS->current is a digit: goes through to number */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': do { save_and_next(LS); } while (isdigit(LS->current)); if (LS->current == '.') { save_and_next(LS); if (LS->current == '.') { save('.'); luaX_error(LS, "ambiguous syntax (decimal point x string concatenation)"); } } fraction: while (isdigit(LS->current)) save_and_next(LS); if (toupper(LS->current) == 'E') { save_and_next(LS); /* read 'E' */ save_and_next(LS); /* read '+', '-' or first digit */ while (isdigit(LS->current)) save_and_next(LS); } save('\0'); LS->seminfo.r = luaO_str2d(L->Mbuffer+L->Mbuffbase); if (LS->seminfo.r < 0) luaX_error(LS, "invalid numeric format"); return NUMBER; case EOZ: if (LS->iflevel > 0) luaX_error(LS, "input ends inside a $if"); return EOS; default: if (LS->current != '_' && !isalpha(LS->current)) { int c = LS->current; if (iscntrl(c)) luaX_invalidchar(LS, c); save_and_next(LS); return c; } else { /* identifier or reserved word */ TaggedString *ts; do { save_and_next(LS); } while (isalnum(LS->current) || LS->current == '_'); save('\0'); ts = luaS_new(L->Mbuffer+L->Mbuffbase); if (ts->head.marked >= FIRST_RESERVED) return ts->head.marked; /* reserved word */ LS->seminfo.ts = ts; return NAME; } } } }