diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-10 11:40:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-10 11:40:33 +0000 |
commit | 6e610f5ea717c824b232fc5f3052dd9d5c1a25e3 (patch) | |
tree | 4cb0cbda17385e07d2fb4745af9f0fafa2e5aedd /ast.c | |
parent | 907ae13cf6c8b65039e19a86d3c8fd51a3cd868f (diff) |
Parse the source in SCRIPT_LINES__ as array
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -54,6 +54,7 @@ ast_new_internal(rb_ast_t *ast, NODE *node) VALUE rb_ast_parse_str(VALUE str); VALUE rb_ast_parse_file(VALUE path); +VALUE rb_ast_parse_array(VALUE array); static VALUE ast_parse_new(void) @@ -134,6 +135,29 @@ rb_ast_parse_file(VALUE path) return ast_parse_done(ast); } +VALUE +lex_array(VALUE array, int index) +{ + VALUE str = rb_ary_entry(array, index); + if (!NIL_P(str)) { + StringValue(str); + if (!rb_enc_asciicompat(rb_enc_get(str))) { + rb_raise(rb_eArgError, "invalid source encoding"); + } + } + return str; +} + +VALUE +rb_ast_parse_array(VALUE array) +{ + rb_ast_t *ast = 0; + + array = rb_check_array_type(array); + ast = rb_parser_compile_generic(ast_parse_new(), lex_array, Qnil, array, 1); + return ast_parse_done(ast); +} + static VALUE node_children(rb_ast_t*, NODE*); static VALUE @@ -197,7 +221,7 @@ rb_ast_s_of(VALUE module, VALUE body) path = rb_iseq_path(iseq); node_id = iseq->body->location.node_id; if (!NIL_P(lines = script_lines(path))) { - node = rb_ast_parse_str(rb_ary_join(lines, Qnil)); + node = rb_ast_parse_array(lines); } else { node = rb_ast_parse_file(path); |