include/tokenizer.h

changeset 2
e14a1aba4c56
parent 1
6e704fc09528
equal deleted inserted replaced
1:6e704fc09528 2:e14a1aba4c56
29 #define TOK_STRING_VAL(TOK) ((TOK)->u.sval) 29 #define TOK_STRING_VAL(TOK) ((TOK)->u.sval)
30 #define TOK_IDENT_VAL(TOK) ((TOK)->u.sval) 30 #define TOK_IDENT_VAL(TOK) ((TOK)->u.sval)
31 #define TOK_COMMENT_VAL(TOK) ((TOK)->u.sval) 31 #define TOK_COMMENT_VAL(TOK) ((TOK)->u.sval)
32 #define TOK_OP_VAL(TOK) ((TOK)->u.opval) 32 #define TOK_OP_VAL(TOK) ((TOK)->u.opval)
33 33
34 #define TOK_IS_INVALID(TOK) ((TOK)->type==TOK_INVALID)
34 #define TOK_IS_LONG(TOK) ((TOK)->type==TOK_LONG) 35 #define TOK_IS_LONG(TOK) ((TOK)->type==TOK_LONG)
35 #define TOK_IS_DOUBLE(TOK) ((TOK)->type==TOK_DOUBLE) 36 #define TOK_IS_DOUBLE(TOK) ((TOK)->type==TOK_DOUBLE)
36 #define TOK_IS_CHAR(TOK) ((TOK)->type==TOK_CHAR) 37 #define TOK_IS_CHAR(TOK) ((TOK)->type==TOK_CHAR)
37 #define TOK_IS_STRING(TOK) ((TOK)->type==TOK_STRING) 38 #define TOK_IS_STRING(TOK) ((TOK)->type==TOK_STRING)
38 #define TOK_IS_IDENT(TOK) ((TOK)->type==TOK_IDENT) 39 #define TOK_IS_IDENT(TOK) ((TOK)->type==TOK_IDENT)
116 117
117 118
118 enum{ 119 enum{
119 TOKZ_IGNORE_NEXTLINE=0x1, 120 TOKZ_IGNORE_NEXTLINE=0x1,
120 TOKZ_READ_COMMENTS=0x2, 121 TOKZ_READ_COMMENTS=0x2,
121 TOKZ_PARSER_INDENT_MODE=0x4 122 TOKZ_PARSER_INDENT_MODE=0x04,
123 TOKZ_ERROR_TOLERANT=0x8
122 }; 124 };
123 125
124 126
125 enum{ 127 enum{
126 E_TOKZ_UNEXPECTED_EOF=1, 128 E_TOKZ_UNEXPECTED_EOF=1,
140 E_TOKZ_INVALID_ARGUMENT, 142 E_TOKZ_INVALID_ARGUMENT,
141 E_TOKZ_EOS_EXPECTED, 143 E_TOKZ_EOS_EXPECTED,
142 E_TOKZ_TOO_FEW_ARGS, 144 E_TOKZ_TOO_FEW_ARGS,
143 E_TOKZ_TOO_MANY_ARGS, 145 E_TOKZ_TOO_MANY_ARGS,
144 E_TOKZ_MAX_NEST, 146 E_TOKZ_MAX_NEST,
145 E_TOKZ_UNEXPECTED_EOS, 147 E_TOKZ_IDENTIFIER_EXPECTED,
146 E_TOKZ_IDENTIFIER_EXPECTED 148
149 E_TOKZ_LBRACE_EXPECTED
147 }; 150 };
148 151
149 152
150 struct _ConfOpt; 153 struct _ConfOpt;
151 154
152 typedef struct _Tokenizer_FInfo{ 155 typedef struct _Tokenizer_FInfo{
153 FILE *file; 156 FILE *file;
154 char *name; 157 char *name;
155 int line; 158 int line;
156 int ungetc; 159 int ungetc;
160 Token ungettok;
157 } Tokenizer_FInfo; 161 } Tokenizer_FInfo;
158 162
159 typedef struct _Tokenizer{ 163 typedef struct _Tokenizer{
160 FILE *file; 164 FILE *file;
161 char *name; 165 char *name;
162 int line; 166 int line;
163 int ungetc; 167 int ungetc;
168 Token ungettok;
164 169
165 int flags; 170 int flags;
166 const struct _ConfOpt **optstack; 171 const struct _ConfOpt **optstack;
167 int nest_lvl; 172 int nest_lvl;
168 void *user_data; 173 void *user_data;
174 179
175 extern Tokenizer *tokz_open(const char *fname); 180 extern Tokenizer *tokz_open(const char *fname);
176 extern Tokenizer *tokz_open_file(FILE *file); 181 extern Tokenizer *tokz_open_file(FILE *file);
177 extern void tokz_close(Tokenizer *tokz); 182 extern void tokz_close(Tokenizer *tokz);
178 extern bool tokz_get_token(Tokenizer *tokz, Token *tok); 183 extern bool tokz_get_token(Tokenizer *tokz, Token *tok);
184 extern void tokz_unget_token(Tokenizer *tokz, Token *tok);
179 extern void tokz_warn_error(const Tokenizer *tokz, int line, int e); 185 extern void tokz_warn_error(const Tokenizer *tokz, int line, int e);
180 186
181 extern bool tokz_pushf(Tokenizer *tokz, const char *fname); 187 extern bool tokz_pushf(Tokenizer *tokz, const char *fname);
182 extern bool tokz_pushf_file(Tokenizer *tokz, FILE *file); 188 extern bool tokz_pushf_file(Tokenizer *tokz, FILE *file);
183 extern bool tokz_popf(Tokenizer *tokz); 189 extern bool tokz_popf(Tokenizer *tokz);

mercurial