mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* class.c (rb_scan_args): Allow specifying the number of trailing
mandatory arguments right after the number of optional arguments only if the number of leading mandatory arguments is not omitted. * ext/socket/tcpserver.c (tcp_svr_init): Make use of it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
02316f11d5
commit
400ded9338
5 changed files with 23 additions and 9 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Wed Feb 25 00:41:21 2009 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* class.c (rb_scan_args): Allow specifying the number of trailing
|
||||||
|
mandatory arguments right after the number of optional arguments
|
||||||
|
only if the number of leading mandatory arguments is not omitted.
|
||||||
|
|
||||||
|
* ext/socket/tcpserver.c (tcp_svr_init): Make use of it.
|
||||||
|
|
||||||
Wed Feb 25 00:15:15 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed Feb 25 00:15:15 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* ext/curses/curses.c (curses_colors): new method added. a patch
|
* ext/curses/curses.c (curses_colors): new method added. a patch
|
||||||
|
|
|
@ -1081,9 +1081,10 @@ as follows:
|
||||||
--
|
--
|
||||||
scan-arg-spec := param-arg-spec [block-arg-spec]
|
scan-arg-spec := param-arg-spec [block-arg-spec]
|
||||||
|
|
||||||
param-arg-spec := pre-arg-spec [post-arg-spec] / post-arg-spec
|
param-arg-spec := pre-arg-spec [post-arg-spec] / post-arg-spec / pre-opt-post-arg-spec
|
||||||
pre-arg-spec := num-of-leading-mandatory-args [num-of-optional-args]
|
pre-arg-spec := num-of-leading-mandatory-args [num-of-optional-args]
|
||||||
post-arg-spec := sym-for-variable-length-args [num-of-trailing-mandatory-args]
|
post-arg-spec := sym-for-variable-length-args [num-of-trailing-mandatory-args]
|
||||||
|
pre-opt-post-arg-spec := num-of-leading-mandatory-args num-of-optional-args num-of-trailing-mandatory-args
|
||||||
block-arg-spec := sym-for-block-arg
|
block-arg-spec := sym-for-block-arg
|
||||||
|
|
||||||
num-of-leading-mandatory-args := DIGIT ; The number of leading
|
num-of-leading-mandatory-args := DIGIT ; The number of leading
|
||||||
|
|
|
@ -1180,16 +1180,17 @@ rb_scan_args(int argc, VALUE *argv, const char *fmt, ...)
|
||||||
--
|
--
|
||||||
scan-arg-spec := param-arg-spec [block-arg-spec]
|
scan-arg-spec := param-arg-spec [block-arg-spec]
|
||||||
|
|
||||||
param-arg-spec := pre-arg-spec [post-arg-spec] / post-arg-spec
|
param-arg-spec := pre-arg-spec [post-arg-spec] / post-arg-spec / pre-opt-post-arg-spec
|
||||||
pre-arg-spec := num-of-leading-mandatory-args [num-of-optional-args]
|
pre-arg-spec := num-of-leading-mandatory-args [num-of-optional-args]
|
||||||
post-arg-spec := sym-for-variable-length-args [num-of-trailing-mandatory-args]
|
post-arg-spec := sym-for-variable-length-args [num-of-trailing-mandatory-args]
|
||||||
|
pre-opt-post-arg-spec := num-of-leading-mandatory-args num-of-optional-args num-of-trailing-mandatory-args
|
||||||
block-arg-spec := sym-for-block-arg
|
block-arg-spec := sym-for-block-arg
|
||||||
|
|
||||||
num-of-leading-mandatory-args := DIGIT ; 先頭に置かれる省略不可能な引数の数
|
num-of-leading-mandatory-args := DIGIT ; 先頭に置かれる省略不能な引数の数
|
||||||
num-of-optional-args := DIGIT ; 続いて置かれる省略可能な引数の数
|
num-of-optional-args := DIGIT ; 続いて置かれる省略可能な引数の数
|
||||||
sym-for-variable-length-args := "*" ; 続いて置かれる可変長引数を
|
sym-for-variable-length-args := "*" ; 続いて置かれる可変長引数を
|
||||||
; Rubyの配列で取得するための指定
|
; Rubyの配列で取得するための指定
|
||||||
num-of-trailing-mandatory-args := DIGIT ; 終端に置かれる省略不可能な引数の数
|
num-of-trailing-mandatory-args := DIGIT ; 終端に置かれる省略不能な引数の数
|
||||||
sym-for-block-arg := "&" ; イテレータブロックを取得するための
|
sym-for-block-arg := "&" ; イテレータブロックを取得するための
|
||||||
; 指定
|
; 指定
|
||||||
--
|
--
|
||||||
|
|
6
class.c
6
class.c
|
@ -934,6 +934,11 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
|
||||||
if (ISDIGIT(*p)) {
|
if (ISDIGIT(*p)) {
|
||||||
n_opt = *p - '0';
|
n_opt = *p - '0';
|
||||||
p++;
|
p++;
|
||||||
|
if (ISDIGIT(*p)) {
|
||||||
|
n_trail = *p - '0';
|
||||||
|
p++;
|
||||||
|
goto block_arg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*p == '*') {
|
if (*p == '*') {
|
||||||
|
@ -944,6 +949,7 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
block_arg:
|
||||||
if (*p == '&') {
|
if (*p == '&') {
|
||||||
f_block = 1;
|
f_block = 1;
|
||||||
p++;
|
p++;
|
||||||
|
|
|
@ -26,12 +26,10 @@
|
||||||
static VALUE
|
static VALUE
|
||||||
tcp_svr_init(int argc, VALUE *argv, VALUE sock)
|
tcp_svr_init(int argc, VALUE *argv, VALUE sock)
|
||||||
{
|
{
|
||||||
VALUE arg1, arg2;
|
VALUE hostname, port;
|
||||||
|
|
||||||
if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2)
|
rb_scan_args(argc, argv, "011", &hostname, &port);
|
||||||
return init_inetsock(sock, arg1, arg2, Qnil, Qnil, INET_SERVER);
|
return init_inetsock(sock, hostname, port, Qnil, Qnil, INET_SERVER);
|
||||||
else
|
|
||||||
return init_inetsock(sock, Qnil, arg1, Qnil, Qnil, INET_SERVER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue