for the Universal Parser void parser_config_initialize(rb_parser_config_t *config) { config->calloc = calloc; config->malloc = malloc; config->alloc = malloc; config->alloc_n = alloc_n; config->sized_xfree = sized_xfree; // And other adapter function set }
idea to return the AST as a Prism-like class I haven’t planned for it to be used in any future products Then, using Array and Hash should be fine for now
Prism Returns the AST as a Hash and Array result = Kanayago.parse('1 + 1') body = result[:NODE_SCOPE][:body] args = body[:NODE_OPCALL][:args] args[:NODE_LIST][0] # => { NODE_INTEGER: 1 }
VALUE ast_to_hash(const NODE *node) { enum node_type type; // Check and Set node type... switch (type) { // And Other AST NODE case's... case NODE_INTEGER: case NODE_FLOAT: case NODE_RATIONAL: case NODE_IMAGINARY: case NODE_STR: case NODE_SYM: return node_literal_to_hash(node); default: return Qfalse; } }
Kanayago.parse Universal Parser ast_to_hash kanayago_parse Kanayago.parse Given Ruby Code with String Pass to Ruby Code Return AbstractSyntaxTree Given AbstractSyntaxTree Return Converted Hash Pass to Hash