summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-10 10:39:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-10 10:39:58 +0000
commit2aed2cbcf22aaaad1dac4c3b79df24c5a542cd61 (patch)
tree569519b23fd22290b2d0035977e9f558836b5dfa /ast.c
parent67099c45057ca72c48ee14960b9be1be6634b85b (diff)
Parse the source in SCRIPT_LINES__ if possible
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/ast.c b/ast.c
index 4e2f05c2b7..0abe33fd9e 100644
--- a/ast.c
+++ b/ast.c
@@ -168,9 +168,23 @@ node_find(VALUE self, const int node_id)
}
static VALUE
+script_lines(VALUE path)
+{
+ VALUE hash, lines;
+ ID script_lines;
+ CONST_ID(script_lines, "SCRIPT_LINES__");
+ if (!rb_const_defined_at(rb_cObject, script_lines)) return Qnil;
+ hash = rb_const_get_at(rb_cObject, script_lines);
+ if (!RB_TYPE_P(hash, T_HASH)) return Qnil;
+ lines = rb_hash_lookup(hash, path);
+ if (!RB_TYPE_P(lines, T_ARRAY)) return Qnil;
+ return lines;
+}
+
+static VALUE
rb_ast_s_of(VALUE module, VALUE body)
{
- VALUE path, node;
+ VALUE path, node, lines;
int node_id;
const rb_iseq_t *iseq = NULL;
@@ -189,7 +203,12 @@ rb_ast_s_of(VALUE module, VALUE body)
path = rb_iseq_path(iseq);
node_id = iseq->body->location.node_id;
- node = rb_ast_parse_file(path);
+ if (!NIL_P(lines = script_lines(path))) {
+ node = rb_ast_parse_str(rb_ary_join(lines, Qnil));
+ }
+ else {
+ node = rb_ast_parse_file(path);
+ }
return node_find(node, node_id);
}