Add support for '%a' and '%A' to string.format.
[luajit-2.0/celess22.git] / src / lj_lex.h
blob1ddf4b593974cdb3cb1ae0ad1dca65e80b507807
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 */
7 #ifndef _LJ_LEX_H
8 #define _LJ_LEX_H
10 #include <stdarg.h>
12 #include "lj_obj.h"
13 #include "lj_err.h"
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>)
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
33 typedef int LexToken;
35 /* Combined bytecode ins/line. Only used during bytecode generation. */
36 typedef struct BCInsLine {
37 BCIns ins; /* Bytecode instruction. */
38 BCLine line; /* Line number for this bytecode. */
39 } BCInsLine;
41 /* Info for local variables. Only used during bytecode generation. */
42 typedef struct VarInfo {
43 GCRef name; /* Local variable name. */
44 BCPos startpc; /* First point where the local variable is active. */
45 BCPos endpc; /* First point where the local variable is dead. */
46 } VarInfo;
48 /* Lua lexer state. */
49 typedef struct LexState {
50 struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */
51 struct lua_State *L; /* Lua state. */
52 TValue tokenval; /* Current token value. */
53 TValue lookaheadval; /* Lookahead token value. */
54 int current; /* Current character (charint). */
55 LexToken token; /* Current token. */
56 LexToken lookahead; /* Lookahead token. */
57 MSize n; /* Bytes left in input buffer. */
58 const char *p; /* Current position in input buffer. */
59 SBuf sb; /* String buffer for tokens. */
60 lua_Reader rfunc; /* Reader callback. */
61 void *rdata; /* Reader callback data. */
62 BCLine linenumber; /* Input line counter. */
63 BCLine lastline; /* Line of last token. */
64 GCstr *chunkname; /* Current chunk name (interned string). */
65 const char *chunkarg; /* Chunk name argument. */
66 VarInfo *vstack; /* Stack for names and extents of local variables. */
67 MSize sizevstack; /* Size of variable stack. */
68 MSize vtop; /* Top of variable stack. */
69 BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */
70 MSize sizebcstack; /* Size of bytecode stack. */
71 uint32_t level; /* Syntactical nesting level. */
72 } LexState;
74 LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);
75 LJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls);
76 LJ_FUNC void lj_lex_next(LexState *ls);
77 LJ_FUNC LexToken lj_lex_lookahead(LexState *ls);
78 LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token);
79 LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...);
80 LJ_FUNC void lj_lex_init(lua_State *L);
82 #endif