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
|
|
@ -5,48 +5,48 @@ extern ts_parse_config ts_parse_config_json;
|
|||
START_TEST
|
||||
|
||||
describe("json", []() {
|
||||
ts_document *document;
|
||||
ts_document *doc;
|
||||
|
||||
before_each([&]() {
|
||||
document = ts_document_make();
|
||||
ts_document_set_parser(document, ts_parse_config_json);
|
||||
doc = ts_document_make();
|
||||
ts_document_set_parser(doc, ts_parse_config_json);
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
ts_document_free(document);
|
||||
ts_document_free(doc);
|
||||
});
|
||||
|
||||
it("parses strings", [&]() {
|
||||
ts_document_set_text(document, "\"\"");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (string))"));
|
||||
ts_document_set_text(doc, "\"\"");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (string))"));
|
||||
|
||||
ts_document_set_text(document, "\"simple-string\"");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (string))"));
|
||||
ts_document_set_text(doc, "\"simple-string\"");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (string))"));
|
||||
|
||||
ts_document_set_text(document, "\"this is a \\\"string\\\" within a string\"");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (string))"));
|
||||
ts_document_set_text(doc, "\"this is a \\\"string\\\" within a string\"");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (string))"));
|
||||
});
|
||||
|
||||
it("parses objects", [&]() {
|
||||
ts_document_set_text(document, "{}");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (object))"));
|
||||
ts_document_set_text(doc, "{}");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (object))"));
|
||||
|
||||
ts_document_set_text(document, "{ \"key1\": 1 }");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (object (string) (value (number))))"));
|
||||
ts_document_set_text(doc, "{ \"key1\": 1 }");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (object (string) (value (number))))"));
|
||||
|
||||
ts_document_set_text(document, "{\"key1\": 1, \"key2\": 2 }");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (object (string) (value (number)) (string) (value (number))))"));
|
||||
ts_document_set_text(doc, "{\"key1\": 1, \"key2\": 2 }");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (object (string) (value (number)) (string) (value (number))))"));
|
||||
});
|
||||
|
||||
it("parses arrays", [&]() {
|
||||
ts_document_set_text(document, "[]");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (array))"));
|
||||
ts_document_set_text(doc, "[]");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (array))"));
|
||||
|
||||
ts_document_set_text(document, "[5]");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (array (value (number))))"));
|
||||
ts_document_set_text(doc, "[5]");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (array (value (number))))"));
|
||||
|
||||
ts_document_set_text(document, "[1, 2, 3]");
|
||||
AssertThat(string(ts_document_string(document)), Equals("(value (array (value (number)) (value (number)) (value (number))))"));
|
||||
ts_document_set_text(doc, "[1, 2, 3]");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(value (array (value (number)) (value (number)) (value (number))))"));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ describe("trees", []() {
|
|||
ts_tree *tree1, *parent1;
|
||||
|
||||
before_each([&]() {
|
||||
tree1 = ts_tree_make(cat, 0, NULL);
|
||||
parent1 = ts_tree_make(dog, 1, &tree1);
|
||||
tree1 = ts_tree_make_leaf(cat);
|
||||
parent1 = ts_tree_make_node(dog, 1, &tree1);
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
|
|
@ -20,10 +20,10 @@ describe("trees", []() {
|
|||
|
||||
describe("equality", [&]() {
|
||||
it("returns true for identical trees", [&]() {
|
||||
ts_tree *tree2 = ts_tree_make(cat, 0, NULL);
|
||||
ts_tree *tree2 = ts_tree_make_leaf(cat);
|
||||
AssertThat(ts_tree_equals(tree1, tree2), Equals(1));
|
||||
|
||||
ts_tree *parent2 = ts_tree_make(dog, 1, &tree2);
|
||||
ts_tree *parent2 = ts_tree_make_node(dog, 1, &tree2);
|
||||
AssertThat(ts_tree_equals(parent1, parent2), Equals(1));
|
||||
|
||||
ts_tree_release(tree2);
|
||||
|
|
@ -31,13 +31,13 @@ describe("trees", []() {
|
|||
});
|
||||
|
||||
it("returns false for different trees", [&]() {
|
||||
ts_tree *different_tree = ts_tree_make(pig, 0, NULL);
|
||||
ts_tree *different_tree = ts_tree_make_leaf(pig);
|
||||
AssertThat(ts_tree_equals(tree1, different_tree), Equals(0));
|
||||
|
||||
ts_tree *different_parent = ts_tree_make(dog, 1, &different_tree);
|
||||
ts_tree *different_parent = ts_tree_make_node(dog, 1, &different_tree);
|
||||
AssertThat(ts_tree_equals(parent1, different_parent), Equals(0));
|
||||
|
||||
ts_tree *parent_with_same_type = ts_tree_make(cat, 1, &different_parent);
|
||||
ts_tree *parent_with_same_type = ts_tree_make_node(cat, 1, &different_parent);
|
||||
AssertThat(ts_tree_equals(parent_with_same_type, tree1), Equals(0));
|
||||
AssertThat(ts_tree_equals(tree1, parent_with_same_type), Equals(0));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue