diff options
Diffstat (limited to 'src/lj_lex.h')
-rw-r--r-- | src/lj_lex.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/lj_lex.h b/src/lj_lex.h new file mode 100644 index 00000000..cc5d5a9f --- /dev/null +++ b/src/lj_lex.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | ** Lexical analyzer. | ||
3 | ** Major parts taken verbatim from the Lua interpreter. | ||
4 | ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h | ||
5 | */ | ||
6 | |||
7 | #ifndef _LJ_LEX_H | ||
8 | #define _LJ_LEX_H | ||
9 | |||
10 | #include <stdarg.h> | ||
11 | |||
12 | #include "lj_obj.h" | ||
13 | #include "lj_err.h" | ||
14 | |||
15 | /* Lua lexer tokens. */ | ||
16 | #define TKDEF(_, __) \ | ||
17 | _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \ | ||
18 | _(for) _(function) _(if) _(in) _(local) _(nil) _(not) _(or) \ | ||
19 | _(repeat) _(return) _(then) _(true) _(until) _(while) \ | ||
20 | __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \ | ||
21 | __(number, <number>) __(name, <name>) __(string, <string>) __(eof, <eof>) | ||
22 | |||
23 | enum { | ||
24 | TK_OFS = 256, | ||
25 | #define TKENUM1(name) TK_##name, | ||
26 | #define TKENUM2(name, sym) TK_##name, | ||
27 | TKDEF(TKENUM1, TKENUM2) | ||
28 | #undef TKENUM1 | ||
29 | #undef TKENUM2 | ||
30 | TK_RESERVED = TK_while - TK_OFS | ||
31 | }; | ||
32 | |||
33 | typedef int LexToken; | ||
34 | |||
35 | /* Lua lexer state. */ | ||
36 | typedef struct LexState { | ||
37 | struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */ | ||
38 | struct lua_State *L; /* Lua state. */ | ||
39 | TValue tokenval; /* Current token value. */ | ||
40 | TValue lookaheadval; /* Lookahead token value. */ | ||
41 | int current; /* Current character (charint). */ | ||
42 | LexToken token; /* Current token. */ | ||
43 | LexToken lookahead; /* Lookahead token. */ | ||
44 | SBuf sb; /* String buffer for tokens. */ | ||
45 | const char *p; /* Current position in input buffer. */ | ||
46 | MSize n; /* Bytes left in input buffer. */ | ||
47 | lua_Reader rfunc; /* Reader callback. */ | ||
48 | void *rdata; /* Reader callback data. */ | ||
49 | BCLine linenumber; /* Input line counter. */ | ||
50 | BCLine lastline; /* Line of last token. */ | ||
51 | GCstr *chunkname; /* Current chunk name (interned string). */ | ||
52 | const char *chunkarg; /* Chunk name argument. */ | ||
53 | uint32_t level; /* Syntactical nesting level. */ | ||
54 | } LexState; | ||
55 | |||
56 | LJ_FUNC void lj_lex_start(lua_State *L, LexState *ls); | ||
57 | LJ_FUNC void lj_lex_next(LexState *ls); | ||
58 | LJ_FUNC LexToken lj_lex_lookahead(LexState *ls); | ||
59 | LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token); | ||
60 | LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...); | ||
61 | LJ_FUNC void lj_lex_init(lua_State *L); | ||
62 | |||
63 | #endif | ||