Skip to content

Commit

Permalink
* in an array pattern should not be parsed as nil in ripper
Browse files Browse the repository at this point in the history
After 6c0925b, it was impossible
to distinguish between the presence or absence of `*`.

    # Before the commit
    Ripper.sexp('0 in []')[1][0][2][1]  #=> [:aryptn, nil, nil, nil, nil]
    Ripper.sexp('0 in [*]')[1][0][2][1] #=> [:aryptn, nil, nil, [:var_field, nil], nil]

    # After the commit
    Ripper.sexp('0 in []')[1][0][2][1]  #=> [:aryptn, nil, nil, nil, nil]
    Ripper.sexp('0 in [*]')[1][0][2][1] #=> [:aryptn, nil, nil, nil, nil]

This commit reverts it.
  • Loading branch information
k-tsj committed Apr 1, 2023
1 parent 3a238ef commit 4ac8d11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4656,7 +4656,7 @@ p_rest : tSTAR tIDENTIFIER
/*%%%*/
$$ = 0;
/*% %*/
/*% ripper: Qnil %*/
/*% ripper: var_field(p, Qnil) %*/
}
;

Expand Down
8 changes: 4 additions & 4 deletions test/ripper/test_sexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_dsym
[__LINE__, %q{ case 0; in *; end }] =>
[:case,
[:@int, "0", [1, 5]],
[:in, [:aryptn, nil, nil, nil, nil], [[:void_stmt]], nil]],
[:in, [:aryptn, nil, nil, [:var_field, nil], nil], [[:void_stmt]], nil]],

[__LINE__, %q{ case 0; in *,a; end }] =>
[:case,
Expand All @@ -238,7 +238,7 @@ def test_dsym
[:aryptn,
nil,
nil,
nil,
[:var_field, nil],
[[:var_field, [:@ident, "a", [1, 13]]]]],
[[:void_stmt]],
nil]],
Expand Down Expand Up @@ -426,9 +426,9 @@ def test_dsym
[:in,
[:fndptn,
nil,
nil,
[:var_field, nil],
[[:var_field, [:@ident, "a", [1, 9]]]],
nil],
[:var_field, nil]],
nil,
nil]],

Expand Down

0 comments on commit 4ac8d11

Please sign in to comment.