xref: /freebsd/sys/contrib/openzfs/module/lua/llex.h (revision c03c5b1c80914ec656fbee84539355d1fad68bf9)
1 /*
2 ** $Id: llex.h,v 1.72.1.1 2013/04/12 18:48:47 roberto Exp $
3 ** Lexical Analyzer
4 ** See Copyright Notice in lua.h
5 */
6 
7 #ifndef llex_h
8 #define llex_h
9 
10 #include "lobject.h"
11 #include "lzio.h"
12 
13 
14 #define FIRST_RESERVED	257
15 
16 
17 
18 /*
19 * WARNING: if you change the order of this enumeration,
20 * grep "ORDER RESERVED"
21 */
22 enum RESERVED {
23   /* terminal symbols denoted by reserved words */
24   TK_AND = FIRST_RESERVED, TK_BREAK,
25   TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
26   TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
27   TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
28   /* other terminal symbols */
29   TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_DBCOLON, TK_EOS,
30   TK_NUMBER, TK_NAME, TK_STRING
31 };
32 
33 /* number of reserved words */
34 #define NUM_RESERVED	(cast(int, TK_WHILE-FIRST_RESERVED+1))
35 
36 
37 typedef union {
38   lua_Number r;
39   TString *ts;
40 } SemInfo;  /* semantics information */
41 
42 
43 typedef struct Token {
44   int token;
45   SemInfo seminfo;
46 } Token;
47 
48 #ifdef current
49 #undef current
50 #endif
51 
52 /* state of the lexer plus state of the parser when shared by all
53    functions */
54 typedef struct LexState {
55   int current;  /* current character (charint) */
56   int linenumber;  /* input line counter */
57   int lastline;  /* line of last token `consumed' */
58   Token t;  /* current token */
59   Token lookahead;  /* look ahead token */
60   struct FuncState *fs;  /* current function (parser) */
61   struct lua_State *L;
62   ZIO *z;  /* input stream */
63   Mbuffer *buff;  /* buffer for tokens */
64   struct Dyndata *dyd;  /* dynamic structures used by the parser */
65   TString *source;  /* current source name */
66   TString *envn;  /* environment variable name */
67   char decpoint;  /* locale decimal point */
68 } LexState;
69 
70 
71 LUAI_FUNC void luaX_init (lua_State *L);
72 LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
73                               TString *source, int firstchar);
74 LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
75 LUAI_FUNC void luaX_next (LexState *ls);
76 LUAI_FUNC int luaX_lookahead (LexState *ls);
77 LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
78 LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
79 
80 
81 #endif
82