move the h_act_* functions to src/actions.c

This commit is contained in:
Sven M. Hallberg 2013-05-20 14:58:20 +02:00
parent 31256ba867
commit 29cee318f9
6 changed files with 9 additions and 60 deletions

View file

@ -41,6 +41,7 @@ HAMMER_PARTS := \
system_allocator.o \
benchmark.o \
cfgrammar.o \
actions.o \
$(PARSERS:%=parsers/%.o) \
$(BACKENDS:%=backends/%.o)

View file

@ -37,16 +37,6 @@ static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol);
static void collect_geneps(HCFGrammar *grammar);
// XXX to be consolidated with glue.c when merged upstream
const HParsedToken *h_act_first(const HParseResult *p)
{
assert(p->ast);
assert(p->ast->token_type == TT_SEQUENCE);
assert(p->ast->seq->used > 0);
return p->ast->seq->elements[0];
}
/* Convert 'parser' into CFG representation by desugaring and compiling the set
* of nonterminals.
* A NULL return means we are unable to represent the parser as a CFG.

View file

@ -596,6 +596,14 @@ const uint8_t* h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
*/
void h_bit_writer_free(HBitWriter* w);
// General-purpose actions for use with h_action
// XXX to be consolidated with glue.h when merged upstream
const HParsedToken *h_act_first(const HParseResult *p);
const HParsedToken *h_act_second(const HParseResult *p);
const HParsedToken *h_act_last(const HParseResult *p);
const HParsedToken *h_act_flatten(const HParseResult *p);
const HParsedToken *h_act_ignore(const HParseResult *p);
// {{{ Benchmark functions
HAMMER_FN_DECL(HBenchmarkResults *, h_benchmark, HParser* parser, HParserTestcase* testcases);
void h_benchmark_report(FILE* stream, HBenchmarkResults* results);

View file

@ -31,18 +31,6 @@ static HParseResult* parse_ignoreseq(void* env, HParseState *state) {
return res;
}
extern const HParsedToken *h_act_first(const HParseResult *p);
extern const HParsedToken *h_act_last(const HParseResult *p);
// XXX to be consolidated with glue.c when merged upstream
const HParsedToken *h_act_second(const HParseResult *p) {
assert(p->ast);
assert(p->ast->token_type == TT_SEQUENCE);
assert(p->ast->seq->used > 0);
return p->ast->seq->elements[1];
}
static HCFChoice* desugar_ignoreseq(HAllocator *mm__, void *env) {
HIgnoreSeq *seq = (HIgnoreSeq*)env;
HCFSequence *hseq = h_new(HCFSequence, 1);

View file

@ -56,35 +56,6 @@ static bool many_isValidCF(void *env) {
repeat->sep->vtable->isValidCF(repeat->sep->env));
}
static void act_flatten_(HCountedArray *seq, const HParsedToken *tok) {
if(tok == NULL) {
return;
} else if(tok->token_type == TT_SEQUENCE) {
size_t i;
for(i=0; i<tok->seq->used; i++)
act_flatten_(seq, tok->seq->elements[i]);
} else {
h_carray_append(seq, (HParsedToken *)tok);
}
}
const HParsedToken *h_act_flatten(const HParseResult *p) {
HCountedArray *seq = h_carray_new(p->arena);
act_flatten_(seq, p->ast);
HParsedToken *res = a_new_(p->arena, HParsedToken, 1);
res->token_type = TT_SEQUENCE;
res->seq = seq;
res->index = p->ast->index;
res->bit_offset = p->ast->bit_offset;
return res;
}
const HParsedToken *h_act_ignore(const HParseResult *p) {
return NULL;
}
static HCFChoice* desugar_many(HAllocator *mm__, void *env) {
HRepeat *repeat = (HRepeat*)env;
if(repeat->count > 1) {

View file

@ -17,15 +17,6 @@ static HParseResult* parse_whitespace(void* env, HParseState *state) {
static const char SPACE_CHRS[6] = {' ', '\f', '\n', '\r', '\t', '\v'};
// XXX to be consolidated with glue.c when merged upstream
const HParsedToken *h_act_last(const HParseResult *p) {
assert(p->ast);
assert(p->ast->token_type == TT_SEQUENCE);
assert(p->ast->seq->used > 0);
return p->ast->seq->elements[p->ast->seq->used-1];
}
static HCFChoice* desugar_whitespace(HAllocator *mm__, void *env) {
HCFChoice *ws = h_new(HCFChoice, 1);
ws->type = HCF_CHOICE;