Skip to content

Instantly share code, notes, and snippets.

@sethhorsley
Created February 10, 2025 04:34
Show Gist options
  • Save sethhorsley/accf9484362d539555c007cfd5f77b93 to your computer and use it in GitHub Desktop.
Save sethhorsley/accf9484362d539555c007cfd5f77b93 to your computer and use it in GitHub Desktop.
Parse ruby from c using prism
#include <prism.h>
#include <stdlib.h>
void erbx_parse(const uint8_t *source, size_t length) {
pm_parser_t parser;
pm_parser_init(&parser, source, length, NULL);
pm_node_t *root = pm_parse(&parser);
const char *hh = pm_token_type_name(root->type);
pm_buffer_t buffer;
pm_buffer_init(&buffer);
pm_prettyprint(&buffer, &parser, root);
printf("%*.s\n", (int) buffer.length, buffer.value);
pm_buffer_free(&buffer);
pm_node_destroy(&parser, root);
pm_parser_free(&parser);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment