Starting work on Scala-style left-recursion caching.
This commit is contained in:
parent
60fd846b2f
commit
e748b9c4cb
3 changed files with 18 additions and 29 deletions
28
src/hammer.c
28
src/hammer.c
|
|
@ -22,34 +22,6 @@
|
|||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
parse_state_t* from(parse_state_t *ps, const size_t index) {
|
||||
parse_state_t *ret = g_new(parse_state_t, 1);
|
||||
*ret = *ps;
|
||||
ret->input_stream.index += index;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const uint8_t* substring(const parse_state_t *ps, const size_t start, const size_t end) {
|
||||
if (end > start && (ps->input_stream.index + end) < ps->input_stream.length) {
|
||||
gpointer ret = g_malloc(end - start);
|
||||
memcpy(ret, ps->input_stream.input, end - start);
|
||||
return (const uint8_t*)ret;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const GVariant* at(parse_state_t *ps, const size_t index) {
|
||||
GVariant *ret = NULL;
|
||||
if (index + ps->input_stream.index < ps->input_stream.length)
|
||||
ret = g_variant_new_byte((ps->input_stream.input)[index + ps->input_stream.index]);
|
||||
return g_variant_new_maybe(G_VARIANT_TYPE_BYTE, ret);
|
||||
}
|
||||
|
||||
const gchar* to_string(parse_state_t *ps) {
|
||||
return g_strescape((const gchar*)(ps->input_stream.input), NULL);
|
||||
}
|
||||
|
||||
guint djbhash(const uint8_t *buf, size_t len) {
|
||||
guint hash = 5381;
|
||||
while (len--) {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ typedef struct parsed_token {
|
|||
uint64_t uint;
|
||||
double dbl;
|
||||
float flt;
|
||||
GSequence *seq;
|
||||
GSequence *seq; // a sequence of parsed_token_t's
|
||||
};
|
||||
} parsed_token_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,23 @@ typedef struct parser_cache_key {
|
|||
const parser_t *parser;
|
||||
} parser_cache_key_t;
|
||||
|
||||
typedef enum parser_cache_value_type {
|
||||
PC_BASE,
|
||||
PC_IN_RECURSION,
|
||||
PC_LRESULT,
|
||||
PC_RESULT
|
||||
} parser_cache_value_type_t;
|
||||
|
||||
typedef struct parser_cache_value {
|
||||
parser_cache_value_type_t value_type;
|
||||
union {
|
||||
int base;
|
||||
parse_result_t *in_recursion;
|
||||
parse_result_t *lresult;
|
||||
parse_result_t *result;
|
||||
};
|
||||
} parser_cache_value_t;
|
||||
|
||||
typedef unsigned int *charset;
|
||||
|
||||
static inline charset new_charset() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue