3 ** Major parts taken verbatim from the Lua interpreter.
4 ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
15 /* Lua lexer tokens. */
16 #define TKDEF(_, __) \
17 _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \
18 _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \
19 _(repeat) _(return) _(then) _(true) _(until) _(while) \
20 __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \
21 __(label, ::) __(number, <number>) __(name, <name>) __(string, <string>) \
26 #define TKENUM1(name) TK_##name,
27 #define TKENUM2(name, sym) TK_##name,
28 TKDEF(TKENUM1
, TKENUM2
)
31 TK_RESERVED
= TK_while
- TK_OFS
36 /* Combined bytecode ins/line. Only used during bytecode generation. */
37 typedef struct BCInsLine
{
38 BCIns ins
; /* Bytecode instruction. */
39 BCLine line
; /* Line number for this bytecode. */
42 /* Info for local variables. Only used during bytecode generation. */
43 typedef struct VarInfo
{
44 GCRef name
; /* Local variable name or goto/label name. */
45 BCPos startpc
; /* First point where the local variable is active. */
46 BCPos endpc
; /* First point where the local variable is dead. */
47 uint8_t slot
; /* Variable slot. */
48 uint8_t info
; /* Variable/goto/label info. */
51 /* Lua lexer state. */
52 typedef struct LexState
{
53 struct FuncState
*fs
; /* Current FuncState. Defined in lj_parse.c. */
54 struct lua_State
*L
; /* Lua state. */
55 TValue tokenval
; /* Current token value. */
56 TValue lookaheadval
; /* Lookahead token value. */
57 int current
; /* Current character (charint). */
58 LexToken token
; /* Current token. */
59 LexToken lookahead
; /* Lookahead token. */
60 MSize n
; /* Bytes left in input buffer. */
61 const char *p
; /* Current position in input buffer. */
62 SBuf sb
; /* String buffer for tokens. */
63 lua_Reader rfunc
; /* Reader callback. */
64 void *rdata
; /* Reader callback data. */
65 BCLine linenumber
; /* Input line counter. */
66 BCLine lastline
; /* Line of last token. */
67 GCstr
*chunkname
; /* Current chunk name (interned string). */
68 const char *chunkarg
; /* Chunk name argument. */
69 const char *mode
; /* Allow loading bytecode (b) and/or source text (t). */
70 VarInfo
*vstack
; /* Stack for names and extents of local variables. */
71 MSize sizevstack
; /* Size of variable stack. */
72 MSize vtop
; /* Top of variable stack. */
73 BCInsLine
*bcstack
; /* Stack for bytecode instructions/line numbers. */
74 MSize sizebcstack
; /* Size of bytecode stack. */
75 uint32_t level
; /* Syntactical nesting level. */
78 LJ_FUNC
int lj_lex_setup(lua_State
*L
, LexState
*ls
);
79 LJ_FUNC
void lj_lex_cleanup(lua_State
*L
, LexState
*ls
);
80 LJ_FUNC
void lj_lex_next(LexState
*ls
);
81 LJ_FUNC LexToken
lj_lex_lookahead(LexState
*ls
);
82 LJ_FUNC
const char *lj_lex_token2str(LexState
*ls
, LexToken token
);
83 LJ_FUNC_NORET
void lj_lex_error(LexState
*ls
, LexToken token
, ErrMsg em
, ...);
84 LJ_FUNC
void lj_lex_init(lua_State
*L
);