Prism Ruby parser
|
Functions related to nodes in the AST. More...
Go to the source code of this file.
Functions | |
void | pm_node_list_append (pm_node_list_t *list, pm_node_t *node) |
Append a new node onto the end of the node list. | |
void | pm_node_list_prepend (pm_node_list_t *list, pm_node_t *node) |
Prepend a new node onto the beginning of the node list. | |
void | pm_node_list_concat (pm_node_list_t *list, pm_node_list_t *other) |
Concatenate the given node list onto the end of the other node list. | |
void | pm_node_list_free (pm_node_list_t *list) |
Free the internal memory associated with the given node list. | |
PRISM_EXPORTED_FUNCTION void | pm_node_destroy (pm_parser_t *parser, struct pm_node *node) |
Deallocate a node and all of its children. | |
PRISM_EXPORTED_FUNCTION const char * | pm_node_type_to_str (pm_node_type_t node_type) |
Returns a string representation of the given node type. | |
PRISM_EXPORTED_FUNCTION void | pm_visit_node (const pm_node_t *node, bool(*visitor)(const pm_node_t *node, void *data), void *data) |
Visit each of the nodes in this subtree using the given visitor callback. | |
PRISM_EXPORTED_FUNCTION void | pm_visit_child_nodes (const pm_node_t *node, bool(*visitor)(const pm_node_t *node, void *data), void *data) |
Visit the children of the given node with the given callback. | |
Functions related to nodes in the AST.
void pm_node_list_append | ( | pm_node_list_t * | list, |
pm_node_t * | node | ||
) |
Append a new node onto the end of the node list.
list | The list to append to. |
node | The node to append. |
void pm_node_list_prepend | ( | pm_node_list_t * | list, |
pm_node_t * | node | ||
) |
Prepend a new node onto the beginning of the node list.
list | The list to prepend to. |
node | The node to prepend. |
void pm_node_list_concat | ( | pm_node_list_t * | list, |
pm_node_list_t * | other | ||
) |
Concatenate the given node list onto the end of the other node list.
list | The list to concatenate onto. |
other | The list to concatenate. |
void pm_node_list_free | ( | pm_node_list_t * | list | ) |
Free the internal memory associated with the given node list.
list | The list to free. |
PRISM_EXPORTED_FUNCTION void pm_node_destroy | ( | pm_parser_t * | parser, |
pm_node_t * | node | ||
) |
Deallocate a node and all of its children.
parser | The parser that owns the node. |
node | The node to deallocate. |
Deallocate a node and all of its children.
Similarly to pm_node_alloc, we're not using the parser argument, but it's there to allow for the future possibility of pre-allocating larger memory pools.
PRISM_EXPORTED_FUNCTION const char * pm_node_type_to_str | ( | pm_node_type_t | node_type | ) |
Returns a string representation of the given node type.
node_type | The node type to convert to a string. |
PRISM_EXPORTED_FUNCTION void pm_visit_node | ( | const pm_node_t * | node, |
bool(*)(const pm_node_t *node, void *data) | visitor, | ||
void * | data | ||
) |
Visit each of the nodes in this subtree using the given visitor callback.
The callback function will be called for each node in the subtree. If it returns false, then that node's children will not be visited. If it returns true, then the children will be visited. The data parameter is treated as an opaque pointer and is passed to the visitor callback for consumers to use as they see fit.
As an example:
node | The root node to start visiting from. |
visitor | The callback to call for each node in the subtree. |
data | An opaque pointer that is passed to the visitor callback. |
The callback function will be called for each node in the subtree. If it returns false, then that node's children will not be visited. If it returns true, then the children will be visited. The data parameter is treated as an opaque pointer and is passed to the visitor callback for consumers to use as they see fit.
PRISM_EXPORTED_FUNCTION void pm_visit_child_nodes | ( | const pm_node_t * | node, |
bool(*)(const pm_node_t *node, void *data) | visitor, | ||
void * | data | ||
) |
Visit the children of the given node with the given callback.
This is the default behavior for walking the tree that is called from pm_visit_node if the callback returns true.
node | The node to visit the children of. |
visitor | The callback to call for each child node. |
data | An opaque pointer that is passed to the visitor callback. |
This is the default behavior for walking the tree that is called from pm_visit_node if the callback returns true.