[ruby/yarp] Consolidate OperatorAndWrite and OperatorOrWrite nodes

https://github.com/ruby/yarp/commit/9e680a7598
This commit is contained in:
Kevin Newton 2023-08-18 15:09:38 -04:00 committed by git
parent 3d7a030112
commit ec47fc9539
17 changed files with 171 additions and 668 deletions

View File

@ -17,6 +17,16 @@ module YARP
assert_location(AndNode, "foo && bar") assert_location(AndNode, "foo && bar")
end end
def test_AndWriteNode
assert_location(AndWriteNode, "foo &&= bar")
assert_location(AndWriteNode, "foo = 1; foo &&= bar", 9...20)
assert_location(AndWriteNode, "@@foo &&= bar")
assert_location(AndWriteNode, "Parent::Child &&= bar")
assert_location(AndWriteNode, "Foo &&= bar")
assert_location(AndWriteNode, "$foo &&= bar")
assert_location(AndWriteNode, "@foo &&= bar")
end
def test_ArgumentsNode def test_ArgumentsNode
assert_location(ArgumentsNode, "foo(bar, baz, qux)", 4...17, &:arguments) assert_location(ArgumentsNode, "foo(bar, baz, qux)", 4...17, &:arguments)
end end
@ -199,18 +209,10 @@ module YARP
assert_location(ClassNode, "class Foo < Bar end") assert_location(ClassNode, "class Foo < Bar end")
end end
def test_ClassVariableOperatorAndWriteNode
assert_location(ClassVariableOperatorAndWriteNode, "@@foo &&= bar")
end
def test_ClassVariableOperatorWriteNode def test_ClassVariableOperatorWriteNode
assert_location(ClassVariableOperatorWriteNode, "@@foo += bar") assert_location(ClassVariableOperatorWriteNode, "@@foo += bar")
end end
def test_ClassVariableOperatorOrWriteNode
assert_location(ClassVariableOperatorOrWriteNode, "@@foo ||= bar")
end
def test_ClassVariableReadNode def test_ClassVariableReadNode
assert_location(ClassVariableReadNode, "@@foo") assert_location(ClassVariableReadNode, "@@foo")
end end
@ -231,30 +233,14 @@ module YARP
assert_location(ConstantPathWriteNode, "::Foo::Bar = baz") assert_location(ConstantPathWriteNode, "::Foo::Bar = baz")
end end
def test_ConstantPathOperatorAndWriteNode
assert_location(ConstantPathOperatorAndWriteNode, "Parent::Child &&= bar")
end
def test_ConstantPathOperatorWriteNode def test_ConstantPathOperatorWriteNode
assert_location(ConstantPathOperatorWriteNode, "Parent::Child += bar") assert_location(ConstantPathOperatorWriteNode, "Parent::Child += bar")
end end
def test_ConstantPathOperatorOrWriteNode
assert_location(ConstantPathOperatorOrWriteNode, "Parent::Child ||= bar")
end
def test_ConstantOperatorAndWriteNode
assert_location(ConstantOperatorAndWriteNode, "Foo &&= bar")
end
def test_ConstantOperatorWriteNode def test_ConstantOperatorWriteNode
assert_location(ConstantOperatorWriteNode, "Foo += bar") assert_location(ConstantOperatorWriteNode, "Foo += bar")
end end
def test_ConstantOperatorOrWriteNode
assert_location(ConstantOperatorOrWriteNode, "Foo ||= bar")
end
def test_ConstantReadNode def test_ConstantReadNode
assert_location(ConstantReadNode, "Foo") assert_location(ConstantReadNode, "Foo")
assert_location(ConstantReadNode, "Foo::Bar", 5...8, &:child) assert_location(ConstantReadNode, "Foo::Bar", 5...8, &:child)
@ -328,18 +314,10 @@ module YARP
assert_location(ForwardingSuperNode, "super {}") assert_location(ForwardingSuperNode, "super {}")
end end
def test_GlobalVariableOperatorAndWriteNode
assert_location(GlobalVariableOperatorAndWriteNode, "$foo &&= bar")
end
def test_GlobalVariableOperatorWriteNode def test_GlobalVariableOperatorWriteNode
assert_location(GlobalVariableOperatorWriteNode, "$foo += bar") assert_location(GlobalVariableOperatorWriteNode, "$foo += bar")
end end
def test_GlobalVariableOperatorOrWriteNode
assert_location(GlobalVariableOperatorOrWriteNode, "$foo ||= bar")
end
def test_GlobalVariableReadNode def test_GlobalVariableReadNode
assert_location(GlobalVariableReadNode, "$foo") assert_location(GlobalVariableReadNode, "$foo")
end end
@ -374,18 +352,10 @@ module YARP
end end
end end
def test_InstanceVariableOperatorAndWriteNode
assert_location(InstanceVariableOperatorAndWriteNode, "@foo &&= bar")
end
def test_InstanceVariableOperatorWriteNode def test_InstanceVariableOperatorWriteNode
assert_location(InstanceVariableOperatorWriteNode, "@foo += bar") assert_location(InstanceVariableOperatorWriteNode, "@foo += bar")
end end
def test_InstanceVariableOperatorOrWriteNode
assert_location(InstanceVariableOperatorOrWriteNode, "@foo ||= bar")
end
def test_InstanceVariableReadNode def test_InstanceVariableReadNode
assert_location(InstanceVariableReadNode, "@foo") assert_location(InstanceVariableReadNode, "@foo")
end end
@ -452,20 +422,11 @@ module YARP
assert_location(LambdaNode, "-> do foo end") assert_location(LambdaNode, "-> do foo end")
end end
def test_LocalVariableOperatorAndWriteNode
assert_location(LocalVariableOperatorAndWriteNode, "foo &&= bar")
assert_location(LocalVariableOperatorAndWriteNode, "foo = 1; foo &&= bar", 9...20)
end
def test_LocalVariableOperatorWriteNode def test_LocalVariableOperatorWriteNode
assert_location(LocalVariableOperatorWriteNode, "foo += bar") assert_location(LocalVariableOperatorWriteNode, "foo += bar")
assert_location(LocalVariableOperatorWriteNode, "foo = 1; foo += bar", 9...19) assert_location(LocalVariableOperatorWriteNode, "foo = 1; foo += bar", 9...19)
end end
def test_LocalVariableOperatorOrWriteNode
assert_location(LocalVariableOperatorOrWriteNode, "foo ||= bar")
assert_location(LocalVariableOperatorOrWriteNode, "foo = 1; foo ||= bar", 9...20)
end
def test_LocalVariableReadNode def test_LocalVariableReadNode
assert_location(LocalVariableReadNode, "foo = 1; foo", 9...12) assert_location(LocalVariableReadNode, "foo = 1; foo", 9...12)
@ -521,6 +482,16 @@ module YARP
assert_location(OrNode, "foo or bar") assert_location(OrNode, "foo or bar")
end end
def test_OrWriteNode
assert_location(OrWriteNode, "@@foo ||= bar")
assert_location(OrWriteNode, "Parent::Child ||= bar")
assert_location(OrWriteNode, "Foo ||= bar")
assert_location(OrWriteNode, "$foo ||= bar")
assert_location(OrWriteNode, "@foo ||= bar")
assert_location(OrWriteNode, "foo ||= bar")
assert_location(OrWriteNode, "foo = 1; foo ||= bar", 9...20)
end
def test_ParametersNode def test_ParametersNode
assert_location(ParametersNode, "def foo(bar, baz); end", 8...16, &:parameters) assert_location(ParametersNode, "def foo(bar, baz); end", 8...16, &:parameters)
end end

View File

@ -1,11 +1,10 @@
ProgramNode(0...24)( ProgramNode(0...24)(
[:a], [:a],
StatementsNode(0...24)( StatementsNode(0...24)(
[LocalVariableOperatorAndWriteNode(0...7)( [AndWriteNode(0...7)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...5),
CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"), CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"),
:a (2...5)
), ),
LocalVariableOperatorWriteNode(9...15)( LocalVariableOperatorWriteNode(9...15)(
(9...10), (9...10),
@ -14,11 +13,10 @@ ProgramNode(0...24)(
:a, :a,
:+ :+
), ),
LocalVariableOperatorOrWriteNode(17...24)( OrWriteNode(17...24)(
(17...18), LocalVariableReadNode(17...18)(:a, 0),
(19...22),
CallNode(23...24)(nil, nil, (23...24), nil, nil, nil, nil, 2, "b"), CallNode(23...24)(nil, nil, (23...24), nil, nil, nil, nil, 2, "b"),
:a (19...22)
)] )]
) )
) )

View File

@ -1,15 +1,14 @@
ProgramNode(0...18)( ProgramNode(0...18)(
[:a], [:a],
StatementsNode(0...18)( StatementsNode(0...18)(
[LocalVariableOperatorOrWriteNode(0...18)( [OrWriteNode(0...18)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...5),
RescueModifierNode(6...18)( RescueModifierNode(6...18)(
CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"), CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"),
(8...14), (8...14),
NilNode(15...18)() NilNode(15...18)()
), ),
:a (2...5)
)] )]
) )
) )

View File

@ -1,14 +1,14 @@
ProgramNode(0...12)( ProgramNode(0...12)(
[], [],
StatementsNode(0...12)( StatementsNode(0...12)(
[ConstantPathOperatorOrWriteNode(0...12)( [OrWriteNode(0...12)(
ConstantPathNode(0...6)( ConstantPathNode(0...6)(
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
ConstantReadNode(5...6)(), ConstantReadNode(5...6)(),
(3...5) (3...5)
), ),
(7...10), IntegerNode(11...12)(),
IntegerNode(11...12)() (7...10)
)] )]
) )
) )

View File

@ -1,10 +1,10 @@
ProgramNode(0...9)( ProgramNode(0...9)(
[], [],
StatementsNode(0...9)( StatementsNode(0...9)(
[ConstantPathOperatorOrWriteNode(0...9)( [OrWriteNode(0...9)(
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
(4...7), IntegerNode(8...9)(),
IntegerNode(8...9)() (4...7)
)] )]
) )
) )

View File

@ -1,10 +1,10 @@
ProgramNode(0...9)( ProgramNode(0...9)(
[], [],
StatementsNode(0...9)( StatementsNode(0...9)(
[ConstantPathOperatorAndWriteNode(0...9)( [AndWriteNode(0...9)(
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
(4...7), IntegerNode(8...9)(),
IntegerNode(8...9)() (4...7)
)] )]
) )
) )

View File

@ -1,14 +1,14 @@
ProgramNode(0...10)( ProgramNode(0...10)(
[], [],
StatementsNode(0...10)( StatementsNode(0...10)(
[ConstantPathOperatorOrWriteNode(0...10)( [OrWriteNode(0...10)(
ConstantPathNode(0...4)( ConstantPathNode(0...4)(
ConstantReadNode(0...1)(), ConstantReadNode(0...1)(),
ConstantReadNode(3...4)(), ConstantReadNode(3...4)(),
(1...3) (1...3)
), ),
(5...8), IntegerNode(9...10)(),
IntegerNode(9...10)() (5...8)
)] )]
) )
) )

View File

@ -1,9 +1,8 @@
ProgramNode(0...11)( ProgramNode(0...11)(
[:a], [:a],
StatementsNode(0...11)( StatementsNode(0...11)(
[LocalVariableOperatorOrWriteNode(0...11)( [OrWriteNode(0...11)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...5),
CallNode(6...11)( CallNode(6...11)(
CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"), CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"),
(7...8), (7...8),
@ -15,7 +14,7 @@ ProgramNode(0...11)(
0, 0,
"c" "c"
), ),
:a (2...5)
)] )]
) )
) )

View File

@ -610,10 +610,10 @@ ProgramNode(0...704)(
), ),
(543...546) (543...546)
), ),
InstanceVariableOperatorOrWriteNode(551...561)( OrWriteNode(551...561)(
(551...553), InstanceVariableReadNode(551...553)(),
(554...557), StringNode(558...561)((558...560), (560...560), (560...561), ""),
StringNode(558...561)((558...560), (560...560), (560...561), "") (554...557)
), ),
LocalVariableWriteNode(562...576)( LocalVariableWriteNode(562...576)(
:x, :x,
@ -703,16 +703,16 @@ ProgramNode(0...704)(
), ),
(665...668) (665...668)
), ),
InstanceVariableOperatorOrWriteNode(687...704)( OrWriteNode(687...704)(
(687...689), InstanceVariableReadNode(687...689)(),
(690...693),
InterpolatedStringNode(694...704)( InterpolatedStringNode(694...704)(
(694...704), (694...704),
[StringNode(705...707)(nil, (705...707), nil, " "), [StringNode(705...707)(nil, (705...707), nil, " "),
EmbeddedStatementsNode(707...710)((707...709), nil, (709...710)), EmbeddedStatementsNode(707...710)((707...709), nil, (709...710)),
StringNode(710...711)(nil, (710...711), nil, "\n")], StringNode(710...711)(nil, (710...711), nil, "\n")],
(711...719) (711...719)
) ),
(690...693)
)] )]
) )
) )

View File

@ -36,26 +36,23 @@ ProgramNode(0...233)(
:a, :a,
:/ :/
), ),
LocalVariableOperatorAndWriteNode(36...43)( AndWriteNode(36...43)(
(36...37), LocalVariableReadNode(36...37)(:a, 0),
(38...41),
CallNode(42...43)(nil, nil, (42...43), nil, nil, nil, nil, 2, "b"), CallNode(42...43)(nil, nil, (42...43), nil, nil, nil, nil, 2, "b"),
:a (38...41)
), ),
LocalVariableOperatorOrWriteNode(44...51)( OrWriteNode(44...51)(
(44...45), LocalVariableReadNode(44...45)(:a, 0),
(46...49),
IntegerNode(50...51)(), IntegerNode(50...51)(),
:a (46...49)
), ),
CallNode(52...65)( CallNode(52...65)(
ParenthesesNode(52...61)( ParenthesesNode(52...61)(
StatementsNode(53...60)( StatementsNode(53...60)(
[LocalVariableOperatorOrWriteNode(53...60)( [OrWriteNode(53...60)(
(53...54), LocalVariableReadNode(53...54)(:a, 0),
(55...58),
IntegerNode(59...60)(), IntegerNode(59...60)(),
:a (55...58)
)] )]
), ),
(52...53), (52...53),
@ -73,11 +70,10 @@ ProgramNode(0...233)(
CallNode(66...83)( CallNode(66...83)(
ParenthesesNode(66...76)( ParenthesesNode(66...76)(
StatementsNode(67...75)( StatementsNode(67...75)(
[LocalVariableOperatorOrWriteNode(67...75)( [OrWriteNode(67...75)(
(67...68), LocalVariableReadNode(67...68)(:h, 0),
(69...72),
HashNode(73...75)((73...74), [], (74...75)), HashNode(73...75)((73...74), [], (74...75)),
:h (69...72)
)] )]
), ),
(66...67), (66...67),

View File

@ -6,9 +6,8 @@ ProgramNode(0...991)(
(0...6), (0...6),
ConstantReadNode(7...8)(), ConstantReadNode(7...8)(),
StatementsNode(11...31)( StatementsNode(11...31)(
[LocalVariableOperatorOrWriteNode(11...31)( [OrWriteNode(11...31)(
(11...14), LocalVariableReadNode(11...14)(:foo, 0),
(15...18),
ParenthesesNode(19...31)( ParenthesesNode(19...31)(
StatementsNode(21...30)( StatementsNode(21...30)(
[MultiWriteNode(21...30)( [MultiWriteNode(21...30)(
@ -45,7 +44,7 @@ ProgramNode(0...991)(
(19...20), (19...20),
(30...31) (30...31)
), ),
:foo (15...18)
)] )]
), ),
(32...35) (32...35)

View File

@ -28,14 +28,14 @@ ProgramNode(0...77)(
nil, nil,
nil, nil,
StatementsNode(36...45)( StatementsNode(36...45)(
[ConstantPathOperatorOrWriteNode(36...45)( [OrWriteNode(36...45)(
ConstantPathNode(36...39)( ConstantPathNode(36...39)(
nil, nil,
ConstantReadNode(38...39)(), ConstantReadNode(38...39)(),
(36...38) (36...38)
), ),
(40...43), IntegerNode(44...45)(),
IntegerNode(44...45)() (40...43)
)] )]
), ),
[], [],
@ -51,14 +51,14 @@ ProgramNode(0...77)(
nil, nil,
nil, nil,
StatementsNode(59...72)( StatementsNode(59...72)(
[ConstantPathOperatorOrWriteNode(59...72)( [OrWriteNode(59...72)(
ConstantPathNode(59...66)( ConstantPathNode(59...66)(
SelfNode(59...63)(), SelfNode(59...63)(),
ConstantReadNode(65...66)(), ConstantReadNode(65...66)(),
(63...65) (63...65)
), ),
(67...70), IntegerNode(71...72)(),
IntegerNode(71...72)() (67...70)
)] )]
), ),
[], [],

View File

@ -301,13 +301,12 @@ ProgramNode(0...437)(
), ),
:+ :+
), ),
ConstantPathOperatorOrWriteNode(242...273)( OrWriteNode(242...273)(
ConstantPathNode(242...248)( ConstantPathNode(242...248)(
LocalVariableReadNode(242...245)(:foo, 0), LocalVariableReadNode(242...245)(:foo, 0),
ConstantReadNode(247...248)(), ConstantReadNode(247...248)(),
(245...247) (245...247)
), ),
(249...252),
CallNode(253...273)( CallNode(253...273)(
nil, nil,
nil, nil,
@ -334,15 +333,15 @@ ProgramNode(0...437)(
nil, nil,
0, 0,
"raise" "raise"
) ),
(249...252)
), ),
ConstantPathOperatorOrWriteNode(275...307)( OrWriteNode(275...307)(
ConstantPathNode(275...281)( ConstantPathNode(275...281)(
LocalVariableReadNode(275...278)(:foo, 0), LocalVariableReadNode(275...278)(:foo, 0),
ConstantReadNode(280...281)(), ConstantReadNode(280...281)(),
(278...280) (278...280)
), ),
(282...285),
RescueModifierNode(286...307)( RescueModifierNode(286...307)(
CallNode(286...296)( CallNode(286...296)(
nil, nil,
@ -369,7 +368,8 @@ ProgramNode(0...437)(
), ),
(297...303), (297...303),
NilNode(304...307)() NilNode(304...307)()
) ),
(282...285)
), ),
CallOperatorWriteNode(309...339)( CallOperatorWriteNode(309...339)(
CallNode(309...315)( CallNode(309...315)(

View File

@ -1,11 +1,10 @@
ProgramNode(0...7)( ProgramNode(0...7)(
[:a], [:a],
StatementsNode(0...7)( StatementsNode(0...7)(
[LocalVariableOperatorAndWriteNode(0...7)( [AndWriteNode(0...7)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...5),
IntegerNode(6...7)(), IntegerNode(6...7)(),
:a (2...5)
)] )]
) )
) )

View File

@ -1,11 +1,10 @@
ProgramNode(0...7)( ProgramNode(0...7)(
[:a], [:a],
StatementsNode(0...7)( StatementsNode(0...7)(
[LocalVariableOperatorOrWriteNode(0...7)( [OrWriteNode(0...7)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...5),
IntegerNode(6...7)(), IntegerNode(6...7)(),
:a (2...5)
)] )]
) )
) )

View File

@ -399,6 +399,19 @@ nodes:
left and right left and right
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
- name: AndWriteNode
child_nodes:
- name: target
type: node
- name: value
type: node
- name: operator_loc
type: location
comment: |
Represents the use of the `&&=` operator.
target &&= value
^^^^^^^^^^^^^^^^
- name: ArgumentsNode - name: ArgumentsNode
child_nodes: child_nodes:
- name: arguments - name: arguments
@ -723,32 +736,6 @@ nodes:
class Foo end class Foo end
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
- name: ClassVariableOperatorAndWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `&&=` operator for assignment to a class variable.
@@target &&= value
^^^^^^^^^^^^^^^^
- name: ClassVariableOperatorOrWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `||=` operator for assignment to a class variable.
@@target ||= value
^^^^^^^^^^^^^^^^^^
- name: ClassVariableOperatorWriteNode - name: ClassVariableOperatorWriteNode
child_nodes: child_nodes:
- name: name_loc - name: name_loc
@ -783,32 +770,6 @@ nodes:
@@foo = 1 @@foo = 1
^^^^^^^^^ ^^^^^^^^^
- name: ConstantOperatorAndWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `&&=` operator for assignment to a constant.
Target &&= value
^^^^^^^^^^^^^^^^
- name: ConstantOperatorOrWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `||=` operator for assignment to a constant.
Target ||= value
^^^^^^^^^^^^^^^^
- name: ConstantOperatorWriteNode - name: ConstantOperatorWriteNode
child_nodes: child_nodes:
- name: name_loc - name: name_loc
@ -837,34 +798,6 @@ nodes:
Foo::Bar Foo::Bar
^^^^^^^^ ^^^^^^^^
- name: ConstantPathOperatorAndWriteNode
child_nodes:
- name: target
type: node
kind: ConstantPathNode
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `&&=` operator for assignment to a constant path.
Parent::Child &&= value
^^^^^^^^^^^^^^^^^^^^^^^
- name: ConstantPathOperatorOrWriteNode
child_nodes:
- name: target
type: node
kind: ConstantPathNode
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `||=` operator for assignment to a constant path.
Parent::Child ||= value
^^^^^^^^^^^^^^^^^^^^^^^
- name: ConstantPathOperatorWriteNode - name: ConstantPathOperatorWriteNode
child_nodes: child_nodes:
- name: target - name: target
@ -1123,32 +1056,6 @@ nodes:
super super
^^^^^ ^^^^^
- name: GlobalVariableOperatorAndWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `&&=` operator for assignment to a global variable.
$target &&= value
^^^^^^^^^^^^^^^^^
- name: GlobalVariableOperatorOrWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `||=` operator for assignment to a global variable.
$target ||= value
^^^^^^^^^^^^^^^^^
- name: GlobalVariableOperatorWriteNode - name: GlobalVariableOperatorWriteNode
child_nodes: child_nodes:
- name: name_loc - name: name_loc
@ -1263,32 +1170,6 @@ nodes:
case a; in b then c end case a; in b then c end
^^^^^^^^^^^ ^^^^^^^^^^^
- name: InstanceVariableOperatorAndWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `&&=` operator for assignment to an instance variable.
@target &&= value
^^^^^^^^^^^^^^^^^
- name: InstanceVariableOperatorOrWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
comment: |
Represents the use of the `||=` operator for assignment to an instance variable.
@target ||= value
^^^^^^^^^^^^^^^^^
- name: InstanceVariableOperatorWriteNode - name: InstanceVariableOperatorWriteNode
child_nodes: child_nodes:
- name: name_loc - name: name_loc
@ -1441,36 +1322,6 @@ nodes:
->(value) { value * 2 } ->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
- name: LocalVariableOperatorAndWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: constant_id
type: constant
comment: |
Represents the use of the `&&=` operator for assignment to a local variable.
target &&= value
^^^^^^^^^^^^^^^^
- name: LocalVariableOperatorOrWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: constant_id
type: constant
comment: |
Represents the use of the `||=` operator for assignment to a local variable.
target ||= value
^^^^^^^^^^^^^^^^
- name: LocalVariableOperatorWriteNode - name: LocalVariableOperatorWriteNode
child_nodes: child_nodes:
- name: name_loc - name: name_loc
@ -1647,6 +1498,19 @@ nodes:
left or right left or right
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
- name: OrWriteNode
child_nodes:
- name: target
type: node
- name: value
type: node
- name: operator_loc
type: location
comment: |
Represents the use of the `||=` operator.
target ||= value
^^^^^^^^^^^^^^^^
- name: ParametersNode - name: ParametersNode
child_nodes: child_nodes:
- name: requireds - name: requireds

View File

@ -658,6 +658,27 @@ yp_and_node_create(yp_parser_t *parser, yp_node_t *left, const yp_token_t *opera
return node; return node;
} }
// Allocate and initialize a new AndWriteNode.
static yp_and_write_node_t *
yp_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_and_write_node_t);
*node = (yp_and_write_node_t) {
{
.type = YP_NODE_AND_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
},
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate an initialize a new arguments node. // Allocate an initialize a new arguments node.
static yp_arguments_node_t * static yp_arguments_node_t *
yp_arguments_node_create(yp_parser_t *parser) { yp_arguments_node_create(yp_parser_t *parser) {
@ -1485,29 +1506,6 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y
return node; return node;
} }
// Allocate and initialize a new ClassVariableOperatorAndWriteNode node.
static yp_class_variable_operator_and_write_node_t *
yp_class_variable_operator_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_CLASS_VARIABLE_READ_NODE));
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_class_variable_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_class_variable_operator_and_write_node_t);
*node = (yp_class_variable_operator_and_write_node_t) {
{
.type = YP_NODE_CLASS_VARIABLE_OPERATOR_AND_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ClassVariableOperatorWriteNode node. // Allocate and initialize a new ClassVariableOperatorWriteNode node.
static yp_class_variable_operator_write_node_t * static yp_class_variable_operator_write_node_t *
yp_class_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_class_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
@ -1530,29 +1528,6 @@ yp_class_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *tar
return node; return node;
} }
// Allocate and initialize a new ClassVariableOperatorOrWriteNode node.
static yp_class_variable_operator_or_write_node_t *
yp_class_variable_operator_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_CLASS_VARIABLE_READ_NODE));
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_class_variable_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_class_variable_operator_or_write_node_t);
*node = (yp_class_variable_operator_or_write_node_t) {
{
.type = YP_NODE_CLASS_VARIABLE_OPERATOR_OR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ClassVariableReadNode node. // Allocate and initialize a new ClassVariableReadNode node.
static yp_class_variable_read_node_t * static yp_class_variable_read_node_t *
yp_class_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) { yp_class_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) {
@ -1583,28 +1558,6 @@ yp_class_variable_read_node_to_class_variable_write_node(yp_parser_t *parser, yp
return node; return node;
} }
// Allocate and initialize a new ConstantPathOperatorAndWriteNode node.
static yp_constant_path_operator_and_write_node_t *
yp_constant_path_operator_and_write_node_create(yp_parser_t *parser, yp_constant_path_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_constant_path_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_path_operator_and_write_node_t);
*node = (yp_constant_path_operator_and_write_node_t) {
{
.type = YP_NODE_CONSTANT_PATH_OPERATOR_AND_WRITE_NODE,
.location = {
.start = target->base.location.start,
.end = value->location.end
}
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ConstantPathOperatorWriteNode node. // Allocate and initialize a new ConstantPathOperatorWriteNode node.
static yp_constant_path_operator_write_node_t * static yp_constant_path_operator_write_node_t *
yp_constant_path_operator_write_node_create(yp_parser_t *parser, yp_constant_path_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_constant_path_operator_write_node_create(yp_parser_t *parser, yp_constant_path_node_t *target, const yp_token_t *operator, yp_node_t *value) {
@ -1627,28 +1580,6 @@ yp_constant_path_operator_write_node_create(yp_parser_t *parser, yp_constant_pat
return node; return node;
} }
// Allocate and initialize a new ConstantPathOperatorOrWriteNode node.
static yp_constant_path_operator_or_write_node_t *
yp_constant_path_operator_or_write_node_create(yp_parser_t *parser, yp_constant_path_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_constant_path_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_path_operator_or_write_node_t);
*node = (yp_constant_path_operator_or_write_node_t) {
{
.type = YP_NODE_CONSTANT_PATH_OPERATOR_OR_WRITE_NODE,
.location = {
.start = target->base.location.start,
.end = value->location.end
}
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ConstantPathNode node. // Allocate and initialize a new ConstantPathNode node.
static yp_constant_path_node_t * static yp_constant_path_node_t *
yp_constant_path_node_create(yp_parser_t *parser, yp_node_t *parent, const yp_token_t *delimiter, yp_node_t *child) { yp_constant_path_node_create(yp_parser_t *parser, yp_node_t *parent, const yp_token_t *delimiter, yp_node_t *child) {
@ -1691,29 +1622,6 @@ yp_constant_path_write_node_create(yp_parser_t *parser, yp_constant_path_node_t
return node; return node;
} }
// Allocate and initialize a new ConstantOperatorAndWriteNode node.
static yp_constant_operator_and_write_node_t *
yp_constant_operator_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_CONSTANT_READ_NODE));
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_constant_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_operator_and_write_node_t);
*node = (yp_constant_operator_and_write_node_t) {
{
.type = YP_NODE_CONSTANT_OPERATOR_AND_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ConstantOperatorWriteNode node. // Allocate and initialize a new ConstantOperatorWriteNode node.
static yp_constant_operator_write_node_t * static yp_constant_operator_write_node_t *
yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
@ -1736,29 +1644,6 @@ yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, c
return node; return node;
} }
// Allocate and initialize a new ConstantOperatorOrWriteNode node.
static yp_constant_operator_or_write_node_t *
yp_constant_operator_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_CONSTANT_READ_NODE));
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_constant_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_operator_or_write_node_t);
*node = (yp_constant_operator_or_write_node_t) {
{
.type = YP_NODE_CONSTANT_OPERATOR_OR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ConstantReadNode node. // Allocate and initialize a new ConstantReadNode node.
static yp_constant_read_node_t * static yp_constant_read_node_t *
yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) { yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) {
@ -2193,29 +2078,6 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc
return node; return node;
} }
// Allocate and initialize a new GlobalVariableOperatorAndWriteNode node.
static yp_global_variable_operator_and_write_node_t *
yp_global_variable_operator_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_global_variable_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_operator_and_write_node_t);
*node = (yp_global_variable_operator_and_write_node_t) {
{
.type = YP_NODE_GLOBAL_VARIABLE_OPERATOR_AND_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new GlobalVariableOperatorWriteNode node. // Allocate and initialize a new GlobalVariableOperatorWriteNode node.
static yp_global_variable_operator_write_node_t * static yp_global_variable_operator_write_node_t *
yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
@ -2238,29 +2100,6 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta
return node; return node;
} }
// Allocate and initialize a new GlobalVariableOperatorOrWriteNode node.
static yp_global_variable_operator_or_write_node_t *
yp_global_variable_operator_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_global_variable_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_operator_or_write_node_t);
*node = (yp_global_variable_operator_or_write_node_t) {
{
.type = YP_NODE_GLOBAL_VARIABLE_OPERATOR_OR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate a new GlobalVariableReadNode node. // Allocate a new GlobalVariableReadNode node.
static yp_global_variable_read_node_t * static yp_global_variable_read_node_t *
yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) { yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) {
@ -2551,29 +2390,6 @@ yp_in_node_create(yp_parser_t *parser, yp_node_t *pattern, yp_statements_node_t
return node; return node;
} }
// Allocate and initialize a new InstanceVariableOperatorAndWriteNode node.
static yp_instance_variable_operator_and_write_node_t *
yp_instance_variable_operator_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_INSTANCE_VARIABLE_READ_NODE));
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_instance_variable_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_operator_and_write_node_t);
*node = (yp_instance_variable_operator_and_write_node_t) {
{
.type = YP_NODE_INSTANCE_VARIABLE_OPERATOR_AND_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new InstanceVariableOperatorWriteNode node. // Allocate and initialize a new InstanceVariableOperatorWriteNode node.
static yp_instance_variable_operator_write_node_t * static yp_instance_variable_operator_write_node_t *
yp_instance_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_instance_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
@ -2596,29 +2412,6 @@ yp_instance_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *
return node; return node;
} }
// Allocate and initialize a new InstanceVariableOperatorOrWriteNode node.
static yp_instance_variable_operator_or_write_node_t *
yp_instance_variable_operator_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_INSTANCE_VARIABLE_READ_NODE));
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_instance_variable_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_operator_or_write_node_t);
*node = (yp_instance_variable_operator_or_write_node_t) {
{
.type = YP_NODE_INSTANCE_VARIABLE_OPERATOR_OR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new InstanceVariableReadNode node. // Allocate and initialize a new InstanceVariableReadNode node.
static yp_instance_variable_read_node_t * static yp_instance_variable_read_node_t *
yp_instance_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) { yp_instance_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) {
@ -2892,30 +2685,6 @@ yp_lambda_node_create(
return node; return node;
} }
// Allocate and initialize a new LocalVariableOperatorAndWriteNode node.
static yp_local_variable_operator_and_write_node_t *
yp_local_variable_operator_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id) {
assert(YP_NODE_TYPE_P(target, YP_NODE_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_CALL_NODE));
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_local_variable_operator_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_operator_and_write_node_t);
*node = (yp_local_variable_operator_and_write_node_t) {
{
.type = YP_NODE_LOCAL_VARIABLE_OPERATOR_AND_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.constant_id = constant_id
};
return node;
}
// Allocate and initialize a new LocalVariableOperatorWriteNode node. // Allocate and initialize a new LocalVariableOperatorWriteNode node.
static yp_local_variable_operator_write_node_t * static yp_local_variable_operator_write_node_t *
yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id) { yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id) {
@ -2939,30 +2708,6 @@ yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *tar
return node; return node;
} }
// Allocate and initialize a new LocalVariableOperatorOrWriteNode node.
static yp_local_variable_operator_or_write_node_t *
yp_local_variable_operator_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id) {
assert(YP_NODE_TYPE_P(target, YP_NODE_LOCAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_CALL_NODE));
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_local_variable_operator_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_operator_or_write_node_t);
*node = (yp_local_variable_operator_or_write_node_t) {
{
.type = YP_NODE_LOCAL_VARIABLE_OPERATOR_OR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.constant_id = constant_id
};
return node;
}
// Allocate a new LocalVariableReadNode node. // Allocate a new LocalVariableReadNode node.
static yp_local_variable_read_node_t * static yp_local_variable_read_node_t *
yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name, uint32_t depth) { yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name, uint32_t depth) {
@ -3239,6 +2984,27 @@ yp_or_node_create(yp_parser_t *parser, yp_node_t *left, const yp_token_t *operat
return node; return node;
} }
// Allocate and initialize a new OrWriteNode.
static yp_or_write_node_t *
yp_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_or_write_node_t);
*node = (yp_or_write_node_t) {
{
.type = YP_NODE_OR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
},
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value
};
return node;
}
// Allocate and initialize a new ParametersNode node. // Allocate and initialize a new ParametersNode node.
static yp_parameters_node_t * static yp_parameters_node_t *
yp_parameters_node_create(yp_parser_t *parser) { yp_parameters_node_create(yp_parser_t *parser) {
@ -12452,14 +12218,15 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
case YP_NODE_NUMBERED_REFERENCE_READ_NODE: case YP_NODE_NUMBERED_REFERENCE_READ_NODE:
yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable"); yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable");
/* fallthrough */ /* fallthrough */
case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { case YP_NODE_CLASS_VARIABLE_READ_NODE:
case YP_NODE_CONSTANT_PATH_NODE:
case YP_NODE_CONSTANT_READ_NODE:
case YP_NODE_GLOBAL_VARIABLE_READ_NODE:
case YP_NODE_INSTANCE_VARIABLE_READ_NODE:
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
parser_lex(parser); parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_node_t *result = (yp_node_t *) yp_global_variable_operator_and_write_node_create(parser, node, &token, value); return (yp_node_t *) yp_and_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
} }
case YP_NODE_CALL_NODE: { case YP_NODE_CALL_NODE: {
yp_call_node_t *call_node = (yp_call_node_t *) node; yp_call_node_t *call_node = (yp_call_node_t *) node;
@ -12476,13 +12243,11 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
} }
parser_lex(parser); parser_lex(parser);
yp_node_t *target = (yp_node_t *) yp_local_variable_read_node_create(parser, &(yp_token_t) { .type = YP_TOKEN_IDENTIFIER, .start = message_loc.start, .end = message_loc.end }, 0);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_constant_id_t constant_id = yp_parser_constant_id_location(parser, message_loc.start, message_loc.end);
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_and_write_node_create(parser, node, &token, value, constant_id);
yp_node_destroy(parser, node); yp_node_destroy(parser, node);
return result; return (yp_node_t *) yp_and_write_node_create(parser, target, &token, value);
} }
parser_lex(parser); parser_lex(parser);
@ -12493,49 +12258,6 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
return (yp_node_t *) yp_call_operator_and_write_node_create(parser, (yp_call_node_t *) node, &token, value); return (yp_node_t *) yp_call_operator_and_write_node_create(parser, (yp_call_node_t *) node, &token, value);
} }
case YP_NODE_CLASS_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_node_t *result = (yp_node_t *) yp_class_variable_operator_and_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_CONSTANT_PATH_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
return (yp_node_t *) yp_constant_path_operator_and_write_node_create(parser, (yp_constant_path_node_t *) node, &token, value);
}
case YP_NODE_CONSTANT_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_node_t *result = (yp_node_t *) yp_constant_operator_and_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_node_t *result = (yp_node_t *) yp_instance_variable_operator_and_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_constant_id_t constant_id = ((yp_local_variable_read_node_t *) node)->constant_id;
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_and_write_node_create(parser, node, &token, value, constant_id);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_MULTI_WRITE_NODE: { case YP_NODE_MULTI_WRITE_NODE: {
parser_lex(parser); parser_lex(parser);
yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Cannot use `&&=' on a multi-write."); yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Cannot use `&&=' on a multi-write.");
@ -12557,14 +12279,16 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
case YP_NODE_NUMBERED_REFERENCE_READ_NODE: case YP_NODE_NUMBERED_REFERENCE_READ_NODE:
yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable"); yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable");
/* fallthrough */ /* fallthrough */
case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { case YP_NODE_CLASS_VARIABLE_READ_NODE:
case YP_NODE_CONSTANT_PATH_NODE:
case YP_NODE_CONSTANT_READ_NODE:
case YP_NODE_GLOBAL_VARIABLE_READ_NODE:
case YP_NODE_INSTANCE_VARIABLE_READ_NODE:
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
parser_lex(parser); parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
yp_node_t *result = (yp_node_t *) yp_global_variable_operator_or_write_node_create(parser, node, &token, value); return (yp_node_t *) yp_or_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
} }
case YP_NODE_CALL_NODE: { case YP_NODE_CALL_NODE: {
yp_call_node_t *call_node = (yp_call_node_t *) node; yp_call_node_t *call_node = (yp_call_node_t *) node;
@ -12581,13 +12305,11 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
} }
parser_lex(parser); parser_lex(parser);
yp_node_t *target = (yp_node_t *) yp_local_variable_read_node_create(parser, &(yp_token_t) { .type = YP_TOKEN_IDENTIFIER, .start = message_loc.start, .end = message_loc.end }, 0);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
yp_constant_id_t constant_id = yp_parser_constant_id_location(parser, message_loc.start, message_loc.end);
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_or_write_node_create(parser, node, &token, value, constant_id);
yp_node_destroy(parser, node); yp_node_destroy(parser, node);
return result; return (yp_node_t *) yp_or_write_node_create(parser, target, &token, value);
} }
parser_lex(parser); parser_lex(parser);
@ -12598,49 +12320,6 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
return (yp_node_t *) yp_call_operator_or_write_node_create(parser, (yp_call_node_t *) node, &token, value); return (yp_node_t *) yp_call_operator_or_write_node_create(parser, (yp_call_node_t *) node, &token, value);
} }
case YP_NODE_CLASS_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
yp_node_t *result = (yp_node_t *) yp_class_variable_operator_or_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_CONSTANT_PATH_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
return (yp_node_t *) yp_constant_path_operator_or_write_node_create(parser, (yp_constant_path_node_t *) node, &token, value);
}
case YP_NODE_CONSTANT_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
yp_node_t *result = (yp_node_t *) yp_constant_operator_or_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
yp_node_t *result = (yp_node_t *) yp_instance_variable_operator_or_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
yp_constant_id_t constant_id = ((yp_local_variable_read_node_t *) node)->constant_id;
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_or_write_node_create(parser, node, &token, value, constant_id);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_MULTI_WRITE_NODE: { case YP_NODE_MULTI_WRITE_NODE: {
parser_lex(parser); parser_lex(parser);
yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Cannot use `||=' on a multi-write."); yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Cannot use `||=' on a multi-write.");