diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-04 22:01:50 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-04 22:01:50 -0800 |
commit | 3860d330a370b2cb2cf1a1b26fa91907a9748245 (patch) | |
tree | e22b813097c24730d33942677823a2d29b8f4bff /parser.h |
first commit
Diffstat (limited to 'parser.h')
-rw-r--r-- | parser.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/parser.h b/parser.h new file mode 100644 index 0000000..168c7e9 --- /dev/null +++ b/parser.h @@ -0,0 +1,102 @@ +#ifndef PARSER_H_ +#define PARSER_H_ +#include "better_string.h" +#include <stdbool.h> +#include <stdlib.h> + +typedef struct VALUE_STRUCT value_t; +typedef struct ARRAY_STRUCT array_t; + +struct ARRAY_STRUCT { + value_t **items; + size_t size; + size_t capacity; +}; + +struct VALUE_STRUCT { + enum { VWORD, VINT, VFLOAT, VSTR, VQUOTE } type; + union { + long double int_float; + array_t *quote; + string_t *str_word; + }; + bool escaped; +}; + +typedef struct PARSER_STRUCT { + char *source; + int i; + char c; +} parser_t; + +typedef struct NODE_STRUCT { + string_t *key; + value_t *value; + struct NODE_STRUCT *next; +} node_t; + +typedef struct { + node_t *head; + size_t size; +} sll_t; + +typedef struct { + sll_t **buckets; + size_t size; +} ht_t; + +array_t *init_array(size_t size); + +void array_append(array_t *a, value_t *v); + +value_t *array_pop(array_t *a); + +array_t *array_copy(array_t *a); + +void array_free(array_t *a); + +value_t *init_value(int type); + +value_t *value_copy(value_t *v); + +void value_free(value_t *v); + +parser_t *init_parser(char *source); + +void parser_reset(parser_t *p, char *source); + +void parser_move(parser_t *p); + +void parser_skip_whitespace(parser_t *p); + +value_t *parser_get_next(parser_t *p); + +node_t *init_node(string_t *key, value_t *v); + +sll_t *init_sll(); + +void sll_add(sll_t *l, string_t *key, value_t *v); + +value_t *sll_get(sll_t *l, string_t *key); + +void sll_free(sll_t *l); + +ht_t *init_ht(size_t size); + +void ht_add(ht_t *h, string_t *key, value_t *v); + +value_t *ht_get(ht_t *h, string_t *key); + +void ht_free(ht_t *h); + +unsigned long hash(ht_t *h, char *key); + +bool eval_builtins(value_t *v); + +bool eval_ht(value_t *v); + +bool eval_quote(value_t *v); + +void eval(value_t *v); + +#endif // PARSER_H_ |