зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
5a6a502ef9
Коммит
0201900d76
|
@ -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>
|
Wed Feb 17 20:23:38 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* string.c (rb_str_init): fix segfault and memory leak, consider
|
* string.c (rb_str_init): fix segfault and memory leak, consider
|
||||||
|
|
|
@ -62,6 +62,9 @@ firstline, predefined = __LINE__+1, %[\
|
||||||
core#hash_merge_kwd
|
core#hash_merge_kwd
|
||||||
|
|
||||||
- debug#created_info
|
- debug#created_info
|
||||||
|
|
||||||
|
$_ LASTLINE
|
||||||
|
$~ BACKREF
|
||||||
]
|
]
|
||||||
|
|
||||||
# VM ID OP Parser Token
|
# VM ID OP Parser Token
|
||||||
|
@ -145,7 +148,7 @@ predefined.split(/^/).each_with_index do |line, num|
|
||||||
case name
|
case name
|
||||||
when /\A[A-Z]\w*\z/; const_ids
|
when /\A[A-Z]\w*\z/; const_ids
|
||||||
when /\A(?!\d)\w+\z/; local_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/; class_ids
|
||||||
when /\A@(?!\d)\w+\z/; instance_ids
|
when /\A@(?!\d)\w+\z/; instance_ids
|
||||||
when /\A((?!\d)\w+)=\z/; attrset_ids
|
when /\A((?!\d)\w+)=\z/; attrset_ids
|
||||||
|
|
14
parse.y
14
parse.y
|
@ -9887,7 +9887,7 @@ cond0(struct parser_params *parser, NODE *node)
|
||||||
case NODE_DREGX:
|
case NODE_DREGX:
|
||||||
case NODE_DREGX_ONCE:
|
case NODE_DREGX_ONCE:
|
||||||
warning_unless_e_option(parser, node, "regex literal in condition");
|
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_AND:
|
||||||
case NODE_OR:
|
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,
|
arg->succ_block = block_append(arg->succ_block,
|
||||||
newline_node(node_assign(assignable(var,0),
|
newline_node(node_assign(assignable(var,0),
|
||||||
NEW_CALL(
|
NEW_CALL(
|
||||||
gettable(rb_intern("$~")),
|
gettable(idBACKREF),
|
||||||
idAREF,
|
idAREF,
|
||||||
NEW_LIST(NEW_LIT(ID2SYM(var))))
|
NEW_LIST(NEW_LIT(ID2SYM(var))))
|
||||||
)));
|
)));
|
||||||
|
@ -10637,12 +10637,12 @@ reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *m
|
||||||
return
|
return
|
||||||
block_append(
|
block_append(
|
||||||
newline_node(match),
|
newline_node(match),
|
||||||
NEW_IF(gettable(rb_intern("$~")),
|
NEW_IF(gettable(idBACKREF),
|
||||||
block_append(
|
block_append(
|
||||||
newline_node(arg.succ_block),
|
newline_node(arg.succ_block),
|
||||||
newline_node(
|
newline_node(
|
||||||
NEW_CALL(
|
NEW_CALL(
|
||||||
gettable(rb_intern("$~")),
|
gettable(idBACKREF),
|
||||||
rb_intern("begin"),
|
rb_intern("begin"),
|
||||||
NEW_LIST(NEW_LIT(INT2FIX(0)))))),
|
NEW_LIST(NEW_LIT(INT2FIX(0)))))),
|
||||||
block_append(
|
block_append(
|
||||||
|
@ -10712,7 +10712,7 @@ rb_parser_append_print(VALUE vparser, NODE *node)
|
||||||
|
|
||||||
node = block_append(node,
|
node = block_append(node,
|
||||||
NEW_FCALL(rb_intern("print"),
|
NEW_FCALL(rb_intern("print"),
|
||||||
NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
|
NEW_ARRAY(NEW_GVAR(idLASTLINE))));
|
||||||
if (prelude) {
|
if (prelude) {
|
||||||
prelude->nd_body = node;
|
prelude->nd_body = node;
|
||||||
scope->nd_body = prelude;
|
scope->nd_body = prelude;
|
||||||
|
@ -10743,12 +10743,12 @@ rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
|
||||||
}
|
}
|
||||||
if (split) {
|
if (split) {
|
||||||
node = block_append(NEW_GASGN(rb_intern("$F"),
|
node = block_append(NEW_GASGN(rb_intern("$F"),
|
||||||
NEW_CALL(NEW_GVAR(rb_intern("$_")),
|
NEW_CALL(NEW_GVAR(idLASTLINE),
|
||||||
rb_intern("split"), 0)),
|
rb_intern("split"), 0)),
|
||||||
node);
|
node);
|
||||||
}
|
}
|
||||||
if (chop) {
|
if (chop) {
|
||||||
node = block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
|
node = block_append(NEW_CALL(NEW_GVAR(idLASTLINE),
|
||||||
rb_intern("chop!"), 0), node);
|
rb_intern("chop!"), 0), node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче