33 #define PARSE_SUCCESS 0 34 #define PARSE_CONTINUE -1 35 #define PARSE_BREAK -2 36 #define PARSE_UNEXPECTED_CONTINUE -3 37 #define PARSE_UNEXPECTED_BREAK -4 48 static inline void cf_parser_init(
struct cf_parser *parser)
57 static inline void cf_parser_free(
struct cf_parser *parser)
66 static inline bool cf_parser_parse(
struct cf_parser *parser,
67 const char *
str,
const char *file)
75 parser->
cur_token = cf_preprocessor_get_tokens(&parser->
pp);
80 int level,
const char *val1,
const char *val2,
83 static inline void cf_adderror_expecting(
struct cf_parser *p,
89 static inline void cf_adderror_unexpected_eof(
struct cf_parser *p)
95 static inline void cf_adderror_syntax_error(
struct cf_parser *p)
101 static inline bool cf_next_token(
struct cf_parser *p)
115 static inline bool cf_next_valid_token(
struct cf_parser *p)
117 if (!cf_next_token(p)) {
118 cf_adderror_unexpected_eof(p);
127 static inline bool cf_go_to_token(
struct cf_parser *p,
128 const char *str1,
const char *str2)
130 while (cf_next_token(p)) {
144 static inline bool cf_go_to_valid_token(
struct cf_parser *p,
145 const char *str1,
const char *str2)
147 if (!cf_go_to_token(p, str1, str2)) {
148 cf_adderror_unexpected_eof(p);
155 static inline bool cf_go_to_token_type(
struct cf_parser *p,
165 static inline int cf_token_should_be(
struct cf_parser *p,
166 const char *str,
const char *goto1,
const char *goto2)
172 if (!cf_go_to_token(p, goto1, goto2))
176 cf_adderror_expecting(p, str);
180 static inline int cf_next_token_should_be(
struct cf_parser *p,
181 const char *str,
const char *goto1,
const char *goto2)
183 if (!cf_next_token(p)) {
184 cf_adderror_unexpected_eof(p);
191 if (!cf_go_to_token(p, goto1, goto2))
195 cf_adderror_expecting(p, str);
202 bool success = cf_next_token(p);
210 static inline bool cf_peek_valid_token(
struct cf_parser *p,
213 bool success = cf_peek_token(p, peek);
215 cf_adderror_unexpected_eof(p);
219 static inline bool cf_token_is(
struct cf_parser *p,
const char *val)
224 static inline int cf_token_is_type(
struct cf_parser *p,
226 const char *goto_token)
229 cf_adderror_expecting(p, type_expected);
231 if (!cf_go_to_valid_token(p, goto_token, NULL))
240 static inline void cf_copy_token(
struct cf_parser *p,
char **dst)
245 static inline int cf_get_name(
struct cf_parser *p,
char **dst,
246 const char *name,
const char *goto_token)
250 errcode = cf_token_is_type(p,
CFTOKEN_NAME, name, goto_token);
258 static inline int cf_next_name(
struct cf_parser *p,
char **dst,
259 const char *name,
const char *goto_token)
261 if (!cf_next_valid_token(p))
264 return cf_get_name(p, dst, name, goto_token);
267 static inline int cf_next_token_copy(
struct cf_parser *p,
char **dst)
269 if (!cf_next_valid_token(p))
272 cf_copy_token(p, dst);
276 static inline int cf_get_name_ref(
struct cf_parser *p,
struct strref *dst,
277 const char *name,
const char *goto_token)
281 errcode = cf_token_is_type(p,
CFTOKEN_NAME, name, goto_token);
289 static inline int cf_next_name_ref(
struct cf_parser *p,
struct strref *dst,
290 const char *name,
const char *goto_token)
292 if (!cf_next_valid_token(p))
295 return cf_get_name_ref(p, dst, name, goto_token);
Definition: cf-lexer.h:39
#define LEX_ERROR
Definition: lexer.h:156
#define PARSE_SUCCESS
Definition: cf-parser.h:33
size_t len
Definition: lexer.h:32
Definition: cf-lexer.h:42
#define PARSE_CONTINUE
Definition: cf-parser.h:34
struct cf_lexer lex
Definition: cf-parser.h:41
struct cf_preprocessor pp
Definition: cf-parser.h:42
EXPORT bool cf_preprocess(struct cf_preprocessor *pp, struct cf_lexer *lex, struct error_data *ed)
Definition: cf-lexer.h:47
enum cf_token_type type
Definition: cf-lexer.h:51
Definition: cf-lexer.h:38
struct strref str
Definition: cf-lexer.h:49
cf_token_type
Definition: cf-lexer.h:37
#define EXPORT
Definition: c99defs.h:53
EXPORT bool cf_pass_pair(struct cf_parser *p, char in, char out)
EXPORT void cf_adderror(struct cf_parser *parser, const char *error, int level, const char *val1, const char *val2, const char *val3)
Definition: cf-lexer.h:170
Definition: cf-lexer.h:41
struct cf_token * cur_token
Definition: cf-parser.h:45
EXPORT void cf_lexer_init(struct cf_lexer *lex)
struct error_data error_list
Definition: cf-parser.h:43
Definition: cf-lexer.h:85
EXPORT void cf_lexer_free(struct cf_lexer *lex)
Definition: cf-parser.h:40
EXPORT bool cf_lexer_lex(struct cf_lexer *lex, const char *str, const char *file)
EXPORT int strref_cmp(const struct strref *str1, const char *str2)
const char * array
Definition: lexer.h:31
EXPORT void cf_preprocessor_init(struct cf_preprocessor *pp)
#define PARSE_EOF
Definition: cf-parser.h:38
EXPORT void cf_preprocessor_free(struct cf_preprocessor *pp)