From cd55d5275d1cce5129d62486ec445ad1760f1a3c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 11 May 2018 12:43:16 -0700 Subject: [PATCH] Update the readme to reflect the new API --- README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2feacc25..330dcf86 100644 --- a/README.md +++ b/README.md @@ -179,25 +179,28 @@ tokens, like `(` and `+`. This is useful when analyzing the meaning of a documen TSLanguage *tree_sitter_arithmetic(); int main() { - TSDocument *document = ts_document_new(); - ts_document_set_language(document, tree_sitter_arithmetic()); - ts_document_set_input_string(document, "a + b * 5"); - ts_document_parse(document); + TSParser *parser = ts_parser_new(); + ts_parser_set_language(parser, tree_sitter_arithmetic()); - TSNode root_node = ts_document_root_node(document); - assert(!strcmp(ts_node_type(root_node, document), "expression")); + const char *source_code = "a + b * 5"; + TSTree *tree = ts_parser_parse(parser, NULL, source_code, strlen(source_code)); + + TSNode root_node = ts_tree_root_node(tree); + assert(!strcmp(ts_node_type(root_node), "expression")); assert(ts_node_named_child_count(root_node) == 1); TSNode sum_node = ts_node_named_child(root_node, 0); - assert(!strcmp(ts_node_type(sum_node, document), "sum")); + assert(!strcmp(ts_node_type(sum_node), "sum")); assert(ts_node_named_child_count(sum_node) == 2); TSNode product_node = ts_node_child(ts_node_named_child(sum_node, 1), 0); - assert(!strcmp(ts_node_type(product_node, document), "product")); + assert(!strcmp(ts_node_type(product_node), "product")); assert(ts_node_named_child_count(product_node) == 2); - printf("Syntax tree: %s\n", ts_node_string(root_node, document)); - ts_document_free(document); + printf("Syntax tree: %s\n", ts_node_string(root_node)); + + ts_tree_delete(tree); + ts_parser_delete(parser); return 0; } ```