Show the structure of a tree-sitter tree as an S-expression.
Available tree-sitter parsers
This is the manual page of the ts_tree_sexpr() S3 generic function.
Methods in parser packages may override this generic.
For the ones that do see the links to their manual pages in the table.
| Package | Version | Title | Method |
| tsjsonc | 0.0.0.9000 | Edit JSON Files. | |
| tstoml | 0.0.0.9000 | Edit TOML files. |
Details
This function returns a nested list representation of the syntax tree, where each node is represented as a list with its type and children.
See also
Other ts_tree exploration:
ts_tree-brackets,
ts_tree_ast(),
ts_tree_dom(),
ts_tree_query()
Other ts_tree generics:
[[.ts_tree(),
[[<-.ts_tree(),
format.ts_tree(),
print.ts_tree(),
select-set,
ts_tree_ast(),
ts_tree_delete(),
ts_tree_dom(),
ts_tree_format(),
ts_tree_insert(),
ts_tree_new(),
ts_tree_query(),
ts_tree_select(),
ts_tree_unserialize(),
ts_tree_update(),
ts_tree_write()
Examples
# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc(
"{ \"a\": //comment\ntrue, \"b\": [1, 2, 3] }"
)
ts_tree_sexpr(tree)
#> [1] "(document (object (pair key: (string (string_content)) (comment) value: (true)) (pair key: (string (string_content)) value: (array (number) (number) (number)))))"
# Create a parse tree with tstoml --------------------------------------
tree <- tstoml::ts_parse_toml(r"(
[servers]
alpha = { ip = "127.0.0.1", dc = "eqdc10" }
beta = { ip = "127.0.0.2", dc = "eqdc20" }
)")
ts_tree_sexpr(tree)
#> [1] "(document (table (bare_key) (pair (bare_key) (inline_table (pair (bare_key) (string (basic_string (basic_string_content)))) (pair (bare_key) (string (basic_string (basic_string_content)))))) (pair (bare_key) (inline_table (pair (bare_key) (string (basic_string (basic_string_content)))) (pair (bare_key) (string (basic_string (basic_string_content))))))))"