Hi,
At Fri, 13 Apr 2007 15:50:11 +0900,
Robert K. wrote in [ruby-talk:247769]:
I think it’s worth the effort only if a) it really accepts “unlimited”
cases and b) it doesn’t cost performance. (Haven’t checked either)
In this case, yes for a, and almost yes for b, I guess.
Since there was a typo in [ruby-talk:247527], merged patch of
[ruby-talk:247527] and [ruby-talk:247595].
Index: parse.y
— parse.y (revision 12203)
+++ parse.y (working copy)
@@ -273,5 +273,5 @@ static void top_local_setup();
%type bodystmt compstmt stmts stmt expr arg primary command
command_call method_call
%type expr_value arg_value primary_value
-%type if_tail opt_else case_body cases opt_rescue exc_list
exc_var opt_ensure
+%type if_then opt_else case_body cases opt_rescue rescue
exc_list exc_var opt_ensure
%type args when_args call_args call_args2 open_args paren_args
opt_paren_args
%type command_args aref_args opt_block_arg block_arg var_ref
var_lhs
@@ -376,5 +376,7 @@ bodystmt : compstmt
$$ = $1;
if ($2) {
@@ -1553,11 +1555,9 @@ primary : literal
fixpos($$, $1);
}
- | kIF expr_value then
-
compstmt
-
if_tail
-
kEND
- | if_then opt_else kEND
{
@@ -1599,14 +1599,16 @@ primary : literal
}
}
- | kCASE expr_value opt_terms
-
case_body
-
kEND
- | kCASE expr_value opt_terms cases opt_else kEND
{
- | kCASE opt_terms case_body kEND
- | kCASE opt_terms cases opt_else kEND
{
-if_tail : opt_else
- | kELSIF expr_value then
-
compstmt
-
if_tail
+opt_else : none
-opt_else : none
- | kELSE compstmt
+if_then : kIF expr_value then
-
$$ = NEW_IF(cond($2), $4, 0);
-
fixpos($$, $2);
-
$$ = NEW_IF(0, $$, $$);
-
}
- | if_then kELSIF expr_value then
-
compstmt
-
{
-
NODE *elsif = NEW_IF(cond($3), $5, 0);
-
fixpos(elsif, $3);
-
$$ = $1;
-
$$->nd_else->nd_else = elsif;
-
$$->nd_else = elsif;
}
;
@@ -1871,7 +1881,6 @@ brace_block : ‘{’
case_body : kWHEN when_args then
compstmt
-cases : opt_else
- | case_body
+cases : case_body
-opt_rescue : kRESCUE exc_list exc_var then
+opt_rescue : none
- | opt_rescue
-
rescue
-
{
-
if ($1) {
-
$1->nd_head->nd_head = $2;
-
$1->nd_head = $2;
-
$$ = $1;
-
}
-
else {
-
$$ = NEW_RESCUE($2, $2, 0);
-
}
-
}
- ;
-
+rescue : kRESCUE exc_list exc_var then
compstmt
@@ -1899,8 +1931,7 @@ opt_rescue : kRESCUE exc_list exc_var th
$5 = block_append($3, $5);
}
@@ -6109,4 +6140,5 @@ rb_id2name(id)
{
char *name;
- if (st_lookup(sym_rev_tbl, id, (st_data_t *)&name))
- return name;
-
if (st_lookup(sym_rev_tbl, id, &data))
-
return (char *)data;
if (is_attrset_id(id)) {
@@ -6333,5 +6365,5 @@ rb_parser_free(ptr)
NODE **prev = &parser_heap, *n;
- while ((n = *prev) != 0) {
if (n->u1.node == ptr) {
*prev = n->u2.node;