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, and its return value determines whether the walk visits that node's children, skips them, or stops entirely. The data parameter is treated as an opaque pointer and is passed to the visitor callback for consumers to use as they see fit.
size_t *indent = (size_t *) data;
for (size_t i = 0; i < *indent * 2; i++) putc(' ', stdout);
size_t next_indent = *indent + 1;
size_t *next_data = &next_indent;
}
int main(void) {
const char *source = "1 + 2; 3 + 4";
size_t size = strlen(source);
size_t indent = 0;
size_t *data = &indent;
pm_options_free(options);
pm_arena_free(arena);
return EXIT_SUCCESS;
}
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_arena_t * pm_arena_new(void)
Returns a newly allocated and initialized arena.
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_options_t * pm_options_new(void)
Allocate a new options struct.
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1)
Allocate and initialize a parser with the given start and end pointers.
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1)
Free both the memory held by the given parser and the parser itself.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser) PRISM_NONNULL(1)
Initiate the parser with the given parser.
PRISM_EXPORTED_FUNCTION void PRISM_EXPORTED_FUNCTION const char * pm_node_type(pm_node_type_t node_type)
Returns a string representation of the given node type.
PRISM_EXPORTED_FUNCTION bool pm_visit_node(const pm_node_t *node, pm_visit_callback_t visitor, void *data) PRISM_NONNULL(1)
Visit each of the nodes in this subtree using the given visitor callback.
pm_visit_result_t
The value returned by a visitor callback, which determines where the walk goes next.
@ PM_VISIT_SKIP
Continue the walk without visiting this node's children.
PRISM_EXPORTED_FUNCTION bool pm_visit_child_nodes(const pm_node_t *node, pm_visit_callback_t visitor, void *data) PRISM_NONNULL(1)
Visit the children of the given node with the given callback.
The main header file for the prism parser.
pm_node_type_t type
This represents the type of the node.
The callback function will be called for each node in the subtree, and its return value determines whether the walk visits that node's children, skips them, or stops entirely. The data parameter is treated as an opaque pointer and is passed to the visitor callback for consumers to use as they see fit.