2012-05-26 16:00:43 +02:00
|
|
|
#include "parser_internal.h"
|
|
|
|
|
|
|
|
|
|
static HParseResult* parse_not(void* env, HParseState* state) {
|
|
|
|
|
HInputStream bak = state->input_stream;
|
|
|
|
|
if (h_do_parse((HParser*)env, state))
|
|
|
|
|
return NULL;
|
|
|
|
|
else {
|
|
|
|
|
state->input_stream = bak;
|
|
|
|
|
return make_result(state, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-03 02:18:19 -05:00
|
|
|
static const HCFChoice* desugar_not(HAllocator *mm__, void *env) {
|
|
|
|
|
assert_message(0, "Not context-free, can't be desugared");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-26 16:00:43 +02:00
|
|
|
static const HParserVtable not_vt = {
|
|
|
|
|
.parse = parse_not,
|
2012-12-18 18:10:40 -05:00
|
|
|
.isValidRegular = h_false, /* see and.c for why */
|
|
|
|
|
.isValidCF = h_false, /* also see and.c for why */
|
2013-02-03 02:18:19 -05:00
|
|
|
.desugar = desugar_not,
|
2012-05-26 16:00:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const HParser* h_not(const HParser* p) {
|
2012-10-10 15:58:03 +02:00
|
|
|
return h_not__m(&system_allocator, p);
|
|
|
|
|
}
|
|
|
|
|
const HParser* h_not__m(HAllocator* mm__, const HParser* p) {
|
|
|
|
|
HParser *res = h_new(HParser, 1);
|
2012-05-26 16:00:43 +02:00
|
|
|
res->vtable = ¬_vt;
|
|
|
|
|
res->env = (void*)p;
|
|
|
|
|
return res;
|
|
|
|
|
}
|