* parse.y (block_param): restrict block parameters to be local

variables only.

* test/ruby/test_iterator.rb (TestIterator::test_nested_iterator):
  update test suite to conform the last change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-10-03 15:59:45 +00:00
Родитель eebdfca0b2
Коммит c4e5ec23d3
6 изменённых файлов: 65 добавлений и 26 удалений

Просмотреть файл

@ -4,6 +4,12 @@ Tue Oct 3 21:04:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (mlhs): simplifies the rule a bit.
* parse.y (block_param): restrict block parameters to be local
variables only.
* test/ruby/test_iterator.rb (TestIterator::test_nested_iterator):
update test suite to conform the last change.
Tue Oct 3 02:31:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (splat_value): use "to_splat" instead of "to_ary" to

Просмотреть файл

@ -542,7 +542,8 @@ module Scanf
@string_left = str
@matched_count = 0
@specs.each_with_index do |spec,@i|
@specs.each_with_index do |spec,i|
@i=i
@last_spec_tried = spec
@last_match_tried = spec.match(@string_left)
break unless @last_match_tried

51
parse.y
Просмотреть файл

@ -540,6 +540,7 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
%type <node> f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> assoc_list assocs assoc undef_list backref string_dvar
%type <node> for_var block_param opt_block_param block_param_def block_param0
%type <node> block_param1 bparam_post
%type <node> opt_bv_decl bv_decls bv_decl lambda f_larglist lambda_body
%type <node> brace_block cmd_brace_block do_block lhs none fitem
%type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post
@ -2856,7 +2857,18 @@ for_var : lhs
| mlhs
;
block_param0 : mlhs_item
block_param1 : bv_decl
| tLPAREN block_param rparen
{
/*%%%*/
$$ = $2;
/*%
$$ = dispatch1(mlhs_paren, $2);
%*/
}
;
bparam_post : block_param1
{
/*%%%*/
$$ = NEW_LIST($1);
@ -2864,7 +2876,26 @@ block_param0 : mlhs_item
$$ = mlhs_add(mlhs_new(), $1);
%*/
}
| block_param0 ',' mlhs_item
| bparam_post ',' block_param1
{
/*%%%*/
$$ = list_append($1, $3);
/*%
$$ = mlhs_add($1, $3);
%*/
}
;
block_param0 : block_param1
{
/*%%%*/
$$ = NEW_LIST($1);
/*%
$$ = mlhs_add(mlhs_new(), $1);
%*/
}
| block_param0 ',' block_param1
{
/*%%%*/
$$ = list_append($1, $3);
@ -2904,7 +2935,7 @@ block_param : block_param0
$$ = blockvar_add_block(blockvar_new($1), $4);
%*/
}
| block_param0 ',' tSTAR lhs ',' mlhs_post ',' tAMPER lhs
| block_param0 ',' tSTAR lhs ',' bparam_post ',' tAMPER lhs
{
/*%%%*/
$$ = NEW_BLOCK_PARAM($9, NEW_MASGN($1, NEW_POSTARG($4,$6)));
@ -2931,7 +2962,7 @@ block_param : block_param0
$$ = blockvar_add_block($$, $6);
%*/
}
| block_param0 ',' tSTAR ',' mlhs_post ',' tAMPER lhs
| block_param0 ',' tSTAR ',' bparam_post ',' tAMPER lhs
{
/*%%%*/
$$ = NEW_BLOCK_PARAM($8, NEW_MASGN($1, NEW_POSTARG(-1,$5)));
@ -2948,7 +2979,7 @@ block_param : block_param0
$$ = blockvar_add_star(blockvar_new($1), $4);
%*/
}
| block_param0 ',' tSTAR lhs ',' mlhs_post
| block_param0 ',' tSTAR lhs ',' bparam_post
{
/*%%%*/
$$ = NEW_MASGN($1, NEW_POSTARG($4,$6));
@ -2964,7 +2995,7 @@ block_param : block_param0
$$ = blockvar_add_star(blockvar_new($1), Qnil);
%*/
}
| block_param0 ',' tSTAR ',' mlhs_post
| block_param0 ',' tSTAR ',' bparam_post
{
/*%%%*/
$$ = NEW_MASGN($1, NEW_MASGN($1, NEW_POSTARG(-1,$5)));
@ -2998,7 +3029,7 @@ block_param : block_param0
$$ = blockvar_add_star(blockvar_new(Qnil), $2);
%*/
}
| tSTAR lhs ',' mlhs_post
| tSTAR lhs ',' bparam_post
{
/*%%%*/
$$ = NEW_MASGN(0, NEW_POSTARG($2,$4));
@ -3006,7 +3037,7 @@ block_param : block_param0
$$ = blockvar_add_star(blockvar_new(Qnil), $2);
%*/
}
| tSTAR lhs ',' mlhs_post ',' tAMPER lhs
| tSTAR lhs ',' bparam_post ',' tAMPER lhs
{
/*%%%*/
$$ = NEW_BLOCK_PARAM($7, NEW_MASGN(0, NEW_POSTARG($2,$4)));
@ -3023,7 +3054,7 @@ block_param : block_param0
$$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
%*/
}
| tSTAR ',' mlhs_post
| tSTAR ',' bparam_post
{
/*%%%*/
$$ = NEW_MASGN(0, NEW_POSTARG(-1,$3));
@ -3031,7 +3062,7 @@ block_param : block_param0
$$ = blockvar_add_star(blockvar_new(Qnil), Qnil);
%*/
}
| tSTAR ',' mlhs_post ',' tAMPER lhs
| tSTAR ',' bparam_post ',' tAMPER lhs
{
/*%%%*/
$$ = NEW_BLOCK_PARAM($6, NEW_MASGN(0, NEW_POSTARG(-1,$3)));

Просмотреть файл

@ -23,49 +23,49 @@ ARGV.options do
# mandatory argument
opts.on("-r", "--require=LIBRARY", String,
"require the LIBRARY, before",
"executing your script") {|@library|}
"executing your script") {|lib|@library=lib}
# optional argument
opts.on("-i", "--inplace=[EXTENSION]",
"edit ARGV files in place", # multiline description
"(make backup if EXTENSION supplied)") {|@inplace| @inplace ||= ''}
"(make backup if EXTENSION supplied)") {|inplace| @inplace = inplace || ''}
opts.on("-N=[NUM]", Integer) {|@number|}
opts.on("-N=[NUM]", Integer) {|num|@number=num}
# additional class
opts.on("-t", "--[no-]time[=TIME]", Time, "it's the time") {|@time|}
opts.on("-t", "--[no-]time[=TIME]", Time, "it's the time") {|time|@time=time}
# limit argument syntax
opts.on("-[0-7]", "-F", "--irs=[OCTAL]", OptionParser::OctalInteger,
"specify record separator", "(\\0, if no argument)") {|@irs|}
"specify record separator", "(\\0, if no argument)") {|irs|@irs=irs}
# boolean switch(default true)
@exec = true
opts.on("-n", "--no-exec[=FLAG]", TrueClass, "not really execute") {|@exec|}
opts.on("-n", "--no-exec[=FLAG]", TrueClass, "not really execute") {|exec|@exec=exec}
# array
opts.on("-a", "--list[=LIST,LIST]", Array, "list") {|@list|}
opts.on("-a", "--list[=LIST,LIST]", Array, "list") {|list|@list=list}
# fixed size array
opts.on("--pair[=car,cdr]", Array, "pair") {|@x, @y|}
opts.on("--pair[=car,cdr]", Array, "pair") {|x,y|@x=x; @y=y}
# keyword completion
opts.on("--code=CODE", CODES, CODE_ALIASES, "select coding system",
"("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|@code|}
"("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|c|@code=c}
# optional argument with keyword completion
opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|@type|}
opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|t|@type=t}
# boolean switch with optional argument(default false)
opts.on("-v", "--[no-]verbose=[FLAG]", "run verbosely") {|@verbose|}
opts.on("-v", "--[no-]verbose=[FLAG]", "run verbosely") {|v|@verbose=v}
# easy way, set local variable
opts.on("-q", "--quit", "quit when ARGV is empty") {|@quit|}
opts.on("-q", "--quit", "quit when ARGV is empty") {|q|@quit=q}
# adding on the fly
opts.on("--add=SWITCH=[ARG]", "add option on the fly", /\A(\w+)(?:=.+)?\Z/) do
|opt, var|
opts.on("--#{opt}", "added in runtime", &eval("proc {|@#{var}|}"))
opts.on("--#{opt}", "added in runtime", &eval("proc {|x|@#{var}=x}"))
end
opts.on_head("specific options:")

Просмотреть файл

@ -846,8 +846,9 @@ def tt
}
end
i=0
tt{|i| break if i == 5}
test_ok(i == 5)
test_ok(i == 0)
def tt2(dummy)
yield 1

Просмотреть файл

@ -52,7 +52,7 @@ class TestIterator < Test::Unit::TestCase
def test_nested_iterator
i = 0
tt{|i| break if i == 5}
assert_equal(5, i)
assert_equal(0, i)
assert_raises(ArgumentError) do
tt3{}