diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 2f6e2cfa..4c8b70bf 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -50,7 +50,7 @@ typedef struct ts_document ts_document; 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); +void ts_document_set_input_string(ts_document *document, const char *text); const ts_tree * ts_document_tree(const ts_document *document); const char * ts_document_string(const ts_document *document); diff --git a/spec/main.cpp b/spec/main.cpp index cb78429c..73ef9ab9 100644 --- a/spec/main.cpp +++ b/spec/main.cpp @@ -6,7 +6,7 @@ int main(int argc, char *argv[]) "", "--no-color", "--only=" - "parenthesized expr" + "" }; return bandit::run(4, const_cast(args)); } \ No newline at end of file diff --git a/spec/runtime/arithmetic_spec.cpp b/spec/runtime/arithmetic_spec.cpp index bc341b25..e59c5a4e 100644 --- a/spec/runtime/arithmetic_spec.cpp +++ b/spec/runtime/arithmetic_spec.cpp @@ -17,45 +17,45 @@ describe("arithmetic", []() { }); it("parses variables", [&]() { - ts_document_set_text(doc, "x"); + ts_document_set_input_string(doc, "x"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (variable))))")); }); it("parses numbers", [&]() { - ts_document_set_text(doc, "5"); + ts_document_set_input_string(doc, "5"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (number))))")); }); it("parses products of variables", [&]() { - ts_document_set_text(doc, "x + y"); + ts_document_set_input_string(doc, "x + y"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (variable))) (plus) (term (factor (variable))))")); - ts_document_set_text(doc, "x * y"); + ts_document_set_input_string(doc, "x * y"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (variable)) (times) (factor (variable))))")); }); it("parses complex trees", [&]() { - ts_document_set_text(doc, "x * y + z * a"); + ts_document_set_input_string(doc, "x * y + z * a"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (variable)) (times) (factor (variable))) (plus) (term (factor (variable)) (times) (factor (variable))))")); - ts_document_set_text(doc, "x * (y + z)"); + ts_document_set_input_string(doc, "x * (y + z)"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (variable)) (times) (factor (expression (term (factor (variable))) (plus) (term (factor (variable)))))))")); }); describe("error recovery", [&]() { it("recovers from errors at the top level", [&]() { - ts_document_set_text(doc, "x * * y"); + ts_document_set_input_string(doc, "x * * y"); AssertThat(string(ts_document_string(doc)), Equals("(ERROR)")); }); it("recovers from errors in parenthesized expressions", [&]() { - ts_document_set_text(doc, "x + (y * + z) * 5"); + ts_document_set_input_string(doc, "x + (y * + z) * 5"); AssertThat(string(ts_document_string(doc)), Equals( "(expression (term (factor (variable))) (plus) (term (factor (ERROR)) (times) (factor (number))))")); }); diff --git a/spec/runtime/json_spec.cpp b/spec/runtime/json_spec.cpp index 4d9ddda3..93858134 100644 --- a/spec/runtime/json_spec.cpp +++ b/spec/runtime/json_spec.cpp @@ -17,54 +17,54 @@ describe("json", []() { }); it("parses strings", [&]() { - ts_document_set_text(doc, "\"\""); + ts_document_set_input_string(doc, "\"\""); AssertThat(string(ts_document_string(doc)), Equals("(value (string))")); - ts_document_set_text(doc, "\"simple-string\""); + ts_document_set_input_string(doc, "\"simple-string\""); AssertThat(string(ts_document_string(doc)), Equals("(value (string))")); - ts_document_set_text(doc, "\"this is a \\\"string\\\" within a string\""); + ts_document_set_input_string(doc, "\"this is a \\\"string\\\" within a string\""); AssertThat(string(ts_document_string(doc)), Equals("(value (string))")); }); it("parses objects", [&]() { - ts_document_set_text(doc, "{}"); + ts_document_set_input_string(doc, "{}"); AssertThat(string(ts_document_string(doc)), Equals("(value (object))")); - ts_document_set_text(doc, "{ \"key1\": 1 }"); + ts_document_set_input_string(doc, "{ \"key1\": 1 }"); AssertThat(string(ts_document_string(doc)), Equals("(value (object (string) (value (number))))")); - ts_document_set_text(doc, "{\"key1\": 1, \"key2\": 2 }"); + ts_document_set_input_string(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(doc, "[]"); + ts_document_set_input_string(doc, "[]"); AssertThat(string(ts_document_string(doc)), Equals("(value (array))")); - ts_document_set_text(doc, "[5]"); + ts_document_set_input_string(doc, "[5]"); AssertThat(string(ts_document_string(doc)), Equals("(value (array (value (number))))")); - ts_document_set_text(doc, "[1, 2, 3]"); + ts_document_set_input_string(doc, "[1, 2, 3]"); AssertThat(string(ts_document_string(doc)), Equals("(value (array (value (number)) (value (number)) (value (number))))")); }); describe("errors", [&]() { it("reports errors in the top-level node", [&]() { - ts_document_set_text(doc, "["); + ts_document_set_input_string(doc, "["); AssertThat(string(ts_document_string(doc)), Equals("(ERROR)")); }); it("reports errors inside of arrays and objects", [&]() { - ts_document_set_text(doc, "{ \"key1\": 1, 5 }"); + ts_document_set_input_string(doc, "{ \"key1\": 1, 5 }"); AssertThat(string(ts_document_string(doc)), Equals("(value (object (string) (value (number)) (ERROR)))")); - ts_document_set_text(doc, "[1,,2]"); + ts_document_set_input_string(doc, "[1,,2]"); AssertThat(string(ts_document_string(doc)), Equals("(value (array (value (number)) (ERROR) (value (number))))")); }); it("reports errors in nested objects", [&]() { - ts_document_set_text(doc, "{ \"key1\": { \"key2\": 1, 2 }, [, \"key3\": 3 }"); + ts_document_set_input_string(doc, "{ \"key1\": { \"key2\": 1, 2 }, [, \"key3\": 3 }"); AssertThat(string(ts_document_string(doc)), Equals("(value (object (string) (value (object (string) (value (number)) (ERROR))) (ERROR) (string) (value (number))))")); }); }); diff --git a/src/runtime/document.cpp b/src/runtime/document.cpp index 0aed935b..baefd9c1 100644 --- a/src/runtime/document.cpp +++ b/src/runtime/document.cpp @@ -21,7 +21,7 @@ void ts_document_set_parser(ts_document *document, ts_parse_config config) { document->symbol_names = config.symbol_names; } -void ts_document_set_text(ts_document *document, const char *text) { +void ts_document_set_input_string(ts_document *document, const char *text) { const ts_tree * result = document->parse_fn(text); document->tree = result; document->errors = NULL;