2013-11-21 22:09:25 -08:00
|
|
|
/*
|
|
|
|
|
* NOTE: This is an internal header and installed for use by extensions. The
|
|
|
|
|
* API is not guaranteed stable.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-05-26 16:00:43 +02:00
|
|
|
#ifndef HAMMER_PARSE_INTERNAL__H
|
|
|
|
|
#define HAMMER_PARSE_INTERNAL__H
|
|
|
|
|
#include "../hammer.h"
|
|
|
|
|
#include "../internal.h"
|
2013-03-17 19:56:43 -07:00
|
|
|
#include "../backends/regex.h"
|
2013-05-25 03:35:42 +02:00
|
|
|
#include "../backends/contextfree.h"
|
2012-05-26 16:00:43 +02:00
|
|
|
|
|
|
|
|
#define a_new_(arena, typ, count) ((typ*)h_arena_malloc((arena), sizeof(typ)*(count)))
|
|
|
|
|
#define a_new(typ, count) a_new_(state->arena, typ, count)
|
|
|
|
|
// we can create a_new0 if necessary. It would allocate some memory and immediately zero it out.
|
|
|
|
|
|
2013-05-11 19:04:59 +02:00
|
|
|
static inline HParseResult* make_result(HArena *arena, HParsedToken *tok) {
|
|
|
|
|
HParseResult *ret = h_arena_malloc(arena, sizeof(HParseResult));
|
2012-05-26 16:00:43 +02:00
|
|
|
ret->ast = tok;
|
2013-05-11 19:04:59 +02:00
|
|
|
ret->arena = arena;
|
2015-01-04 04:00:09 +01:00
|
|
|
ret->bit_length = 0; // This way it gets overridden in h_do_parse
|
2012-05-26 16:00:43 +02:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return token size in bits...
|
|
|
|
|
static inline size_t token_length(HParseResult *pr) {
|
|
|
|
|
if (pr) {
|
|
|
|
|
return pr->bit_length;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 20:43:16 -05:00
|
|
|
/* Epsilon rules happen during desugaring. This handles them. */
|
2013-05-25 03:35:42 +02:00
|
|
|
static inline void desugar_epsilon(HAllocator *mm__, HCFStack *stk__, void *env) {
|
|
|
|
|
HCFS_BEGIN_CHOICE() {
|
|
|
|
|
HCFS_BEGIN_SEQ() {
|
|
|
|
|
} HCFS_END_SEQ();
|
|
|
|
|
HCFS_THIS_CHOICE->reshape = h_act_ignore;
|
|
|
|
|
} HCFS_END_CHOICE();
|
2013-02-20 20:43:16 -05:00
|
|
|
}
|
|
|
|
|
|
2012-05-26 16:00:43 +02:00
|
|
|
#endif // HAMMER_PARSE_INTERNAL__H
|