Rename ts_document_{set_text,set_input_string}
Because next I'll add a more general 'set_input' method
This commit is contained in:
parent
c43ec90dad
commit
21c0f51b84
5 changed files with 24 additions and 24 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ int main(int argc, char *argv[])
|
|||
"",
|
||||
"--no-color",
|
||||
"--only="
|
||||
"parenthesized expr"
|
||||
""
|
||||
};
|
||||
return bandit::run(4, const_cast<char **>(args));
|
||||
}
|
||||
|
|
@ -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))))"));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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))))"));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue