node-field-name-for-child | R Documentation |
These functions return the field name for the i
th child of x
.
node_field_name_for_child()
considers both named and anonymous children.
node_field_name_for_named_child()
considers only named children.
Nodes themselves don't know their own field names, because they don't know if they are fields or not. You must have access to their parents to query their field names.
node_field_name_for_child(x, i)
node_field_name_for_named_child(x, i)
x |
A node. |
i |
The index of the child to get the field name for. |
The field name for the i
th child of x
, or NA_character_
if that child
doesn't exist.
language <- treesitter.r::language()
parser <- parser(language)
text <- "fn <- function() { 1 + 1 }"
tree <- parser_parse(parser, text)
node <- tree_root_node(tree)
# Navigate to first child
node <- node_child(node, 1)
node
# Get the field name of the first few children (note that anonymous children
# are considered)
node_field_name_for_child(node, 1)
node_field_name_for_child(node, 2)
# Get the field name of the first few named children (note that anonymous
# children are not considered)
node_field_name_for_named_child(node, 1)
node_field_name_for_named_child(node, 2)
# 10th child doesn't exist, this returns `NA_character_`
node_field_name_for_child(node, 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.