Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* right assignment: use existing AST node types (#738) #739

Merged
merged 1 commit into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/AST_FORMAT.md
Expand Up @@ -735,9 +735,10 @@ Format:
Format:

~~~
(rasgn (int 1) (lvasgn :a))
(lvasgn :a (int 1))
"1 => a"
~~~~~~ expression
~ name
~~ operator
~~~

Expand All @@ -746,7 +747,7 @@ Format:
Format:

~~~
(mrasgn (send (int 13) :divmod (int 5)) (mlhs (lvasgn :a) (lvasgn :b)))
(masgn (mlhs (lvasgn :a) (lvasgn :b)) (send (int 13) :divmod (int 5)))
"13.divmod(5) => a,b"
~~~~~~~~~~~~~~~~~~~ expression
^^ operator
Expand Down
3 changes: 0 additions & 3 deletions lib/parser/ast/processor.rb
Expand Up @@ -75,9 +75,6 @@ def on_op_asgn(node)
alias on_mlhs process_regular_node
alias on_masgn process_regular_node

alias on_rasgn process_regular_node
alias on_mrasgn process_regular_node

def on_const(node)
scope_node, name = *node

Expand Down
5 changes: 2 additions & 3 deletions lib/parser/builders/default.rb
Expand Up @@ -656,12 +656,11 @@ def multi_assign(lhs, eql_t, rhs)
end

def rassign(lhs, assoc_t, rhs)
n(:rasgn, [lhs, rhs], binary_op_map(lhs, assoc_t, rhs))
assign(rhs, assoc_t, lhs)
end

def multi_rassign(lhs, assoc_t, rhs)
n(:mrasgn, [ lhs, rhs ],
binary_op_map(lhs, assoc_t, rhs))
multi_assign(rhs, assoc_t, lhs)
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/parser/meta.rb
Expand Up @@ -12,7 +12,7 @@ module Meta
sym dsym xstr regopt regexp array splat
pair kwsplat hash irange erange self
lvar ivar cvar gvar const defined? lvasgn
ivasgn cvasgn gvasgn casgn mlhs masgn rasgn mrasgn
ivasgn cvasgn gvasgn casgn mlhs masgn
op_asgn and_asgn ensure rescue arg_expr
or_asgn back_ref nth_ref
match_with_lvasgn match_current_line
Expand Down
2 changes: 1 addition & 1 deletion lib/parser/source/comment/associator.rb
Expand Up @@ -107,7 +107,7 @@ def associate_locations

private

POSTFIX_TYPES = Set[:if, :while, :while_post, :until, :until_post].freeze
POSTFIX_TYPES = Set[:if, :while, :while_post, :until, :until_post, :masgn].freeze
def children_in_source_order(node)
if POSTFIX_TYPES.include?(node.type)
# All these types have either nodes with expressions, or `nil`
Expand Down
28 changes: 14 additions & 14 deletions test/test_parser.rb
Expand Up @@ -9688,17 +9688,16 @@ def test_endless_method_with_rescue_mod

def test_rasgn
assert_parses(
s(:rasgn,
s(:int, 1), s(:lvasgn, :a)),
s(:lvasgn, :a,
s(:int, 1)),
%q{1 => a},
%q{~~~~~~ expression
| ^^ operator},
SINCE_3_0)

assert_parses(
s(:rasgn,
s(:send, s(:int, 1), :+, s(:int, 2)),
s(:gvasgn, :$a)),
s(:gvasgn, :$a,
s(:send, s(:int, 1), :+, s(:int, 2))),
%q{1 + 2 => $a},
%q{~~~~~~~~~~~ expression
| ^^ operator},
Expand All @@ -9707,22 +9706,23 @@ def test_rasgn

def test_mrasgn
assert_parses(
s(:mrasgn,
s(:send, s(:int, 13), :divmod, s(:int, 5)),
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b))),
s(:masgn,
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b)),
s(:send, s(:int, 13), :divmod, s(:int, 5))),
%q{13.divmod(5) => a,b},
%q{~~~~~~~~~~~~~~~~~~~ expression
| ^^ operator},
SINCE_3_0)

assert_parses(
s(:mrasgn,
s(:mrasgn,
s(:send, s(:int, 13), :divmod, s(:int, 5)),
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b))),
s(:mlhs, s(:lvasgn, :c), s(:lvasgn, :d))),
s(:masgn,
s(:mlhs, s(:lvasgn, :c), s(:lvasgn, :d)),
s(:masgn,
s(:mlhs, s(:lvasgn, :a), s(:lvasgn, :b)),
s(:send, s(:int, 13), :divmod, s(:int, 5))),
),
%q{13.divmod(5) => a,b => c, d},
%q{~~~~~~~~~~~~~~~~~~~ expression (mrasgn)
%q{~~~~~~~~~~~~~~~~~~~ expression (masgn)
|~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression},
SINCE_3_0)
end
Expand Down