move the h_act_* functions to src/actions.c
This commit is contained in:
parent
31256ba867
commit
29cee318f9
6 changed files with 9 additions and 60 deletions
|
|
@ -41,6 +41,7 @@ HAMMER_PARTS := \
|
||||||
system_allocator.o \
|
system_allocator.o \
|
||||||
benchmark.o \
|
benchmark.o \
|
||||||
cfgrammar.o \
|
cfgrammar.o \
|
||||||
|
actions.o \
|
||||||
$(PARSERS:%=parsers/%.o) \
|
$(PARSERS:%=parsers/%.o) \
|
||||||
$(BACKENDS:%=backends/%.o)
|
$(BACKENDS:%=backends/%.o)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,16 +37,6 @@ static void collect_nts(HCFGrammar *grammar, HCFChoice *symbol);
|
||||||
static void collect_geneps(HCFGrammar *grammar);
|
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
|
/* Convert 'parser' into CFG representation by desugaring and compiling the set
|
||||||
* of nonterminals.
|
* of nonterminals.
|
||||||
* A NULL return means we are unable to represent the parser as a CFG.
|
* A NULL return means we are unable to represent the parser as a CFG.
|
||||||
|
|
|
||||||
|
|
@ -596,6 +596,14 @@ const uint8_t* h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
|
||||||
*/
|
*/
|
||||||
void h_bit_writer_free(HBitWriter* w);
|
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
|
// {{{ Benchmark functions
|
||||||
HAMMER_FN_DECL(HBenchmarkResults *, h_benchmark, HParser* parser, HParserTestcase* testcases);
|
HAMMER_FN_DECL(HBenchmarkResults *, h_benchmark, HParser* parser, HParserTestcase* testcases);
|
||||||
void h_benchmark_report(FILE* stream, HBenchmarkResults* results);
|
void h_benchmark_report(FILE* stream, HBenchmarkResults* results);
|
||||||
|
|
|
||||||
|
|
@ -31,18 +31,6 @@ static HParseResult* parse_ignoreseq(void* env, HParseState *state) {
|
||||||
return res;
|
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) {
|
static HCFChoice* desugar_ignoreseq(HAllocator *mm__, void *env) {
|
||||||
HIgnoreSeq *seq = (HIgnoreSeq*)env;
|
HIgnoreSeq *seq = (HIgnoreSeq*)env;
|
||||||
HCFSequence *hseq = h_new(HCFSequence, 1);
|
HCFSequence *hseq = h_new(HCFSequence, 1);
|
||||||
|
|
|
||||||
|
|
@ -56,35 +56,6 @@ static bool many_isValidCF(void *env) {
|
||||||
repeat->sep->vtable->isValidCF(repeat->sep->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) {
|
static HCFChoice* desugar_many(HAllocator *mm__, void *env) {
|
||||||
HRepeat *repeat = (HRepeat*)env;
|
HRepeat *repeat = (HRepeat*)env;
|
||||||
if(repeat->count > 1) {
|
if(repeat->count > 1) {
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,6 @@ static HParseResult* parse_whitespace(void* env, HParseState *state) {
|
||||||
|
|
||||||
static const char SPACE_CHRS[6] = {' ', '\f', '\n', '\r', '\t', '\v'};
|
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) {
|
static HCFChoice* desugar_whitespace(HAllocator *mm__, void *env) {
|
||||||
HCFChoice *ws = h_new(HCFChoice, 1);
|
HCFChoice *ws = h_new(HCFChoice, 1);
|
||||||
ws->type = HCF_CHOICE;
|
ws->type = HCF_CHOICE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue