[ruby/yarp] Split up AndWriteNode, OrWriteNode, OperatorWriteNode

https://github.com/ruby/yarp/commit/6d3b3b5776
This commit is contained in:
Kevin Newton 2023-08-25 10:49:00 -04:00 committed by git
parent 649aba28f4
commit a38ca45b65
29 changed files with 1177 additions and 457 deletions

View File

@ -17,16 +17,6 @@ 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
@ -209,6 +199,18 @@ module YARP
assert_location(ClassNode, "class Foo < Bar end") assert_location(ClassNode, "class Foo < Bar end")
end end
def test_ClassVariableAndWriteNode
assert_location(ClassVariableAndWriteNode, "@@foo &&= bar")
end
def test_ClassVariableOperatorWriteNode
assert_location(ClassVariableOperatorWriteNode, "@@foo += bar")
end
def test_ClassVariableOrWriteNode
assert_location(ClassVariableOrWriteNode, "@@foo ||= bar")
end
def test_ClassVariableReadNode def test_ClassVariableReadNode
assert_location(ClassVariableReadNode, "@@foo") assert_location(ClassVariableReadNode, "@@foo")
end end
@ -217,18 +219,42 @@ module YARP
assert_location(ClassVariableWriteNode, "@@foo = bar") assert_location(ClassVariableWriteNode, "@@foo = bar")
end end
def test_ConstantPathAndWriteNode
assert_location(ConstantPathAndWriteNode, "Parent::Child &&= bar")
end
def test_ConstantPathNode def test_ConstantPathNode
assert_location(ConstantPathNode, "Foo::Bar") assert_location(ConstantPathNode, "Foo::Bar")
assert_location(ConstantPathNode, "::Foo") assert_location(ConstantPathNode, "::Foo")
assert_location(ConstantPathNode, "::Foo::Bar") assert_location(ConstantPathNode, "::Foo::Bar")
end end
def test_ConstantPathOperatorWriteNode
assert_location(ConstantPathOperatorWriteNode, "Parent::Child += bar")
end
def test_ConstantPathOrWriteNode
assert_location(ConstantPathOrWriteNode, "Parent::Child ||= bar")
end
def test_ConstantPathWriteNode def test_ConstantPathWriteNode
assert_location(ConstantPathWriteNode, "Foo::Bar = baz") assert_location(ConstantPathWriteNode, "Foo::Bar = baz")
assert_location(ConstantPathWriteNode, "::Foo = bar") assert_location(ConstantPathWriteNode, "::Foo = bar")
assert_location(ConstantPathWriteNode, "::Foo::Bar = baz") assert_location(ConstantPathWriteNode, "::Foo::Bar = baz")
end end
def test_ConstantAndWriteNode
assert_location(ConstantAndWriteNode, "Foo &&= bar")
end
def test_ConstantOperatorWriteNode
assert_location(ConstantOperatorWriteNode, "Foo += bar")
end
def test_ConstantOrWriteNode
assert_location(ConstantOrWriteNode, "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)
@ -302,6 +328,18 @@ module YARP
assert_location(ForwardingSuperNode, "super {}") assert_location(ForwardingSuperNode, "super {}")
end end
def test_GlobalVariableAndWriteNode
assert_location(GlobalVariableAndWriteNode, "$foo &&= bar")
end
def test_GlobalVariableOperatorWriteNode
assert_location(GlobalVariableOperatorWriteNode, "$foo += bar")
end
def test_GlobalVariableOrWriteNode
assert_location(GlobalVariableOrWriteNode, "$foo ||= bar")
end
def test_GlobalVariableReadNode def test_GlobalVariableReadNode
assert_location(GlobalVariableReadNode, "$foo") assert_location(GlobalVariableReadNode, "$foo")
end end
@ -336,6 +374,18 @@ module YARP
end end
end end
def test_InstanceVariableAndWriteNode
assert_location(InstanceVariableAndWriteNode, "@foo &&= bar")
end
def test_InstanceVariableOperatorWriteNode
assert_location(InstanceVariableOperatorWriteNode, "@foo += bar")
end
def test_InstanceVariableOrWriteNode
assert_location(InstanceVariableOrWriteNode, "@foo ||= bar")
end
def test_InstanceVariableReadNode def test_InstanceVariableReadNode
assert_location(InstanceVariableReadNode, "@foo") assert_location(InstanceVariableReadNode, "@foo")
end end
@ -402,6 +452,21 @@ module YARP
assert_location(LambdaNode, "-> do foo end") assert_location(LambdaNode, "-> do foo end")
end end
def test_LocalVariableAndWriteNode
assert_location(LocalVariableAndWriteNode, "foo &&= bar")
assert_location(LocalVariableAndWriteNode, "foo = 1; foo &&= bar", 9...20)
end
def test_LocalVariableOperatorWriteNode
assert_location(LocalVariableOperatorWriteNode, "foo += bar")
assert_location(LocalVariableOperatorWriteNode, "foo = 1; foo += bar", 9...19)
end
def test_LocalVariableOrWriteNode
assert_location(LocalVariableOrWriteNode, "foo ||= bar")
assert_location(LocalVariableOrWriteNode, "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)
end end
@ -445,16 +510,6 @@ module YARP
assert_location(NumberedReferenceReadNode, "$1") assert_location(NumberedReferenceReadNode, "$1")
end end
def test_OperatorWriteNode
assert_location(OperatorWriteNode, "@@foo += bar")
assert_location(OperatorWriteNode, "Parent::Child += bar")
assert_location(OperatorWriteNode, "Foo += bar")
assert_location(OperatorWriteNode, "$foo += bar")
assert_location(OperatorWriteNode, "@foo += bar")
assert_location(OperatorWriteNode, "foo += bar")
assert_location(OperatorWriteNode, "foo = 1; foo += bar", 9...19)
end
def test_OptionalParameterNode def test_OptionalParameterNode
assert_location(OptionalParameterNode, "def foo(bar = nil); end", 8...17) do |node| assert_location(OptionalParameterNode, "def foo(bar = nil); end", 8...17) do |node|
node.parameters.optionals.first node.parameters.optionals.first
@ -466,16 +521,6 @@ 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

@ -88,11 +88,13 @@ ProgramNode(0...402)(
(61...62) (61...62)
), ),
StatementsNode(63...72)( StatementsNode(63...72)(
[OperatorWriteNode(63...72)( [LocalVariableOperatorWriteNode(63...72)(
LocalVariableWriteNode(63...67)(:memo, 0, nil, (63...67), nil), (63...67),
(68...70), (68...70),
LocalVariableReadNode(71...72)(:x, 0),
:memo,
:+, :+,
LocalVariableReadNode(71...72)(:x, 0) 0
)] )]
), ),
(51...52), (51...52),

View File

@ -1,21 +1,27 @@
ProgramNode(0...24)( ProgramNode(0...24)(
[:a], [:a],
StatementsNode(0...24)( StatementsNode(0...24)(
[AndWriteNode(0...7)( [LocalVariableAndWriteNode(0...7)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(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"),
(2...5) :a,
0
), ),
OperatorWriteNode(9...15)( LocalVariableOperatorWriteNode(9...15)(
LocalVariableWriteNode(9...10)(:a, 0, nil, (9...10), nil), (9...10),
(11...13), (11...13),
CallNode(14...15)(nil, nil, (14...15), nil, nil, nil, nil, 2, "b"),
:a,
:+, :+,
CallNode(14...15)(nil, nil, (14...15), nil, nil, nil, nil, 2, "b") 0
), ),
OrWriteNode(17...24)( LocalVariableOrWriteNode(17...24)(
LocalVariableWriteNode(17...18)(:a, 0, nil, (17...18), nil), (17...18),
(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"),
(19...22) :a,
0
)] )]
) )
) )

View File

@ -8,11 +8,13 @@ ProgramNode(0...78)(
), ),
DefinedNode(27...43)( DefinedNode(27...43)(
(35...36), (35...36),
OperatorWriteNode(36...42)( LocalVariableOperatorWriteNode(36...42)(
LocalVariableWriteNode(36...37)(:x, 0, nil, (36...37), nil), (36...37),
(38...40), (38...40),
IntegerNode(41...42)(),
:x,
:%, :%,
IntegerNode(41...42)() 0
), ),
(42...43), (42...43),
(27...35) (27...35)

View File

@ -1,14 +1,16 @@
ProgramNode(0...18)( ProgramNode(0...18)(
[:a], [:a],
StatementsNode(0...18)( StatementsNode(0...18)(
[OrWriteNode(0...18)( [LocalVariableOrWriteNode(0...18)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(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)()
), ),
(2...5) :a,
0
)] )]
) )
) )

View File

@ -1,18 +1,14 @@
ProgramNode(0...12)( ProgramNode(0...12)(
[], [],
StatementsNode(0...12)( StatementsNode(0...12)(
[OrWriteNode(0...12)( [ConstantPathOrWriteNode(0...12)(
ConstantPathWriteNode(0...6)( 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)
),
nil,
nil
), ),
IntegerNode(11...12)(), (7...10),
(7...10) IntegerNode(11...12)()
)] )]
) )
) )

View File

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

View File

@ -1,15 +1,11 @@
ProgramNode(0...8)( ProgramNode(0...8)(
[], [],
StatementsNode(0...8)( StatementsNode(0...8)(
[OperatorWriteNode(0...8)( [ConstantPathOperatorWriteNode(0...8)(
ConstantPathWriteNode(0...3)( ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
nil,
nil
),
(4...6), (4...6),
:&, IntegerNode(7...8)(),
IntegerNode(7...8)() :&
)] )]
) )
) )

View File

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

View File

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

View File

@ -9,18 +9,13 @@ ProgramNode(0...15)(
ArgumentsNode(2...15)( ArgumentsNode(2...15)(
[ParenthesesNode(2...15)( [ParenthesesNode(2...15)(
StatementsNode(3...14)( StatementsNode(3...14)(
[OperatorWriteNode(3...14)( [ConstantPathOperatorWriteNode(3...14)(
ConstantPathWriteNode(3...7)( ConstantPathNode(3...7)(
ConstantPathNode(3...7)( ConstantReadNode(3...4)(),
ConstantReadNode(3...4)(), ConstantReadNode(6...7)(),
ConstantReadNode(6...7)(), (4...6)
(4...6)
),
nil,
nil
), ),
(8...10), (8...10),
:*,
CallNode(11...14)( CallNode(11...14)(
nil, nil,
nil, nil,
@ -43,7 +38,8 @@ ProgramNode(0...15)(
nil, nil,
0, 0,
"d" "d"
) ),
:*
)] )]
), ),
(2...3), (2...3),

View File

@ -1,8 +1,9 @@
ProgramNode(0...11)( ProgramNode(0...11)(
[:a], [:a],
StatementsNode(0...11)( StatementsNode(0...11)(
[OrWriteNode(0...11)( [LocalVariableOrWriteNode(0...11)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(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),
@ -14,7 +15,8 @@ ProgramNode(0...11)(
0, 0,
"c" "c"
), ),
(2...5) :a,
0
)] )]
) )
) )

View File

@ -1,18 +1,13 @@
ProgramNode(0...11)( ProgramNode(0...11)(
[], [],
StatementsNode(0...11)( StatementsNode(0...11)(
[OperatorWriteNode(0...11)( [ConstantPathOperatorWriteNode(0...11)(
ConstantPathWriteNode(0...4)( ConstantPathNode(0...4)(
ConstantPathNode(0...4)( ConstantReadNode(0...1)(),
ConstantReadNode(0...1)(), ConstantReadNode(3...4)(),
ConstantReadNode(3...4)(), (1...3)
(1...3)
),
nil,
nil
), ),
(5...7), (5...7),
:*,
CallNode(8...11)( CallNode(8...11)(
nil, nil,
nil, nil,
@ -25,7 +20,8 @@ ProgramNode(0...11)(
nil, nil,
0, 0,
"c" "c"
) ),
:*
)] )]
) )
) )

View File

@ -25,11 +25,13 @@ ProgramNode(0...40)(
0, 0,
"p" "p"
), ),
OperatorWriteNode(18...24)( LocalVariableOperatorWriteNode(18...24)(
LocalVariableWriteNode(18...19)(:y, 0, nil, (18...19), nil), (18...19),
(20...22), (20...22),
IntegerNode(23...24)(),
:y,
:*, :*,
IntegerNode(23...24)() 0
), ),
ReturnNode(27...35)( ReturnNode(27...35)(
(27...33), (27...33),

View File

@ -1,11 +1,13 @@
ProgramNode(6...34)( ProgramNode(6...34)(
[:foo], [:foo],
StatementsNode(6...34)( StatementsNode(6...34)(
[OperatorWriteNode(6...24)( [LocalVariableOperatorWriteNode(6...24)(
LocalVariableWriteNode(6...9)(:foo, 0, nil, (6...9), nil), (6...9),
(10...12), (10...12),
CallNode(21...24)(nil, nil, (21...24), nil, nil, nil, nil, 2, "bar"),
:foo,
:+, :+,
CallNode(21...24)(nil, nil, (21...24), nil, nil, nil, nil, 2, "bar") 0
), ),
CallNode(31...34)(nil, nil, (31...34), nil, nil, nil, nil, 2, "baz")] CallNode(31...34)(nil, nil, (31...34), nil, nil, nil, nil, 2, "baz")]
) )

View File

@ -610,10 +610,10 @@ ProgramNode(0...704)(
), ),
(543...546) (543...546)
), ),
OrWriteNode(551...561)( InstanceVariableOrWriteNode(551...561)(
InstanceVariableWriteNode(551...553)((551...553), nil, nil), (551...553),
StringNode(558...561)((558...560), (560...560), (560...561), ""), (554...557),
(554...557) StringNode(558...561)((558...560), (560...560), (560...561), "")
), ),
LocalVariableWriteNode(562...576)( LocalVariableWriteNode(562...576)(
:x, :x,
@ -703,16 +703,16 @@ ProgramNode(0...704)(
), ),
(665...668) (665...668)
), ),
OrWriteNode(687...704)( InstanceVariableOrWriteNode(687...704)(
InstanceVariableWriteNode(687...689)((687...689), nil, nil), (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

@ -1,53 +1,69 @@
ProgramNode(0...233)( ProgramNode(0...233)(
[:a, :h], [:a, :h],
StatementsNode(0...233)( StatementsNode(0...233)(
[OperatorWriteNode(0...6)( [LocalVariableOperatorWriteNode(0...6)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(2...4), (2...4),
IntegerNode(5...6)(),
:a,
:+, :+,
IntegerNode(5...6)() 0
), ),
OperatorWriteNode(7...13)( LocalVariableOperatorWriteNode(7...13)(
LocalVariableWriteNode(7...8)(:a, 0, nil, (7...8), nil), (7...8),
(9...11), (9...11),
IntegerNode(12...13)(),
:a,
:-, :-,
IntegerNode(12...13)() 0
), ),
OperatorWriteNode(14...21)( LocalVariableOperatorWriteNode(14...21)(
LocalVariableWriteNode(14...15)(:a, 0, nil, (14...15), nil), (14...15),
(16...19), (16...19),
IntegerNode(20...21)(),
:a,
:**, :**,
IntegerNode(20...21)() 0
), ),
OperatorWriteNode(22...28)( LocalVariableOperatorWriteNode(22...28)(
LocalVariableWriteNode(22...23)(:a, 0, nil, (22...23), nil), (22...23),
(24...26), (24...26),
IntegerNode(27...28)(),
:a,
:*, :*,
IntegerNode(27...28)() 0
), ),
OperatorWriteNode(29...35)( LocalVariableOperatorWriteNode(29...35)(
LocalVariableWriteNode(29...30)(:a, 0, nil, (29...30), nil), (29...30),
(31...33), (31...33),
IntegerNode(34...35)(),
:a,
:/, :/,
IntegerNode(34...35)() 0
), ),
AndWriteNode(36...43)( LocalVariableAndWriteNode(36...43)(
LocalVariableWriteNode(36...37)(:a, 0, nil, (36...37), nil), (36...37),
(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"),
(38...41) :a,
0
), ),
OrWriteNode(44...51)( LocalVariableOrWriteNode(44...51)(
LocalVariableWriteNode(44...45)(:a, 0, nil, (44...45), nil), (44...45),
(46...49),
IntegerNode(50...51)(), IntegerNode(50...51)(),
(46...49) :a,
0
), ),
CallNode(52...65)( CallNode(52...65)(
ParenthesesNode(52...61)( ParenthesesNode(52...61)(
StatementsNode(53...60)( StatementsNode(53...60)(
[OrWriteNode(53...60)( [LocalVariableOrWriteNode(53...60)(
LocalVariableWriteNode(53...54)(:a, 0, nil, (53...54), nil), (53...54),
(55...58),
IntegerNode(59...60)(), IntegerNode(59...60)(),
(55...58) :a,
0
)] )]
), ),
(52...53), (52...53),
@ -65,10 +81,12 @@ ProgramNode(0...233)(
CallNode(66...83)( CallNode(66...83)(
ParenthesesNode(66...76)( ParenthesesNode(66...76)(
StatementsNode(67...75)( StatementsNode(67...75)(
[OrWriteNode(67...75)( [LocalVariableOrWriteNode(67...75)(
LocalVariableWriteNode(67...68)(:h, 0, nil, (67...68), nil), (67...68),
(69...72),
HashNode(73...75)((73...74), [], (74...75)), HashNode(73...75)((73...74), [], (74...75)),
(69...72) :h,
0
)] )]
), ),
(66...67), (66...67),

View File

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

View File

@ -1,53 +1,41 @@
ProgramNode(0...77)( ProgramNode(0...77)(
[], [],
StatementsNode(0...77)( StatementsNode(0...77)(
[OperatorWriteNode(0...8)( [ConstantPathOperatorWriteNode(0...8)(
ConstantPathWriteNode(0...3)( ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
nil,
nil
),
(4...6), (4...6),
:+, IntegerNode(7...8)(),
IntegerNode(7...8)() :+
), ),
OperatorWriteNode(10...16)( ConstantOperatorWriteNode(10...16)(
ConstantWriteNode(10...11)((10...11), nil, nil), (10...11),
(12...14), (12...14),
:+, IntegerNode(15...16)(),
IntegerNode(15...16)() :+
), ),
OperatorWriteNode(18...27)( ConstantPathOperatorWriteNode(18...27)(
ConstantPathWriteNode(18...22)( ConstantPathNode(18...22)(
ConstantPathNode(18...22)( ConstantReadNode(18...19)(),
ConstantReadNode(18...19)(), ConstantReadNode(21...22)(),
ConstantReadNode(21...22)(), (19...21)
(19...21)
),
nil,
nil
), ),
(23...25), (23...25),
:+, IntegerNode(26...27)(),
IntegerNode(26...27)() :+
), ),
DefNode(29...50)( DefNode(29...50)(
(33...34), (33...34),
nil, nil,
nil, nil,
StatementsNode(36...45)( StatementsNode(36...45)(
[OrWriteNode(36...45)( [ConstantPathOrWriteNode(36...45)(
ConstantPathWriteNode(36...39)( ConstantPathNode(36...39)(
ConstantPathNode(36...39)(
nil,
ConstantReadNode(38...39)(),
(36...38)
),
nil, nil,
nil ConstantReadNode(38...39)(),
(36...38)
), ),
IntegerNode(44...45)(), (40...43),
(40...43) IntegerNode(44...45)()
)] )]
), ),
[], [],
@ -63,18 +51,14 @@ ProgramNode(0...77)(
nil, nil,
nil, nil,
StatementsNode(59...72)( StatementsNode(59...72)(
[OrWriteNode(59...72)( [ConstantPathOrWriteNode(59...72)(
ConstantPathWriteNode(59...66)( ConstantPathNode(59...66)(
ConstantPathNode(59...66)( SelfNode(59...63)(),
SelfNode(59...63)(), ConstantReadNode(65...66)(),
ConstantReadNode(65...66)(), (63...65)
(63...65)
),
nil,
nil
), ),
IntegerNode(71...72)(), (67...70),
(67...70) IntegerNode(71...72)()
)] )]
), ),
[], [],

View File

@ -77,28 +77,13 @@ ProgramNode(0...64)(
), ),
:+ :+
), ),
OperatorWriteNode(32...47)( ConstantPathOperatorWriteNode(32...47)(
ConstantPathWriteNode(32...38)( ConstantPathNode(32...38)(
ConstantPathNode(32...38)( CallNode(32...35)(nil, nil, (32...35), nil, nil, nil, nil, 2, "foo"),
CallNode(32...35)( ConstantReadNode(37...38)(),
nil, (35...37)
nil,
(32...35),
nil,
nil,
nil,
nil,
2,
"foo"
),
ConstantReadNode(37...38)(),
(35...37)
),
nil,
nil
), ),
(39...41), (39...41),
:+,
CallNode(42...47)( CallNode(42...47)(
nil, nil,
nil, nil,
@ -121,7 +106,8 @@ ProgramNode(0...64)(
nil, nil,
0, 0,
"m" "m"
) ),
:+
), ),
CallOperatorWriteNode(49...64)( CallOperatorWriteNode(49...64)(
CallNode(49...55)( CallNode(49...55)(

View File

@ -1,15 +1,17 @@
ProgramNode(0...22)( ProgramNode(0...22)(
[:foo], [:foo],
StatementsNode(0...22)( StatementsNode(0...22)(
[OperatorWriteNode(0...22)( [LocalVariableOperatorWriteNode(0...22)(
LocalVariableWriteNode(0...3)(:foo, 0, nil, (0...3), nil), (0...3),
(4...6), (4...6),
:+,
RescueModifierNode(7...22)( RescueModifierNode(7...22)(
CallNode(7...11)(nil, nil, (7...11), nil, nil, nil, nil, 2, "meth"), CallNode(7...11)(nil, nil, (7...11), nil, nil, nil, nil, 2, "meth"),
(12...18), (12...18),
CallNode(19...22)(nil, nil, (19...22), nil, nil, nil, nil, 2, "bar") CallNode(19...22)(nil, nil, (19...22), nil, nil, nil, nil, 2, "bar")
) ),
:foo,
:+,
0
)] )]
) )
) )

View File

@ -1,10 +1,9 @@
ProgramNode(0...437)( ProgramNode(0...437)(
[:foo], [:foo],
StatementsNode(0...437)( StatementsNode(0...437)(
[OperatorWriteNode(0...27)( [LocalVariableOperatorWriteNode(0...27)(
LocalVariableWriteNode(0...3)(:foo, 0, nil, (0...3), nil), (0...3),
(4...6), (4...6),
:+,
CallNode(7...27)( CallNode(7...27)(
nil, nil,
nil, nil,
@ -31,12 +30,14 @@ ProgramNode(0...437)(
nil, nil,
0, 0,
"raise" "raise"
) ),
), :foo,
OperatorWriteNode(29...57)(
LocalVariableWriteNode(29...32)(:foo, 0, nil, (29...32), nil),
(33...35),
:+, :+,
0
),
LocalVariableOperatorWriteNode(29...57)(
(29...32),
(33...35),
RescueModifierNode(36...57)( RescueModifierNode(36...57)(
CallNode(36...46)( CallNode(36...46)(
nil, nil,
@ -63,7 +64,10 @@ ProgramNode(0...437)(
), ),
(47...53), (47...53),
NilNode(54...57)() NilNode(54...57)()
) ),
:foo,
:+,
0
), ),
LocalVariableWriteNode(59...85)( LocalVariableWriteNode(59...85)(
:foo, :foo,
@ -299,16 +303,13 @@ ProgramNode(0...437)(
), ),
:+ :+
), ),
OrWriteNode(242...273)( ConstantPathOrWriteNode(242...273)(
ConstantPathWriteNode(242...248)( 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)
),
nil,
nil
), ),
(249...252),
CallNode(253...273)( CallNode(253...273)(
nil, nil,
nil, nil,
@ -335,19 +336,15 @@ ProgramNode(0...437)(
nil, nil,
0, 0,
"raise" "raise"
), )
(249...252)
), ),
OrWriteNode(275...307)( ConstantPathOrWriteNode(275...307)(
ConstantPathWriteNode(275...281)( 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)
),
nil,
nil
), ),
(282...285),
RescueModifierNode(286...307)( RescueModifierNode(286...307)(
CallNode(286...296)( CallNode(286...296)(
nil, nil,
@ -374,8 +371,7 @@ 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,14 +1,12 @@
ProgramNode(0...74)( ProgramNode(0...74)(
[:a, :b], [:a, :b],
StatementsNode(0...74)( StatementsNode(0...74)(
[OperatorWriteNode(0...18)( [LocalVariableOperatorWriteNode(0...18)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(2...4), (2...4),
:+, LocalVariableOperatorWriteNode(5...18)(
OperatorWriteNode(5...18)( (5...6),
LocalVariableWriteNode(5...6)(:b, 0, nil, (5...6), nil),
(7...9), (7...9),
:+,
CallNode(10...18)( CallNode(10...18)(
nil, nil,
nil, nil,
@ -21,13 +19,18 @@ ProgramNode(0...74)(
nil, nil,
0, 0,
"raise" "raise"
) ),
) :b,
), :+,
OperatorWriteNode(20...37)( 0
LocalVariableWriteNode(20...21)(:a, 0, nil, (20...21), nil), ),
(22...24), :a,
:+, :+,
0
),
LocalVariableOperatorWriteNode(20...37)(
(20...21),
(22...24),
LocalVariableWriteNode(25...37)( LocalVariableWriteNode(25...37)(
:b, :b,
0, 0,
@ -46,15 +49,17 @@ ProgramNode(0...74)(
), ),
(25...26), (25...26),
(27...28) (27...28)
) ),
:a,
:+,
0
), ),
LocalVariableWriteNode(39...56)( LocalVariableWriteNode(39...56)(
:a, :a,
0, 0,
OperatorWriteNode(43...56)( LocalVariableOperatorWriteNode(43...56)(
LocalVariableWriteNode(43...44)(:b, 0, nil, (43...44), nil), (43...44),
(45...47), (45...47),
:+,
CallNode(48...56)( CallNode(48...56)(
nil, nil,
nil, nil,
@ -67,7 +72,10 @@ ProgramNode(0...74)(
nil, nil,
0, 0,
"raise" "raise"
) ),
:b,
:+,
0
), ),
(39...40), (39...40),
(41...42) (41...42)

View File

@ -1,10 +1,12 @@
ProgramNode(0...7)( ProgramNode(0...7)(
[:a], [:a],
StatementsNode(0...7)( StatementsNode(0...7)(
[AndWriteNode(0...7)( [LocalVariableAndWriteNode(0...7)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(2...5),
IntegerNode(6...7)(), IntegerNode(6...7)(),
(2...5) :a,
0
)] )]
) )
) )

View File

@ -1,34 +1,36 @@
ProgramNode(0...53)( ProgramNode(0...53)(
[:a], [:a],
StatementsNode(0...53)( StatementsNode(0...53)(
[OperatorWriteNode(0...11)( [ClassVariableOperatorWriteNode(0...11)(
ClassVariableWriteNode(0...5)((0...5), nil, nil), (0...5),
(6...8), (6...8),
:|, IntegerNode(9...11)(),
IntegerNode(9...11)() :|
), ),
OperatorWriteNode(13...20)( InstanceVariableOperatorWriteNode(13...20)(
InstanceVariableWriteNode(13...15)((13...15), nil, nil), (13...15),
(16...18), (16...18),
:|, IntegerNode(19...20)(),
IntegerNode(19...20)() :|
), ),
OperatorWriteNode(22...28)( LocalVariableOperatorWriteNode(22...28)(
LocalVariableWriteNode(22...23)(:a, 0, nil, (22...23), nil), (22...23),
(24...26), (24...26),
IntegerNode(27...28)(),
:a,
:+, :+,
IntegerNode(27...28)() 0
), ),
DefNode(30...53)( DefNode(30...53)(
(34...35), (34...35),
nil, nil,
nil, nil,
StatementsNode(37...48)( StatementsNode(37...48)(
[OperatorWriteNode(37...48)( [ClassVariableOperatorWriteNode(37...48)(
ClassVariableWriteNode(37...42)((37...42), nil, nil), (37...42),
(43...45), (43...45),
:|, IntegerNode(46...48)(),
IntegerNode(46...48)() :|
)] )]
), ),
[], [],

View File

@ -1,10 +1,9 @@
ProgramNode(0...12)( ProgramNode(0...12)(
[:foo], [:foo],
StatementsNode(0...12)( StatementsNode(0...12)(
[OperatorWriteNode(0...12)( [LocalVariableOperatorWriteNode(0...12)(
LocalVariableWriteNode(0...3)(:foo, 0, nil, (0...3), nil), (0...3),
(4...6), (4...6),
:+,
CallNode(7...12)( CallNode(7...12)(
nil, nil,
nil, nil,
@ -15,7 +14,10 @@ ProgramNode(0...12)(
nil, nil,
0, 0,
"m" "m"
) ),
:foo,
:+,
0
)] )]
) )
) )

View File

@ -1,10 +1,12 @@
ProgramNode(0...7)( ProgramNode(0...7)(
[:a], [:a],
StatementsNode(0...7)( StatementsNode(0...7)(
[OrWriteNode(0...7)( [LocalVariableOrWriteNode(0...7)(
LocalVariableWriteNode(0...1)(:a, 0, nil, (0...1), nil), (0...1),
(2...5),
IntegerNode(6...7)(), IntegerNode(6...7)(),
(2...5) :a,
0
)] )]
) )
) )

View File

@ -399,19 +399,6 @@ 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
@ -738,6 +725,47 @@ nodes:
class Foo end class Foo end
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
- name: ClassVariableAndWriteNode
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
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a class variable using an operator that isn't `=`.
@@target += value
^^^^^^^^^^^^^^^^^
- name: ClassVariableOrWriteNode
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: ClassVariableReadNode - name: ClassVariableReadNode
comment: | comment: |
Represents referencing a class variable. Represents referencing a class variable.
@ -757,6 +785,61 @@ nodes:
@@foo = 1 @@foo = 1
^^^^^^^^^ ^^^^^^^^^
- name: ConstantAndWriteNode
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
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a constant using an operator that isn't `=`.
Target += value
^^^^^^^^^^^^^^^
- name: ConstantOrWriteNode
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: ConstantPathAndWriteNode
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: ConstantPathNode - name: ConstantPathNode
child_nodes: child_nodes:
- name: parent - name: parent
@ -770,6 +853,36 @@ nodes:
Foo::Bar Foo::Bar
^^^^^^^^ ^^^^^^^^
- name: ConstantPathOperatorWriteNode
child_nodes:
- name: target
type: node
kind: ConstantPathNode
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a constant path using an operator that isn't `=`.
Parent::Child += value
^^^^^^^^^^^^^^^^^^^^^^
- name: ConstantPathOrWriteNode
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: ConstantPathWriteNode - name: ConstantPathWriteNode
child_nodes: child_nodes:
- name: target - name: target
@ -1012,6 +1125,47 @@ nodes:
super super
^^^^^ ^^^^^
- name: GlobalVariableAndWriteNode
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
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a global variable using an operator that isn't `=`.
$target += value
^^^^^^^^^^^^^^^^
- name: GlobalVariableOrWriteNode
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: GlobalVariableReadNode - name: GlobalVariableReadNode
comment: | comment: |
Represents referencing a global variable. Represents referencing a global variable.
@ -1111,6 +1265,47 @@ nodes:
case a; in b then c end case a; in b then c end
^^^^^^^^^^^ ^^^^^^^^^^^
- name: InstanceVariableAndWriteNode
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
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to an instance variable using an operator that isn't `=`.
@target += value
^^^^^^^^^^^^^^^^
- name: InstanceVariableOrWriteNode
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: InstanceVariableReadNode - name: InstanceVariableReadNode
comment: | comment: |
Represents referencing an instance variable. Represents referencing an instance variable.
@ -1248,6 +1443,59 @@ nodes:
->(value) { value * 2 } ->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
- name: LocalVariableAndWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: constant_id
type: constant
- name: depth
type: uint32
comment: |
Represents the use of the `&&=` operator for assignment to a local variable.
target &&= value
^^^^^^^^^^^^^^^^
- name: LocalVariableOperatorWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: constant_id
type: constant
- name: operator_id
type: constant
- name: depth
type: uint32
comment: |
Represents assigning to a local variable using an operator that isn't `=`.
target += value
^^^^^^^^^^^^^^^
- name: LocalVariableOrWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: constant_id
type: constant
- name: depth
type: uint32
comment: |
Represents the use of the `||=` operator for assignment to a local variable.
target ||= value
^^^^^^^^^^^^^^^^
- name: LocalVariableReadNode - name: LocalVariableReadNode
child_nodes: child_nodes:
- name: constant_id - name: constant_id
@ -1380,21 +1628,6 @@ nodes:
$1 $1
^^ ^^
- name: OperatorWriteNode
child_nodes:
- name: target
type: node
- name: operator_loc
type: location
- name: operator
type: constant
- name: value
type: node
comment: |
Represents the use of an operator on a write.
target += value
^^^^^^^^^^^^^^^
- name: OptionalParameterNode - name: OptionalParameterNode
child_nodes: child_nodes:
- name: constant_id - name: constant_id
@ -1424,19 +1657,6 @@ 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

@ -725,27 +725,6 @@ 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) {
@ -1575,6 +1554,74 @@ 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 ClassVariableAndWriteNode node.
static yp_class_variable_and_write_node_t *
yp_class_variable_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_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_class_variable_and_write_node_t);
*node = (yp_class_variable_and_write_node_t) {
{
.type = YP_NODE_CLASS_VARIABLE_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.
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_t *node = YP_ALLOC_NODE(parser, yp_class_variable_operator_write_node_t);
*node = (yp_class_variable_operator_write_node_t) {
{
.type = YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new ClassVariableOrWriteNode node.
static yp_class_variable_or_write_node_t *
yp_class_variable_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_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_class_variable_or_write_node_t);
*node = (yp_class_variable_or_write_node_t) {
{
.type = YP_NODE_CLASS_VARIABLE_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) {
@ -1605,6 +1652,72 @@ yp_class_variable_read_node_to_class_variable_write_node(yp_parser_t *parser, yp
return node; return node;
} }
// Allocate and initialize a new ConstantPathAndWriteNode node.
static yp_constant_path_and_write_node_t *
yp_constant_path_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_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_path_and_write_node_t);
*node = (yp_constant_path_and_write_node_t) {
{
.type = YP_NODE_CONSTANT_PATH_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.
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_t *node = YP_ALLOC_NODE(parser, yp_constant_path_operator_write_node_t);
*node = (yp_constant_path_operator_write_node_t) {
{
.type = YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE,
.location = {
.start = target->base.location.start,
.end = value->location.end
}
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new ConstantPathOrWriteNode node.
static yp_constant_path_or_write_node_t *
yp_constant_path_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_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_path_or_write_node_t);
*node = (yp_constant_path_or_write_node_t) {
{
.type = YP_NODE_CONSTANT_PATH_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) {
@ -1647,6 +1760,74 @@ yp_constant_path_write_node_create(yp_parser_t *parser, yp_constant_path_node_t
return node; return node;
} }
// Allocate and initialize a new ConstantAndWriteNode node.
static yp_constant_and_write_node_t *
yp_constant_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_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_and_write_node_t);
*node = (yp_constant_and_write_node_t) {
{
.type = YP_NODE_CONSTANT_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.
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_t *node = YP_ALLOC_NODE(parser, yp_constant_operator_write_node_t);
*node = (yp_constant_operator_write_node_t) {
{
.type = YP_NODE_CONSTANT_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new ConstantOrWriteNode node.
static yp_constant_or_write_node_t *
yp_constant_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_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_or_write_node_t);
*node = (yp_constant_or_write_node_t) {
{
.type = YP_NODE_CONSTANT_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) {
@ -2081,6 +2262,74 @@ 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 GlobalVariableAndWriteNode node.
static yp_global_variable_and_write_node_t *
yp_global_variable_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_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_and_write_node_t);
*node = (yp_global_variable_and_write_node_t) {
{
.type = YP_NODE_GLOBAL_VARIABLE_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.
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_t *node = YP_ALLOC_NODE(parser, yp_global_variable_operator_write_node_t);
*node = (yp_global_variable_operator_write_node_t) {
{
.type = YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new GlobalVariableOrWriteNode node.
static yp_global_variable_or_write_node_t *
yp_global_variable_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_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_or_write_node_t);
*node = (yp_global_variable_or_write_node_t) {
{
.type = YP_NODE_GLOBAL_VARIABLE_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) {
@ -2371,6 +2620,74 @@ 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 InstanceVariableAndWriteNode node.
static yp_instance_variable_and_write_node_t *
yp_instance_variable_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_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_and_write_node_t);
*node = (yp_instance_variable_and_write_node_t) {
{
.type = YP_NODE_INSTANCE_VARIABLE_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.
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_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_operator_write_node_t);
*node = (yp_instance_variable_operator_write_node_t) {
{
.type = YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new InstanceVariableOrWriteNode node.
static yp_instance_variable_or_write_node_t *
yp_instance_variable_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_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_or_write_node_t);
*node = (yp_instance_variable_or_write_node_t) {
{
.type = YP_NODE_INSTANCE_VARIABLE_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) {
@ -2644,6 +2961,80 @@ yp_lambda_node_create(
return node; return node;
} }
// Allocate and initialize a new LocalVariableAndWriteNode node.
static yp_local_variable_and_write_node_t *
yp_local_variable_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, uint32_t depth) {
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_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_and_write_node_t);
*node = (yp_local_variable_and_write_node_t) {
{
.type = YP_NODE_LOCAL_VARIABLE_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,
.depth = depth
};
return node;
}
// Allocate and initialize a new LocalVariableOperatorWriteNode node.
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, uint32_t depth) {
yp_local_variable_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_operator_write_node_t);
*node = (yp_local_variable_operator_write_node_t) {
{
.type = YP_NODE_LOCAL_VARIABLE_OPERATOR_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,
.operator_id = yp_parser_constant_id_location(parser, operator->start, operator->end - 1),
.depth = depth
};
return node;
}
// Allocate and initialize a new LocalVariableOrWriteNode node.
static yp_local_variable_or_write_node_t *
yp_local_variable_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, uint32_t depth) {
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_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_or_write_node_t);
*node = (yp_local_variable_or_write_node_t) {
{
.type = YP_NODE_LOCAL_VARIABLE_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,
.depth = depth
};
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) {
@ -2879,28 +3270,6 @@ yp_numbered_reference_read_node_create(yp_parser_t *parser, const yp_token_t *na
return node; return node;
} }
// Allocate and initialize a new OperatorWriteNode.
static yp_operator_write_node_t *
yp_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_operator_write_node_t);
*node = (yp_operator_write_node_t) {
{
.type = YP_NODE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
},
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1),
.value = value
};
return node;
}
// Allocate a new OptionalParameterNode node. // Allocate a new OptionalParameterNode node.
static yp_optional_parameter_node_t * static yp_optional_parameter_node_t *
yp_optional_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, const yp_token_t *operator, yp_node_t *value) { yp_optional_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, const yp_token_t *operator, yp_node_t *value) {
@ -2944,27 +3313,6 @@ 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) {
@ -4074,13 +4422,15 @@ yp_parser_local_depth(yp_parser_t *parser, yp_token_t *token) {
} }
// Add a local variable from a location to the current scope. // Add a local variable from a location to the current scope.
static void static yp_constant_id_t
yp_parser_local_add_location(yp_parser_t *parser, const char *start, const char *end) { yp_parser_local_add_location(yp_parser_t *parser, const char *start, const char *end) {
yp_constant_id_t constant_id = yp_parser_constant_id_location(parser, start, end); yp_constant_id_t constant_id = yp_parser_constant_id_location(parser, start, end);
if (!yp_constant_id_list_includes(&parser->current_scope->locals, constant_id)) { if (!yp_constant_id_list_includes(&parser->current_scope->locals, constant_id)) {
yp_constant_id_list_append(&parser->current_scope->locals, constant_id); yp_constant_id_list_append(&parser->current_scope->locals, constant_id);
} }
return constant_id;
} }
// Add a local variable from a token to the current scope. // Add a local variable from a token to the current scope.
@ -12259,19 +12609,57 @@ 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_CLASS_VARIABLE_READ_NODE: case YP_NODE_GLOBAL_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_token_t operator = not_provided(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
node = parse_target(parser, node, &operator, NULL); yp_node_t *result = (yp_node_t *) yp_global_variable_and_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
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 *value = parse_expression(parser, binding_power, "Expected a value after &&=");
return (yp_node_t *) yp_and_write_node_create(parser, node, &token, value); yp_node_t *result = (yp_node_t *) yp_class_variable_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_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_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_and_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) 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_local_variable_and_write_node_create(parser, node, &token, value, cast->constant_id, cast->depth);
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;
@ -12281,19 +12669,18 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
// will transform it into a local variable write. // will transform it into a local variable write.
if (yp_call_node_variable_call_p(call_node)) { if (yp_call_node_variable_call_p(call_node)) {
yp_location_t message_loc = call_node->message_loc; yp_location_t message_loc = call_node->message_loc;
yp_parser_local_add_location(parser, message_loc.start, message_loc.end); yp_constant_id_t constant_id = yp_parser_local_add_location(parser, message_loc.start, message_loc.end);
if (token_is_numbered_parameter(message_loc.start, message_loc.end)) { if (token_is_numbered_parameter(message_loc.start, message_loc.end)) {
yp_diagnostic_list_append(&parser->error_list, message_loc.start, message_loc.end, "reserved for numbered parameter"); yp_diagnostic_list_append(&parser->error_list, message_loc.start, message_loc.end, "reserved for numbered parameter");
} }
parser_lex(parser); parser_lex(parser);
yp_token_t operator = not_provided(parser);
node = parse_target(parser, node, &operator, NULL);
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_and_write_node_create(parser, node, &token, value); yp_node_t *result = (yp_node_t *) yp_local_variable_and_write_node_create(parser, node, &token, value, constant_id, 0);
yp_node_destroy(parser, node);
return result;
} }
parser_lex(parser); parser_lex(parser);
@ -12325,19 +12712,57 @@ 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_CLASS_VARIABLE_READ_NODE: case YP_NODE_GLOBAL_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_token_t operator = not_provided(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after ||=");
node = parse_target(parser, node, &operator, NULL); yp_node_t *result = (yp_node_t *) yp_global_variable_or_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
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 *value = parse_expression(parser, binding_power, "Expected a value after ||=");
return (yp_node_t *) yp_or_write_node_create(parser, node, &token, value); yp_node_t *result = (yp_node_t *) yp_class_variable_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_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_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_or_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) 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_local_variable_or_write_node_create(parser, node, &token, value, cast->constant_id, cast->depth);
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;
@ -12347,19 +12772,18 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
// will transform it into a local variable write. // will transform it into a local variable write.
if (yp_call_node_variable_call_p(call_node)) { if (yp_call_node_variable_call_p(call_node)) {
yp_location_t message_loc = call_node->message_loc; yp_location_t message_loc = call_node->message_loc;
yp_parser_local_add_location(parser, message_loc.start, message_loc.end); yp_constant_id_t constant_id = yp_parser_local_add_location(parser, message_loc.start, message_loc.end);
if (token_is_numbered_parameter(message_loc.start, message_loc.end)) { if (token_is_numbered_parameter(message_loc.start, message_loc.end)) {
yp_diagnostic_list_append(&parser->error_list, message_loc.start, message_loc.end, "reserved for numbered parameter"); yp_diagnostic_list_append(&parser->error_list, message_loc.start, message_loc.end, "reserved for numbered parameter");
} }
parser_lex(parser); parser_lex(parser);
yp_token_t operator = not_provided(parser);
node = parse_target(parser, node, &operator, NULL);
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_or_write_node_create(parser, node, &token, value); yp_node_t *result = (yp_node_t *) yp_local_variable_or_write_node_create(parser, node, &token, value, constant_id, 0);
yp_node_destroy(parser, node);
return result;
} }
parser_lex(parser); parser_lex(parser);
@ -12401,19 +12825,57 @@ 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_CLASS_VARIABLE_READ_NODE: case YP_NODE_GLOBAL_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_token_t operator = not_provided(parser); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
node = parse_target(parser, node, &operator, NULL); yp_node_t *result = (yp_node_t *) yp_global_variable_operator_write_node_create(parser, node, &token, value);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator"); yp_node_destroy(parser, node);
return (yp_node_t *) yp_operator_write_node_create(parser, node, &token, value); return result;
}
case YP_NODE_CLASS_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_node_t *result = (yp_node_t *) yp_class_variable_operator_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 the operator.");
return (yp_node_t *) yp_constant_path_operator_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 the operator.");
yp_node_t *result = (yp_node_t *) yp_constant_operator_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 the operator.");
yp_node_t *result = (yp_node_t *) yp_instance_variable_operator_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
yp_local_variable_read_node_t *cast = (yp_local_variable_read_node_t *) node;
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_write_node_create(parser, node, &token, value, cast->constant_id, cast->depth);
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;
@ -12423,19 +12885,18 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
// will transform it into a local variable write. // will transform it into a local variable write.
if (yp_call_node_variable_call_p(call_node)) { if (yp_call_node_variable_call_p(call_node)) {
yp_location_t message_loc = call_node->message_loc; yp_location_t message_loc = call_node->message_loc;
yp_parser_local_add_location(parser, message_loc.start, message_loc.end); yp_constant_id_t constant_id = yp_parser_local_add_location(parser, message_loc.start, message_loc.end);
if (token_is_numbered_parameter(message_loc.start, message_loc.end)) { if (token_is_numbered_parameter(message_loc.start, message_loc.end)) {
yp_diagnostic_list_append(&parser->error_list, message_loc.start, message_loc.end, "reserved for numbered parameter"); yp_diagnostic_list_append(&parser->error_list, message_loc.start, message_loc.end, "reserved for numbered parameter");
} }
parser_lex(parser); parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_write_node_create(parser, node, &token, value, constant_id, 0);
yp_token_t operator = not_provided(parser); yp_node_destroy(parser, node);
node = parse_target(parser, node, &operator, NULL); return result;
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
return (yp_node_t *) yp_operator_write_node_create(parser, node, &token, value);
} }
yp_token_t operator = not_provided(parser); yp_token_t operator = not_provided(parser);