summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-17 12:42:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-17 12:42:00 +0000
commit0201900d76c9b05000924dd74b98892db7be3d6e (patch)
tree90f7e0f7b3229c25317e4c86f179f2cf43892e9a
parent5a6a502ef9d88a77f701be8e0dde8fa489eb1e1f (diff)
id.def: $~ and $_
* defs/id.def (predefined): add idLASTLINE and idBACKREF for $~ and $_ respectively. * parse.y: use idLASTLINE and idBACKREF instead of rb_intern. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--defs/id.def5
-rw-r--r--parse.y14
3 files changed, 18 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index df9084d..6b00970 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Feb 17 21:41:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * defs/id.def (predefined): add idLASTLINE and idBACKREF for $~
+ and $_ respectively.
+
+ * parse.y: use idLASTLINE and idBACKREF instead of rb_intern.
+
Wed Feb 17 20:23:38 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_init): fix segfault and memory leak, consider
diff --git a/defs/id.def b/defs/id.def
index 1ff0d9a..e186725 100644
--- a/defs/id.def
+++ b/defs/id.def
@@ -62,6 +62,9 @@ firstline, predefined = __LINE__+1, %[\
core#hash_merge_kwd
- debug#created_info
+
+ $_ LASTLINE
+ $~ BACKREF
]
# VM ID OP Parser Token
@@ -145,7 +148,7 @@ predefined.split(/^/).each_with_index do |line, num|
case name
when /\A[A-Z]\w*\z/; const_ids
when /\A(?!\d)\w+\z/; local_ids
- when /\A\$(?:\d+|(?!\d)\w+)\z/; global_ids
+ when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
when /\A@@(?!\d)\w+\z/; class_ids
when /\A@(?!\d)\w+\z/; instance_ids
when /\A((?!\d)\w+)=\z/; attrset_ids
diff --git a/parse.y b/parse.y
index 49833e0..63ce0df 100644
--- a/parse.y
+++ b/parse.y
@@ -9887,7 +9887,7 @@ cond0(struct parser_params *parser, NODE *node)
case NODE_DREGX:
case NODE_DREGX_ONCE:
warning_unless_e_option(parser, node, "regex literal in condition");
- return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_")));
+ return NEW_MATCH2(node, NEW_GVAR(idLASTLINE));
case NODE_AND:
case NODE_OR:
@@ -10610,7 +10610,7 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
arg->succ_block = block_append(arg->succ_block,
newline_node(node_assign(assignable(var,0),
NEW_CALL(
- gettable(rb_intern("$~")),
+ gettable(idBACKREF),
idAREF,
NEW_LIST(NEW_LIT(ID2SYM(var))))
)));
@@ -10637,12 +10637,12 @@ reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *m
return
block_append(
newline_node(match),
- NEW_IF(gettable(rb_intern("$~")),
+ NEW_IF(gettable(idBACKREF),
block_append(
newline_node(arg.succ_block),
newline_node(
NEW_CALL(
- gettable(rb_intern("$~")),
+ gettable(idBACKREF),
rb_intern("begin"),
NEW_LIST(NEW_LIT(INT2FIX(0)))))),
block_append(
@@ -10712,7 +10712,7 @@ rb_parser_append_print(VALUE vparser, NODE *node)
node = block_append(node,
NEW_FCALL(rb_intern("print"),
- NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
+ NEW_ARRAY(NEW_GVAR(idLASTLINE))));
if (prelude) {
prelude->nd_body = node;
scope->nd_body = prelude;
@@ -10743,12 +10743,12 @@ rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
}
if (split) {
node = block_append(NEW_GASGN(rb_intern("$F"),
- NEW_CALL(NEW_GVAR(rb_intern("$_")),
+ NEW_CALL(NEW_GVAR(idLASTLINE),
rb_intern("split"), 0)),
node);
}
if (chop) {
- node = block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
+ node = block_append(NEW_CALL(NEW_GVAR(idLASTLINE),
rb_intern("chop!"), 0), node);
}