Start work on error recovery
- In runtime, make parse errors part of the parse tree - Add error state to lexers in which they can accept any token
This commit is contained in:
parent
4520d6e1a2
commit
e58a6d8ba7
18 changed files with 622 additions and 528 deletions
|
|
@ -7,36 +7,37 @@ extern "C" {
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
size_t position;
|
||||
char lookahead_char;
|
||||
size_t expected_input_count;
|
||||
const char **expected_inputs;
|
||||
} ts_error;
|
||||
|
||||
const char * ts_error_string(const ts_error *error);
|
||||
|
||||
typedef size_t ts_symbol;
|
||||
typedef int ts_symbol;
|
||||
extern const ts_symbol ts_symbol_error;
|
||||
|
||||
typedef struct ts_tree {
|
||||
ts_symbol value;
|
||||
struct ts_tree **children;
|
||||
size_t child_count;
|
||||
ts_symbol symbol;
|
||||
size_t ref_count;
|
||||
union {
|
||||
struct {
|
||||
size_t count;
|
||||
struct ts_tree **contents;
|
||||
} children;
|
||||
struct {
|
||||
char lookahead_char;
|
||||
size_t expected_input_count;
|
||||
const ts_symbol *expected_inputs;
|
||||
} error;
|
||||
} data;
|
||||
} ts_tree;
|
||||
|
||||
ts_tree * ts_tree_make(ts_symbol value, size_t child_count, ts_tree **children);
|
||||
ts_tree * ts_tree_make_leaf(ts_symbol symbol);
|
||||
ts_tree * ts_tree_make_node(ts_symbol symbol, size_t child_count, ts_tree **children);
|
||||
ts_tree * ts_tree_make_error(char lookahead_char, size_t expected_input_count, const ts_symbol *expected_inputs);
|
||||
void ts_tree_retain(ts_tree *tree);
|
||||
void ts_tree_release(ts_tree *tree);
|
||||
int ts_tree_equals(const ts_tree *tree1, const ts_tree *tree2);
|
||||
char * ts_tree_string(const ts_tree *tree, const char **names);
|
||||
char * ts_tree_error_string(const ts_tree *tree, const char **names);
|
||||
size_t ts_tree_child_count(const ts_tree *tree);
|
||||
ts_tree ** ts_tree_children(const ts_tree *tree);
|
||||
|
||||
typedef struct {
|
||||
ts_error error;
|
||||
ts_tree *tree;
|
||||
} ts_parse_result;
|
||||
|
||||
typedef ts_parse_result ts_parse_fn(const char *);
|
||||
typedef const ts_tree * ts_parse_fn(const char *);
|
||||
|
||||
typedef struct {
|
||||
ts_parse_fn *parse_fn;
|
||||
|
|
@ -49,7 +50,7 @@ ts_document * ts_document_make();
|
|||
void ts_document_free(ts_document *);
|
||||
void ts_document_set_parser(ts_document *document, ts_parse_config config);
|
||||
void ts_document_set_text(ts_document *document, const char *text);
|
||||
ts_tree * ts_document_tree(const ts_document *document);
|
||||
const ts_tree * ts_document_tree(const ts_document *document);
|
||||
const char * ts_document_string(const ts_document *document);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue