Replace R-assignment by single-line pattern matching.

Since `R-assignment` in CRuby is abandoned.  Single-line pattern matching
in `mruby` only matches single local variable at the moment. Currently
it works as a right assignment to a local variable. It will be enhanced
in the future.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2020-10-31 19:45:17 +09:00
parent 70ee936367
commit dc886873bc
4 changed files with 3056 additions and 3178 deletions
+2 -1
View File
@@ -32,7 +32,8 @@ pull-request.
We have ported some new syntax from CRuby.
* R-assignment (`12 => x`)
* Single line pattern matching (`12 => x`);
mruby matches only with local variables at the moment
* Numbered block parameter (`x.map{_1 * 2}`)
* End-less `def` (`def double(x) = x*2`)
+8 -22
View File
@@ -1442,7 +1442,7 @@ heredoc_end(parser_state *p)
%type <nd> singleton string string_fragment string_rep string_interp xstring regexp
%type <nd> literal numeric cpath symbol defn_head defs_head
%type <nd> top_compstmt top_stmts top_stmt rassign
%type <nd> top_compstmt top_stmts top_stmt
%type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
%type <nd> expr_value arg_rhs primary_value
%type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
@@ -1685,30 +1685,16 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
{
$$ = new_masgn(p, $1, new_array(p, $3));
}
| rassign
| arg tASSOC tIDENTIFIER
{
node *lhs = new_lvar(p, $3);
void_expr_error(p, $1);
assignable(p, lhs);
$$ = new_asgn(p, lhs, $1);
}
| expr
;
rassign : arg tASSOC lhs
{
void_expr_error(p, $1);
$$ = new_asgn(p, $3, $1);
}
| arg tASSOC mlhs
{
void_expr_error(p, $1);
$$ = new_masgn(p, $3, $1);
}
| rassign tASSOC lhs
{
$$ = new_asgn(p, $3, $1);
}
| rassign tASSOC mlhs
{
$$ = new_masgn(p, $3, $1);
}
;
command_asgn : lhs '=' command_rhs
{
$$ = new_asgn(p, $1, $3);
File diff suppressed because it is too large Load Diff
+1 -5
View File
@@ -345,13 +345,9 @@ assert('splat object in assignment') do
assert_equal [2], (a = *o)
end
assert('right-ward assignment') do
assert('one-line pattern match') do
1 => a
assert_equal(1, a)
13.divmod(5) => a,b
assert_equal([2,3], [a, b])
13.divmod(5) => a,b => c, d
assert_equal([2,3,2,3], [a, b, c, d])
end
assert('splat object in case statement') do