In Files

  • ast.c

Namespace

Class/Module Index [+]

Quicksearch

RubyVM::AST

Public Class Methods

parse(p1) click to toggle source
 
               static VALUE
rb_ast_s_parse(VALUE module, VALUE str)
{
    VALUE obj;
    rb_ast_t *ast = 0;

    const VALUE parser = rb_parser_new();

    str = rb_check_string_type(str);
    rb_parser_set_context(parser, NULL, 1);
    ast = rb_parser_compile_string_path(parser, rb_str_new_cstr("no file name"), str, 1);

    if (!ast->body.root) return Qnil;

    obj = ast_new_internal(ast, (NODE *)ast->body.root);

    return obj;
}
            
parse_file(p1) click to toggle source
 
               static VALUE
rb_ast_s_parse_file(VALUE module, VALUE path)
{
    VALUE obj, f;
    rb_ast_t *ast = 0;
    rb_encoding *enc = rb_utf8_encoding();

    const VALUE parser = rb_parser_new();

    FilePathValue(path);
    f = rb_file_open_str(path, "r");
    rb_funcall(f, rb_intern("set_encoding"), 2, rb_enc_from_encoding(enc), rb_str_new_cstr("-"));
    rb_parser_set_context(parser, NULL, 1);
    ast = rb_parser_compile_file_path(parser, path, f, 1);

    rb_io_close(f);

    if (!ast->body.root) return Qnil;

    obj = ast_new_internal(ast, (NODE *)ast->body.root);

    return obj;
}