Resync YARP

This commit is contained in:
Takashi Kokubun 2023-08-16 17:57:34 -07:00
parent 81d715099c
commit 40002dd7dc
Notes: git 2023-08-17 16:59:16 +00:00
82 changed files with 514 additions and 481 deletions

View File

@ -411,7 +411,8 @@ module YARP
end
def test_InterpolatedStringNode
assert_location(InterpolatedStringNode, "<<~A\nhello world\nA")
assert_location(InterpolatedStringNode, "\"foo \#@bar baz\"")
assert_location(InterpolatedStringNode, "<<~A\nhello world\nA", 0...4)
end
def test_InterpolatedSymbolNode

View File

@ -84,6 +84,10 @@ class ParseTest < Test::Unit::TestCase
# changing the shape of the tree.
assert_equal_nodes(result.value, YARP.load(source, YARP.dump(source, relative)).value)
# Next, check that the location ranges of each node in the tree are a
# superset of their respective child nodes.
assert_non_overlapping_locations(result.value)
# Next, assert that the newlines are in the expected places.
expected_newlines = [0]
source.b.scan("\n") { expected_newlines << $~.offset(0)[0] + 1 }
@ -137,6 +141,32 @@ class ParseTest < Test::Unit::TestCase
private
# Check that the location ranges of each node in the tree are a superset of
# their respective child nodes.
def assert_non_overlapping_locations(node)
queue = [node]
while (current = queue.shift)
# We only want to compare parent/child location overlap in the case that
# we are not looking at a heredoc. That's because heredoc locations are
# special in that they only use the declaration of the heredoc.
compare = !(current.is_a?(YARP::InterpolatedStringNode) || current.is_a?(YARP::InterpolatedXStringNode)) || !current.opening&.start_with?("<<")
current.child_nodes.each do |child|
# child_nodes can return nil values, so we need to skip those.
next unless child
# Now that we know we have a child node, add that to the queue.
queue << child
if compare
assert_operator current.location.start_offset, :<=, child.location.start_offset
assert_operator current.location.end_offset, :>=, child.location.end_offset
end
end
end
end
def find_source_file_node(program)
queue = [program]
while (node = queue.shift)

View File

@ -1,13 +1,13 @@
ProgramNode(0...231)(
ProgramNode(0...217)(
[],
StatementsNode(0...231)(
[InterpolatedStringNode(0...15)(
StatementsNode(0...217)(
[InterpolatedStringNode(0...6)(
(0...6),
[StringNode(7...11)(nil, (7...11), nil, " a\n")],
(11...15)
),
CallNode(16...58)(
InterpolatedStringNode(16...47)(
CallNode(16...36)(
InterpolatedStringNode(16...24)(
(16...24),
[StringNode(37...41)(nil, (37...41), nil, " a\n")],
(41...47)
@ -15,8 +15,8 @@ ProgramNode(0...231)(
nil,
(25...26),
nil,
ArgumentsNode(27...58)(
[InterpolatedStringNode(27...58)(
ArgumentsNode(27...36)(
[InterpolatedStringNode(27...36)(
(27...36),
[StringNode(47...51)(nil, (47...51), nil, " b\n")],
(51...58)
@ -27,7 +27,7 @@ ProgramNode(0...231)(
0,
"+"
),
InterpolatedXStringNode(59...81)(
InterpolatedXStringNode(59...67)(
(59...67),
[StringNode(68...72)(nil, (68...72), nil, " a\n"),
EmbeddedStatementsNode(72...76)(
@ -50,17 +50,17 @@ ProgramNode(0...231)(
StringNode(76...77)(nil, (76...77), nil, "\n")],
(77...81)
),
InterpolatedStringNode(82...106)(
InterpolatedStringNode(82...88)(
(82...88),
[StringNode(98...102)(nil, (98...102), nil, " a\n")],
(102...106)
),
InterpolatedStringNode(107...128)(
InterpolatedStringNode(107...113)(
(107...113),
[StringNode(114...122)(nil, (114...122), nil, " a\n" + " b\n")],
(122...128)
),
InterpolatedStringNode(129...151)(
InterpolatedStringNode(129...137)(
(129...137),
[StringNode(138...142)(nil, (138...142), nil, " a\n"),
EmbeddedStatementsNode(142...146)(
@ -83,7 +83,7 @@ ProgramNode(0...231)(
StringNode(146...147)(nil, (146...147), nil, "\n")],
(147...151)
),
InterpolatedStringNode(152...172)(
InterpolatedStringNode(152...158)(
(152...158),
[StringNode(159...163)(nil, (159...163), nil, " a\n"),
EmbeddedStatementsNode(163...167)(
@ -107,13 +107,13 @@ ProgramNode(0...231)(
(168...172)
),
StringNode(173...179)((173...175), (175...178), (178...179), "abc"),
InterpolatedStringNode(181...200)(
InterpolatedStringNode(181...187)(
(181...187),
[StringNode(188...196)(nil, (188...196), nil, " a\n" + " b\n")],
(196...200)
),
InterpolatedStringNode(201...208)((201...206), [], (207...208)),
InterpolatedStringNode(209...231)(
InterpolatedStringNode(201...206)((201...206), [], (207...208)),
InterpolatedStringNode(209...217)(
(209...217),
[StringNode(218...227)(nil, (218...227), nil, " a \#{1}\n")],
(227...231)

View File

@ -18,17 +18,17 @@ ProgramNode(0...108)(
"puts"
),
ArrayNode(28...37)(
[SymbolNode(31...36)(nil, (31...36), nil, "a\u0000\u0000b")],
[SymbolNode(31...36)(nil, (31...36), nil, "ab")],
(28...31),
(36...37)
),
InterpolatedStringNode(41...73)(
InterpolatedStringNode(41...45)(
(41...45),
[StringNode(47...70)(
nil,
(47...70),
nil,
" 1 \u0000\u0000 2\r\n" + " 3\r\n"
" 1 2\r\n" + " 3\r\n"
)],
(70...73)
),
@ -49,7 +49,7 @@ ProgramNode(0...108)(
(95...96),
ArgumentsNode(96...107)(
[CallNode(96...107)(
InterpolatedStringNode(96...128)(
InterpolatedStringNode(96...102)(
(96...102),
[StringNode(110...121)(
nil,

View File

@ -1,6 +1,4 @@
ProgramNode(0...10)(
ProgramNode(0...6)(
[],
StatementsNode(0...10)(
[InterpolatedStringNode(0...10)((0...6), [], (7...10))]
)
StatementsNode(0...6)([InterpolatedStringNode(0...6)((0...6), [], (7...10))])
)

View File

@ -1,13 +1,13 @@
ProgramNode(0...47)(
ProgramNode(0...7)(
[],
StatementsNode(0...47)(
[InterpolatedStringNode(0...47)(
StatementsNode(0...7)(
[InterpolatedStringNode(0...7)(
(0...7),
[StringNode(8...12)(nil, (8...12), nil, "pre\n"),
EmbeddedStatementsNode(12...36)(
(12...14),
StatementsNode(15...35)(
[InterpolatedStringNode(15...35)(
StatementsNode(15...21)(
[InterpolatedStringNode(15...21)(
(15...21),
[StringNode(22...30)(nil, (22...30), nil, " hello\n")],
(30...35)

View File

@ -1,8 +1,8 @@
ProgramNode(0...106)(
ProgramNode(0...23)(
[],
StatementsNode(0...106)(
[InterpolatedStringNode(0...14)((0...7), [], (9...14)),
InterpolatedStringNode(15...106)(
StatementsNode(0...23)(
[InterpolatedStringNode(0...7)((0...7), [], (9...14)),
InterpolatedStringNode(15...23)(
(15...23),
[StringNode(25...100)(
nil,
@ -13,8 +13,7 @@ ProgramNode(0...106)(
" not here\n" +
"HERE\n" +
"\n" +
"<<~BUT\n" +
" but\n" +
"<<~BUT but\n" +
"BUT\n" +
" there\n"
)],

View File

@ -1,7 +1,7 @@
ProgramNode(0...26)(
ProgramNode(0...6)(
[],
StatementsNode(0...26)(
[InterpolatedStringNode(0...26)(
StatementsNode(0...6)(
[InterpolatedStringNode(0...6)(
(0...6),
[StringNode(7...23)(nil, (7...23), nil, " some\n" + " heredocs\n")],
(23...26)

View File

@ -1,17 +1,12 @@
ProgramNode(0...35)(
ProgramNode(0...12)(
[:str],
StatementsNode(0...35)(
[LocalVariableWriteNode(0...35)(
StatementsNode(0...12)(
[LocalVariableWriteNode(0...12)(
:str,
0,
InterpolatedStringNode(6...35)(
InterpolatedStringNode(6...12)(
(6...12),
[StringNode(14...30)(
nil,
(14...30),
nil,
"before\u0000\u0000after\r\n"
)],
[StringNode(14...30)(nil, (14...30), nil, "beforeafter\r\n")],
(30...35)
),
(0...3),

View File

@ -1,19 +1,19 @@
ProgramNode(0...93)(
ProgramNode(0...49)(
[],
StatementsNode(0...93)(
StatementsNode(0...49)(
[StringNode(0...40)(
(0...1),
(1...39),
(39...40),
" why would someone do this? \n" + " blah\n"
" why would someone do this? blah\n"
),
InterpolatedStringNode(42...93)(
InterpolatedStringNode(42...49)(
(42...49),
[StringNode(50...88)(
nil,
(50...88),
nil,
" why would someone do this? \n" + " blah\n"
" why would someone do this? blah\n"
)],
(88...93)
)]

View File

@ -1,10 +1,10 @@
ProgramNode(0...21)(
ProgramNode(0...9)(
[:s],
StatementsNode(0...21)(
[LocalVariableWriteNode(0...21)(
StatementsNode(0...9)(
[LocalVariableWriteNode(0...9)(
:s,
0,
InterpolatedStringNode(4...21)(
InterpolatedStringNode(4...9)(
(4...9),
[StringNode(10...17)(nil, (10...17), nil, "a\xE9b\n")],
(17...21)

View File

@ -1,10 +1,10 @@
ProgramNode(0...27)(
ProgramNode(0...10)(
[:s],
StatementsNode(0...27)(
[LocalVariableWriteNode(0...27)(
StatementsNode(0...10)(
[LocalVariableWriteNode(0...10)(
:s,
0,
InterpolatedStringNode(4...27)(
InterpolatedStringNode(4...10)(
(4...10),
[StringNode(11...23)(nil, (11...23), nil, "a\xA7b\n" + "cöd\n")],
(23...27)

View File

@ -7,7 +7,7 @@ ProgramNode(0...47)(
(16...17)
),
ArrayNode(19...47)(
[InterpolatedStringNode(20...46)(
[InterpolatedStringNode(20...27)(
(20...27),
[StringNode(29...41)(nil, (29...41), nil, " some text\n")],
(41...46)

View File

@ -1,10 +1,10 @@
ProgramNode(0...41)(
[:c, :d],
StatementsNode(0...41)(
[LocalVariableWriteNode(0...34)(
[LocalVariableWriteNode(0...11)(
:c,
0,
InterpolatedStringNode(4...34)(
InterpolatedStringNode(4...11)(
(4...11),
[StringNode(12...30)(
nil,

View File

@ -2,12 +2,12 @@ ProgramNode(0...23)(
[],
StatementsNode(0...23)(
[ArrayNode(0...23)(
[InterpolatedStringNode(1...21)(
[InterpolatedStringNode(1...4)(
(1...4),
[EmbeddedStatementsNode(6...12)(
(6...8),
StatementsNode(8...17)(
[InterpolatedStringNode(8...17)(
StatementsNode(8...11)(
[InterpolatedStringNode(8...11)(
(8...11),
[StringNode(13...15)(nil, (13...15), nil, "b\n")],
(15...17)

View File

@ -1,10 +1,10 @@
ProgramNode(0...31)(
ProgramNode(0...12)(
[:a],
StatementsNode(0...31)(
[LocalVariableWriteNode(0...31)(
StatementsNode(0...12)(
[LocalVariableWriteNode(0...12)(
:a,
0,
InterpolatedStringNode(4...31)(
InterpolatedStringNode(4...12)(
(4...12),
[StringNode(13...25)(nil, (13...25), nil, "x\n" + "y\n" + "z\n")],
(25...31)

View File

@ -11,7 +11,7 @@ ProgramNode(0...20)(
(7...8),
ArgumentsNode(8...19)(
[CallNode(8...19)(
InterpolatedStringNode(8...42)(
InterpolatedStringNode(8...14)(
(8...14),
[StringNode(21...26)(nil, (21...26), nil, "\n"),
EmbeddedStatementsNode(26...32)(

View File

@ -1,10 +1,10 @@
ProgramNode(0...24)(
ProgramNode(0...10)(
[:a],
StatementsNode(0...24)(
[LocalVariableWriteNode(0...24)(
StatementsNode(0...10)(
[LocalVariableWriteNode(0...10)(
:a,
0,
InterpolatedStringNode(4...24)(
InterpolatedStringNode(4...10)(
(4...10),
[StringNode(11...20)(nil, (11...20), nil, "x\n" + "\n" + "z\n")],
(20...24)

View File

@ -1,4 +1,4 @@
ProgramNode(0...7)(
ProgramNode(0...4)(
[],
StatementsNode(0...7)([InterpolatedStringNode(0...7)((0...4), [], (5...7))])
StatementsNode(0...4)([InterpolatedStringNode(0...4)((0...4), [], (5...7))])
)

View File

@ -1,10 +1,10 @@
ProgramNode(0...42)(
ProgramNode(0...10)(
[:a],
StatementsNode(0...42)(
[LocalVariableWriteNode(0...42)(
StatementsNode(0...10)(
[LocalVariableWriteNode(0...10)(
:a,
0,
InterpolatedStringNode(4...42)(
InterpolatedStringNode(4...10)(
(4...10),
[StringNode(11...22)(nil, (11...22), nil, " w\n" + "x"),
EmbeddedStatementsNode(22...27)(

View File

@ -1,7 +1,7 @@
ProgramNode(0...9)(
ProgramNode(0...4)(
[],
StatementsNode(0...9)(
[InterpolatedStringNode(0...9)(
StatementsNode(0...4)(
[InterpolatedStringNode(0...4)(
(0...4),
[StringNode(5...7)(nil, (5...7), nil, "a\n")],
(7...9)

View File

@ -1,10 +1,10 @@
ProgramNode(0...49)(
ProgramNode(0...12)(
[:a],
StatementsNode(0...49)(
[LocalVariableWriteNode(0...49)(
StatementsNode(0...12)(
[LocalVariableWriteNode(0...12)(
:a,
0,
InterpolatedStringNode(4...49)(
InterpolatedStringNode(4...12)(
(4...12),
[StringNode(13...43)(
nil,

View File

@ -1,10 +1,10 @@
ProgramNode(0...43)(
ProgramNode(0...12)(
[:a],
StatementsNode(0...43)(
[LocalVariableWriteNode(0...43)(
StatementsNode(0...12)(
[LocalVariableWriteNode(0...12)(
:a,
0,
InterpolatedStringNode(4...43)(
InterpolatedStringNode(4...12)(
(4...12),
[StringNode(13...37)(
nil,

View File

@ -1,10 +1,10 @@
ProgramNode(0...24)(
ProgramNode(0...10)(
[:a],
StatementsNode(0...24)(
[LocalVariableWriteNode(0...24)(
StatementsNode(0...10)(
[LocalVariableWriteNode(0...10)(
:a,
0,
InterpolatedStringNode(4...24)(
InterpolatedStringNode(4...10)(
(4...10),
[StringNode(11...20)(nil, (11...20), nil, "x\n" + "\n" + "z\n")],
(20...24)

View File

@ -2,7 +2,7 @@ ProgramNode(0...22)(
[],
StatementsNode(0...22)(
[CallNode(0...22)(
InterpolatedStringNode(0...16)(
InterpolatedStringNode(0...5)(
(0...5),
[StringNode(7...12)(nil, (7...12), nil, "blah\n")],
(12...16)

View File

@ -1,7 +1,7 @@
ProgramNode(0...20)(
ProgramNode(0...9)(
[],
StatementsNode(0...20)(
[InterpolatedStringNode(0...20)(
StatementsNode(0...9)(
[InterpolatedStringNode(0...9)(
(0...9),
[StringNode(10...12)(nil, (10...12), nil, ".\n")],
(12...20)

View File

@ -1,7 +1,7 @@
ProgramNode(0...25)(
ProgramNode(0...5)(
[],
StatementsNode(0...25)(
[InterpolatedStringNode(0...25)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(6...21)(nil, (6...21), nil, "foo\rbar\n" + "baz\r\n")],
(21...25)

View File

@ -1,7 +1,7 @@
ProgramNode(0...29)(
ProgramNode(0...5)(
[],
StatementsNode(0...29)(
[InterpolatedStringNode(0...29)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(7...24)(nil, (7...24), nil, "foo\rbar\r\n" + "baz\r\r\n")],
(24...29)

View File

@ -1,7 +1,7 @@
ProgramNode(0...19)(
ProgramNode(0...7)(
[],
StatementsNode(0...19)(
[InterpolatedStringNode(0...19)(
StatementsNode(0...7)(
[InterpolatedStringNode(0...7)(
(0...7),
[StringNode(9...15)(nil, (9...15), nil, "body\r\n")],
(15...19)

View File

@ -1,7 +1,7 @@
ProgramNode(0...23)(
ProgramNode(0...5)(
[],
StatementsNode(0...23)(
[InterpolatedStringNode(0...23)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(6...19)(nil, (6...19), nil, "foo\rbar\r\n" + "baz\n")],
(19...23)

View File

@ -1,7 +1,7 @@
ProgramNode(0...27)(
ProgramNode(0...5)(
[],
StatementsNode(0...27)(
[InterpolatedStringNode(0...27)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(7...22)(nil, (7...22), nil, "foo\rbar\r\r\n" + "baz\r\n")],
(22...27)

View File

@ -1,7 +1,7 @@
ProgramNode(0...21)(
ProgramNode(0...5)(
[],
StatementsNode(0...21)(
[InterpolatedStringNode(0...21)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(6...11)(nil, (6...11), nil, "foo\r"),
EmbeddedVariableNode(11...16)(

View File

@ -1,7 +1,7 @@
ProgramNode(0...24)(
ProgramNode(0...5)(
[],
StatementsNode(0...24)(
[InterpolatedStringNode(0...24)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(7...12)(nil, (7...12), nil, "foo\r"),
EmbeddedVariableNode(12...17)(

View File

@ -1,7 +1,7 @@
ProgramNode(0...23)(
ProgramNode(0...10)(
[],
StatementsNode(0...23)(
[InterpolatedStringNode(0...23)(
StatementsNode(0...10)(
[InterpolatedStringNode(0...10)(
(0...10),
[StringNode(11...15)(nil, (11...15), nil, "\#${\n")],
(15...23)

View File

@ -1,7 +1,7 @@
ProgramNode(0...18)(
ProgramNode(0...5)(
[],
StatementsNode(0...18)(
[InterpolatedStringNode(0...18)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(6...14)(nil, (6...14), nil, "\r\n" + "\r\r\n" + "\r\n")],
(14...18)

View File

@ -1,7 +1,7 @@
ProgramNode(0...23)(
ProgramNode(0...5)(
[],
StatementsNode(0...23)(
[InterpolatedStringNode(0...23)(
StatementsNode(0...5)(
[InterpolatedStringNode(0...5)(
(0...5),
[StringNode(7...18)(
nil,

View File

@ -9,7 +9,7 @@ ProgramNode(0...30)(
ArgumentsNode(2...30)(
[CallNode(2...30)(
CallNode(2...26)(
InterpolatedStringNode(2...22)(
InterpolatedStringNode(2...8)(
(2...8),
[StringNode(12...16)(nil, (12...16), nil, " a\n")],
(16...22)

View File

@ -5,7 +5,7 @@ ProgramNode(6...88)(
:string,
0,
CallNode(15...31)(
InterpolatedStringNode(15...71)(
InterpolatedStringNode(15...25)(
(15...25),
[StringNode(32...57)(
nil,

View File

@ -1,7 +1,7 @@
ProgramNode(0...14)(
ProgramNode(0...4)(
[],
StatementsNode(0...14)(
[InterpolatedStringNode(0...14)(
StatementsNode(0...4)(
[InterpolatedStringNode(0...4)(
(0...4),
[StringNode(5...7)(nil, (5...7), nil, "a\n"),
EmbeddedStatementsNode(7...11)(

View File

@ -1,7 +1,7 @@
ProgramNode(0...48)(
[],
StatementsNode(0...48)(
[InterpolatedStringNode(0...34)(
[InterpolatedStringNode(0...8)(
(0...8),
[StringNode(9...28)(
nil,

View File

@ -1,10 +1,10 @@
ProgramNode(6...74)(
[:string],
StatementsNode(6...74)(
[LocalVariableWriteNode(6...57)(
[LocalVariableWriteNode(6...22)(
:string,
0,
InterpolatedStringNode(15...57)(
InterpolatedStringNode(15...22)(
(15...22),
[StringNode(23...48)(
nil,

View File

@ -5,7 +5,7 @@ ProgramNode(0...28)(
[StringNode(3...7)(nil, (3...7), nil, "a\n" + "b"),
StringNode(8...9)(nil, (8...9), nil, "c"),
StringNode(10...11)(nil, (10...11), nil, "d"),
StringNode(12...16)(nil, (12...16), nil, "e\n" + "f"),
StringNode(12...16)(nil, (12...16), nil, "ef"),
StringNode(17...19)(nil, (17...19), nil, "gy"),
StringNode(20...23)(nil, (20...23), nil, "hy"),
StringNode(24...27)(nil, (24...27), nil, "iy")],

View File

@ -1,4 +1,4 @@
ProgramNode(0...7)(
[],
StatementsNode(0...7)([StringNode(0...7)((0...3), (3...6), (6...7), " \n")])
StatementsNode(0...7)([StringNode(0...7)((0...3), (3...6), (6...7), " ")])
)

View File

@ -3,12 +3,12 @@ ProgramNode(0...30)(
StatementsNode(0...30)(
[ArrayNode(0...30)(
[StringNode(4...5)(nil, (4...5), nil, "1"),
InterpolatedStringNode(0...12)(
InterpolatedStringNode(6...12)(
nil,
[EmbeddedStatementsNode(6...12)(
(6...8),
StatementsNode(8...19)(
[InterpolatedStringNode(8...19)(
StatementsNode(8...11)(
[InterpolatedStringNode(8...11)(
(8...11),
[StringNode(15...17)(nil, (15...17), nil, "2\n")],
(17...19)

View File

@ -11,7 +11,7 @@ ProgramNode(0...40)(
(5...6),
(6...32),
(32...33),
"hello\n" + " my\n" + " dear\n" + " friend"
"hello my dear friend"
)]
),
nil,

View File

@ -1,7 +1,7 @@
ProgramNode(0...17)(
ProgramNode(0...4)(
[],
StatementsNode(0...17)(
[InterpolatedStringNode(0...17)(
StatementsNode(0...4)(
[InterpolatedStringNode(0...4)(
(0...4),
[EmbeddedStatementsNode(5...9)(
(5...7),

View File

@ -2,7 +2,7 @@ ProgramNode(0...9)(
[],
StatementsNode(0...9)(
[ArrayNode(0...9)(
[InterpolatedStringNode(0...8)(
[InterpolatedStringNode(3...8)(
nil,
[EmbeddedStatementsNode(3...7)(
(3...5),

View File

@ -1,7 +1,7 @@
ProgramNode(0...48)(
ProgramNode(0...8)(
[],
StatementsNode(0...48)(
[InterpolatedStringNode(0...48)(
StatementsNode(0...8)(
[InterpolatedStringNode(0...8)(
(0...8),
[StringNode(9...44)(
nil,

View File

@ -120,7 +120,7 @@ ProgramNode(0...498)(
),
ArrayNode(325...339)(
[StringNode(328...329)(nil, (328...329), nil, "a"),
InterpolatedStringNode(0...336)(
InterpolatedStringNode(330...336)(
nil,
[StringNode(330...331)(nil, (330...331), nil, "b"),
EmbeddedStatementsNode(331...335)(

View File

@ -1,20 +1,19 @@
ProgramNode(0...387)(
ProgramNode(0...372)(
[],
StatementsNode(0...387)(
[InterpolatedStringNode(0...15)(
StatementsNode(0...372)(
[InterpolatedStringNode(0...6)(
(0...6),
[StringNode(7...11)(nil, (7...11), nil, "a\n")],
(11...15)
),
InterpolatedStringNode(16...38)(
InterpolatedStringNode(16...22)(
(16...22),
[StringNode(23...34)(nil, (23...34), nil, "\ta\n" + "b\n" + "\t\tc\n")],
(34...38)
),
InterpolatedStringNode(39...59)(
InterpolatedStringNode(39...45)(
(39...45),
[StringNode(46...48)(nil, (46...48), nil, ""),
EmbeddedStatementsNode(48...52)(
[EmbeddedStatementsNode(48...52)(
(48...50),
StatementsNode(50...51)([IntegerNode(50...51)()]),
(51...52)
@ -22,7 +21,7 @@ ProgramNode(0...387)(
StringNode(52...55)(nil, (52...55), nil, " a\n")],
(55...59)
),
InterpolatedStringNode(60...80)(
InterpolatedStringNode(60...66)(
(60...66),
[StringNode(67...71)(nil, (67...71), nil, "a "),
EmbeddedStatementsNode(71...75)(
@ -33,7 +32,7 @@ ProgramNode(0...387)(
StringNode(75...76)(nil, (75...76), nil, "\n")],
(76...80)
),
InterpolatedStringNode(81...102)(
InterpolatedStringNode(81...87)(
(81...87),
[StringNode(88...93)(nil, (88...93), nil, " a\n"),
EmbeddedStatementsNode(93...97)(
@ -44,7 +43,7 @@ ProgramNode(0...387)(
StringNode(97...98)(nil, (97...98), nil, "\n")],
(98...102)
),
InterpolatedStringNode(103...125)(
InterpolatedStringNode(103...109)(
(103...109),
[StringNode(110...116)(nil, (110...116), nil, "a\n"),
EmbeddedStatementsNode(116...120)(
@ -55,52 +54,52 @@ ProgramNode(0...387)(
StringNode(120...121)(nil, (120...121), nil, "\n")],
(121...125)
),
InterpolatedStringNode(126...145)(
InterpolatedStringNode(126...132)(
(126...132),
[StringNode(133...141)(nil, (133...141), nil, "a\n" + "b\n")],
(141...145)
),
InterpolatedStringNode(146...166)(
InterpolatedStringNode(146...152)(
(146...152),
[StringNode(153...162)(nil, (153...162), nil, "a\n" + " b\n")],
(162...166)
),
InterpolatedStringNode(167...187)(
InterpolatedStringNode(167...173)(
(167...173),
[StringNode(174...183)(nil, (174...183), nil, "\ta\n" + "b\n")],
(183...187)
),
InterpolatedStringNode(188...210)(
InterpolatedStringNode(188...196)(
(188...196),
[StringNode(197...206)(nil, (197...206), nil, "a \#{1}\n")],
(206...210)
),
InterpolatedStringNode(211...229)(
InterpolatedStringNode(211...217)(
(211...217),
[StringNode(218...225)(nil, (218...225), nil, "a\n" + " b\n")],
(225...229)
),
InterpolatedStringNode(230...248)(
InterpolatedStringNode(230...236)(
(230...236),
[StringNode(237...244)(nil, (237...244), nil, " a\n" + "b\n")],
(244...248)
),
InterpolatedStringNode(249...275)(
InterpolatedStringNode(249...255)(
(249...255),
[StringNode(256...271)(nil, (256...271), nil, "a\n" + "b\n")],
(271...275)
),
InterpolatedStringNode(276...296)(
InterpolatedStringNode(276...282)(
(276...282),
[StringNode(283...292)(nil, (283...292), nil, "a\n" + "\n" + "b\n")],
(292...296)
),
InterpolatedStringNode(297...317)(
InterpolatedStringNode(297...303)(
(297...303),
[StringNode(304...313)(nil, (304...313), nil, "a\n" + "\n" + "b\n")],
(313...317)
),
InterpolatedStringNode(318...340)(
InterpolatedStringNode(318...324)(
(318...324),
[StringNode(325...336)(
nil,
@ -110,7 +109,7 @@ ProgramNode(0...387)(
)],
(336...340)
),
InterpolatedStringNode(341...365)(
InterpolatedStringNode(341...347)(
(341...347),
[StringNode(348...351)(nil, (348...351), nil, "\n"),
EmbeddedStatementsNode(351...355)(
@ -121,10 +120,9 @@ ProgramNode(0...387)(
StringNode(355...357)(nil, (355...357), nil, "a\n")],
(357...365)
),
InterpolatedStringNode(366...387)(
InterpolatedStringNode(366...372)(
(366...372),
[StringNode(373...375)(nil, (373...375), nil, ""),
EmbeddedStatementsNode(375...379)(
[EmbeddedStatementsNode(375...379)(
(375...377),
StatementsNode(377...378)([IntegerNode(377...378)()]),
(378...379)

View File

@ -1,6 +1,6 @@
ProgramNode(0...55)(
ProgramNode(0...39)(
[],
StatementsNode(0...55)(
StatementsNode(0...39)(
[ArrayNode(0...10)(
[StringNode(1...9)((1...2), (2...8), (8...9), "\u0003{1}")],
(0...1),
@ -14,7 +14,7 @@ ProgramNode(0...55)(
0
),
StringNode(22...30)((22...23), (23...29), (29...30), "\u0003{1}"),
InterpolatedStringNode(32...55)(
InterpolatedStringNode(32...39)(
(32...39),
[StringNode(40...50)(nil, (40...50), nil, "\u0003{1}\n")],
(50...55)

View File

@ -1,6 +1,6 @@
ProgramNode(0...719)(
ProgramNode(0...704)(
[:a, :b, :foo, :c, :x],
StatementsNode(0...719)(
StatementsNode(0...704)(
[GlobalVariableWriteNode(0...6)((0...2), (3...4), IntegerNode(5...6)()),
MultiWriteNode(8...24)(
[GlobalVariableWriteNode(8...10)((8...10), nil, nil),
@ -615,10 +615,10 @@ ProgramNode(0...719)(
(554...557),
StringNode(558...561)((558...560), (560...560), (560...561), "")
),
LocalVariableWriteNode(562...591)(
LocalVariableWriteNode(562...576)(
:x,
0,
InterpolatedStringNode(566...591)(
InterpolatedStringNode(566...576)(
(566...576),
[StringNode(577...579)(nil, (577...579), nil, " "),
EmbeddedStatementsNode(579...582)((579...581), nil, (581...582)),
@ -628,13 +628,13 @@ ProgramNode(0...719)(
(562...563),
(564...565)
),
CallNode(591...620)(
CallNode(591...605)(
LocalVariableReadNode(591...592)(:x, 0),
(592...593),
(593...594),
nil,
ArgumentsNode(595...620)(
[InterpolatedStringNode(595...620)(
ArgumentsNode(595...605)(
[InterpolatedStringNode(595...605)(
(595...605),
[StringNode(606...608)(nil, (606...608), nil, " "),
EmbeddedStatementsNode(608...611)((608...610), nil, (610...611)),
@ -647,13 +647,13 @@ ProgramNode(0...719)(
0,
"x="
),
CallNode(620...651)(
CallNode(620...636)(
LocalVariableReadNode(620...621)(:x, 0),
nil,
(621...623),
(621...622),
ArgumentsNode(626...651)(
[InterpolatedStringNode(626...651)(
ArgumentsNode(626...636)(
[InterpolatedStringNode(626...636)(
(626...636),
[StringNode(637...639)(nil, (637...639), nil, " "),
EmbeddedStatementsNode(639...642)((639...641), nil, (641...642)),
@ -672,8 +672,8 @@ ProgramNode(0...719)(
nil,
(652...664),
(652...653),
ArgumentsNode(653...687)(
[InterpolatedStringNode(653...687)(
ArgumentsNode(653...663)(
[InterpolatedStringNode(653...663)(
(653...663),
[StringNode(673...675)(nil, (673...675), nil, " "),
EmbeddedStatementsNode(675...678)(
@ -703,10 +703,10 @@ ProgramNode(0...719)(
),
(665...668)
),
InstanceVariableOperatorOrWriteNode(687...719)(
InstanceVariableOperatorOrWriteNode(687...704)(
(687...689),
(690...693),
InterpolatedStringNode(694...719)(
InterpolatedStringNode(694...704)(
(694...704),
[StringNode(705...707)(nil, (705...707), nil, " "),
EmbeddedStatementsNode(707...710)((707...709), nil, (709...710)),

View File

@ -983,8 +983,8 @@ ProgramNode(0...913)(
(860...861),
nil,
nil,
StatementsNode(864...893)(
[InterpolatedStringNode(864...893)(
StatementsNode(864...874)(
[InterpolatedStringNode(864...874)(
(864...874),
[StringNode(875...879)(nil, (875...879), nil, " "),
EmbeddedStatementsNode(879...882)((879...881), nil, (881...882)),

View File

@ -19,7 +19,7 @@ ProgramNode(0...299)(
(21...23),
TrueNode(24...28)(),
StatementsNode(31...64)(
[InterpolatedStringNode(31...61)(
[InterpolatedStringNode(31...41)(
(31...41),
[StringNode(42...44)(nil, (42...44), nil, "a\n"),
EmbeddedStatementsNode(44...47)((44...46), nil, (46...47)),
@ -31,7 +31,7 @@ ProgramNode(0...299)(
nil,
(65...68)
),
InterpolatedStringNode(69...109)(
InterpolatedStringNode(69...79)(
(69...79),
[StringNode(80...89)(nil, (80...89), nil, "\#{}\#{}\n"),
EmbeddedStatementsNode(89...92)((89...91), nil, (91...92)),
@ -43,7 +43,7 @@ ProgramNode(0...299)(
(101...109)
),
RescueModifierNode(109...130)(
InterpolatedStringNode(109...145)(
InterpolatedStringNode(109...119)(
(109...119),
[EmbeddedStatementsNode(131...134)((131...133), nil, (133...134)),
StringNode(134...137)(nil, (134...137), nil, "\n" + "a\n")],
@ -91,11 +91,11 @@ ProgramNode(0...299)(
IfNode(174...225)(
(174...176),
TrueNode(177...181)(),
StatementsNode(184...222)(
[ReturnNode(184...222)(
StatementsNode(184...201)(
[ReturnNode(184...201)(
(184...190),
ArgumentsNode(191...222)(
[InterpolatedStringNode(191...222)(
ArgumentsNode(191...201)(
[InterpolatedStringNode(191...201)(
(191...201),
[StringNode(202...206)(nil, (202...206), nil, " "),
EmbeddedStatementsNode(206...211)(
@ -117,8 +117,8 @@ ProgramNode(0...299)(
nil,
(226...229),
(229...230),
ArgumentsNode(230...259)(
[InterpolatedStringNode(230...259)(
ArgumentsNode(230...240)(
[InterpolatedStringNode(230...240)(
(230...240),
[StringNode(242...244)(nil, (242...244), nil, " "),
EmbeddedStatementsNode(244...250)(
@ -152,8 +152,8 @@ ProgramNode(0...299)(
nil,
(259...262),
(262...263),
ArgumentsNode(263...298)(
[InterpolatedStringNode(263...298)(
ArgumentsNode(263...273)(
[InterpolatedStringNode(263...273)(
(263...273),
[StringNode(281...283)(nil, (281...283), nil, " "),
EmbeddedStatementsNode(283...289)(

View File

@ -3,9 +3,9 @@ ProgramNode(0...916)(
StatementsNode(0...916)(
[HashNode(0...38)(
(0...1),
[AssocNode(2...53)(
[AssocNode(2...21)(
StringNode(2...7)((2...3), (3...6), (6...7), "foo"),
InterpolatedStringNode(11...53)(
InterpolatedStringNode(11...21)(
(11...21),
[StringNode(39...41)(nil, (39...41), nil, " "),
EmbeddedStatementsNode(41...44)((41...43), nil, (43...44)),
@ -47,8 +47,8 @@ ProgramNode(0...916)(
nil,
(98...99),
(99...100),
ArgumentsNode(100...128)(
[InterpolatedStringNode(100...128)(
ArgumentsNode(100...110)(
[InterpolatedStringNode(100...110)(
(100...110),
[StringNode(114...116)(nil, (114...116), nil, " "),
EmbeddedStatementsNode(116...119)(
@ -99,9 +99,9 @@ ProgramNode(0...916)(
),
HashNode(137...167)(
(137...138),
[AssocNode(139...182)(
[AssocNode(139...158)(
StringNode(139...144)((139...140), (140...143), (143...144), "foo"),
InterpolatedStringNode(148...182)(
InterpolatedStringNode(148...158)(
(148...158),
[StringNode(168...170)(nil, (168...170), nil, " "),
EmbeddedStatementsNode(170...173)((170...172), nil, (172...173)),

View File

@ -95,8 +95,8 @@ ProgramNode(0...148)(
nil,
(82...85),
(85...86),
ArgumentsNode(86...109)(
[InterpolatedStringNode(86...109)(
ArgumentsNode(86...92)(
[InterpolatedStringNode(86...92)(
(86...92),
[StringNode(101...105)(nil, (101...105), nil, " b\n")],
(105...109)
@ -131,8 +131,8 @@ ProgramNode(0...148)(
nil,
(118...121),
(121...122),
ArgumentsNode(122...141)(
[InterpolatedStringNode(122...141)(
ArgumentsNode(122...128)(
[InterpolatedStringNode(122...128)(
(122...128),
[StringNode(133...137)(nil, (133...137), nil, " b\n")],
(137...141)

View File

@ -1,62 +1,62 @@
ProgramNode(0...608)(
[],
StatementsNode(0...608)(
[InterpolatedStringNode(0...10)((0...5), [], (6...10)),
InterpolatedStringNode(11...23)((11...18), [], (19...23)),
InterpolatedStringNode(24...35)((24...30), [], (31...35)),
InterpolatedStringNode(36...49)((36...44), [], (45...49)),
InterpolatedStringNode(50...64)(
[InterpolatedStringNode(0...5)((0...5), [], (6...10)),
InterpolatedStringNode(11...18)((11...18), [], (19...23)),
InterpolatedStringNode(24...30)((24...30), [], (31...35)),
InterpolatedStringNode(36...44)((36...44), [], (45...49)),
InterpolatedStringNode(50...55)(
(50...55),
[StringNode(56...60)(nil, (56...60), nil, " a\n")],
(60...64)
),
InterpolatedStringNode(65...81)(
InterpolatedStringNode(65...72)(
(65...72),
[StringNode(73...77)(nil, (73...77), nil, " a\n")],
(77...81)
),
InterpolatedStringNode(82...102)(
InterpolatedStringNode(82...87)(
(82...87),
[StringNode(88...94)(nil, (88...94), nil, " a\n" + " "),
EmbeddedStatementsNode(94...97)((94...96), nil, (96...97)),
StringNode(97...98)(nil, (97...98), nil, "\n")],
(98...102)
),
InterpolatedStringNode(103...124)(
InterpolatedStringNode(103...109)(
(103...109),
[StringNode(110...116)(nil, (110...116), nil, "a\n"),
EmbeddedStatementsNode(116...119)((116...118), nil, (118...119)),
StringNode(119...120)(nil, (119...120), nil, "\n")],
(120...124)
),
InterpolatedStringNode(125...150)(
InterpolatedStringNode(125...131)(
(125...131),
[StringNode(132...138)(nil, (132...138), nil, "a\n"),
EmbeddedStatementsNode(138...141)((138...140), nil, (140...141)),
StringNode(141...146)(nil, (141...146), nil, "\n" + "b\n")],
(146...150)
),
InterpolatedStringNode(151...172)(
InterpolatedStringNode(151...157)(
(151...157),
[StringNode(158...168)(nil, (158...168), nil, "a\n" + " b\n")],
(168...172)
),
InterpolatedStringNode(173...190)(
InterpolatedStringNode(173...180)(
(173...180),
[StringNode(181...186)(nil, (181...186), nil, "a\n" + "\n" + "b\n")],
(186...190)
),
InterpolatedStringNode(191...210)(
InterpolatedStringNode(191...198)(
(191...198),
[StringNode(199...206)(nil, (199...206), nil, " a\n" + "\n" + " b\n")],
(206...210)
),
InterpolatedStringNode(211...229)(
InterpolatedStringNode(211...218)(
(211...218),
[StringNode(219...225)(nil, (219...225), nil, " a\\nb\n")],
(225...229)
),
InterpolatedStringNode(230...251)(
InterpolatedStringNode(230...235)(
(230...235),
[EmbeddedStatementsNode(236...239)((236...238), nil, (238...239)),
StringNode(239...242)(nil, (239...242), nil, "a\n" + " "),
@ -64,35 +64,33 @@ ProgramNode(0...608)(
StringNode(245...247)(nil, (245...247), nil, "a\n")],
(247...251)
),
InterpolatedStringNode(252...275)(
InterpolatedStringNode(252...257)(
(252...257),
[StringNode(258...260)(nil, (258...260), nil, " "),
EmbeddedStatementsNode(260...263)((260...262), nil, (262...263)),
StringNode(263...271)(nil, (263...271), nil, "\n" + " \#{}\n")],
(271...275)
),
InterpolatedStringNode(276...296)(
InterpolatedStringNode(276...281)(
(276...281),
[StringNode(282...284)(nil, (282...284), nil, " a"),
EmbeddedStatementsNode(284...287)((284...286), nil, (286...287)),
StringNode(287...292)(nil, (287...292), nil, "b\n" + " c\n")],
(292...296)
),
InterpolatedStringNode(297...314)(
InterpolatedStringNode(297...303)(
(297...303),
[StringNode(304...306)(nil, (304...306), nil, ""),
EmbeddedStatementsNode(306...309)((306...308), nil, (308...309)),
[EmbeddedStatementsNode(306...309)((306...308), nil, (308...309)),
StringNode(309...310)(nil, (309...310), nil, "\n")],
(310...314)
),
IfNode(315...349)(
(315...317),
TrueNode(318...322)(),
StatementsNode(325...346)(
[InterpolatedStringNode(325...346)(
StatementsNode(325...331)(
[InterpolatedStringNode(325...331)(
(325...331),
[StringNode(332...336)(nil, (332...336), nil, ""),
EmbeddedStatementsNode(336...339)((336...338), nil, (338...339)),
[EmbeddedStatementsNode(336...339)((336...338), nil, (338...339)),
StringNode(339...340)(nil, (339...340), nil, "\n")],
(340...346)
)]
@ -103,8 +101,8 @@ ProgramNode(0...608)(
IfNode(351...386)(
(351...353),
TrueNode(354...358)(),
StatementsNode(361...383)(
[InterpolatedStringNode(361...383)(
StatementsNode(361...367)(
[InterpolatedStringNode(361...367)(
(361...367),
[StringNode(368...373)(nil, (368...373), nil, "b"),
EmbeddedStatementsNode(373...376)((373...375), nil, (375...376)),
@ -118,11 +116,10 @@ ProgramNode(0...608)(
IfNode(388...423)(
(388...390),
TrueNode(391...395)(),
StatementsNode(398...420)(
[InterpolatedStringNode(398...420)(
StatementsNode(398...404)(
[InterpolatedStringNode(398...404)(
(398...404),
[StringNode(405...409)(nil, (405...409), nil, ""),
EmbeddedStatementsNode(409...412)((409...411), nil, (411...412)),
[EmbeddedStatementsNode(409...412)((409...411), nil, (411...412)),
StringNode(412...414)(nil, (412...414), nil, "a\n")],
(414...420)
)]
@ -133,8 +130,8 @@ ProgramNode(0...608)(
IfNode(425...464)(
(425...427),
TrueNode(428...432)(),
StatementsNode(435...461)(
[InterpolatedStringNode(435...461)(
StatementsNode(435...443)(
[InterpolatedStringNode(435...443)(
(435...443),
[StringNode(444...455)(
nil,

View File

@ -102,8 +102,8 @@ ProgramNode(0...188)(
nil,
(106...107),
(107...108),
ArgumentsNode(108...123)(
[InterpolatedStringNode(108...123)((108...114), [], (119...123))]
ArgumentsNode(108...114)(
[InterpolatedStringNode(108...114)((108...114), [], (119...123))]
),
(114...115),
BlockNode(116...130)(

View File

@ -3,7 +3,7 @@ ProgramNode(0...38)(
StatementsNode(0...38)(
[ArrayNode(0...14)(
[StringNode(3...6)(nil, (3...6), nil, "foo"),
InterpolatedStringNode(0...13)(
InterpolatedStringNode(7...13)(
nil,
[EmbeddedStatementsNode(7...13)(
(7...9),
@ -29,7 +29,7 @@ ProgramNode(0...38)(
),
ArrayNode(16...38)(
[StringNode(19...22)(nil, (19...22), nil, "foo"),
InterpolatedStringNode(0...37)(
InterpolatedStringNode(23...37)(
nil,
[EmbeddedStatementsNode(23...29)(
(23...25),

View File

@ -6,8 +6,8 @@ ProgramNode(0...23)(
nil,
(0...1),
nil,
ArgumentsNode(2...20)(
[InterpolatedStringNode(2...20)((2...10), [], (14...20))]
ArgumentsNode(2...10)(
[InterpolatedStringNode(2...10)((2...10), [], (14...20))]
),
nil,
BlockNode(11...23)([], nil, nil, (11...13), (20...23)),

View File

@ -11,7 +11,7 @@ ProgramNode(0...16)(
(5...6)
),
ArrayNode(8...16)(
[InterpolatedStringNode(0...15)(
[InterpolatedStringNode(11...15)(
nil,
[EmbeddedStatementsNode(11...15)(
(11...13),

View File

@ -1,13 +1,13 @@
ProgramNode(0...327)(
ProgramNode(0...309)(
[],
StatementsNode(0...327)(
[CallNode(0...28)(
StatementsNode(0...309)(
[CallNode(0...8)(
nil,
nil,
(0...1),
nil,
ArgumentsNode(2...28)(
[InterpolatedStringNode(2...28)(
ArgumentsNode(2...8)(
[InterpolatedStringNode(2...8)(
(2...8),
[StringNode(9...17)(nil, (9...17), nil, " x\n"),
EmbeddedStatementsNode(17...25)(
@ -26,13 +26,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(29...55)(
CallNode(29...37)(
nil,
nil,
(29...30),
nil,
ArgumentsNode(31...55)(
[InterpolatedStringNode(31...55)(
ArgumentsNode(31...37)(
[InterpolatedStringNode(31...37)(
(31...37),
[StringNode(38...46)(nil, (38...46), nil, " x\n"),
EmbeddedStatementsNode(46...52)(
@ -61,13 +61,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(56...78)(
CallNode(56...62)(
nil,
nil,
(56...57),
nil,
ArgumentsNode(58...78)(
[InterpolatedStringNode(58...78)(
ArgumentsNode(58...62)(
[InterpolatedStringNode(58...62)(
(58...62),
[StringNode(63...76)(nil, (63...76), nil, "x\n" + "y\n")],
(76...78)
@ -78,13 +78,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(79...97)(
CallNode(79...85)(
nil,
nil,
(79...80),
nil,
ArgumentsNode(81...97)(
[InterpolatedStringNode(81...97)(
ArgumentsNode(81...85)(
[InterpolatedStringNode(81...85)(
(81...85),
[StringNode(86...95)(nil, (86...95), nil, "\tx\n" + "y\n")],
(95...97)
@ -95,13 +95,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(98...124)(
CallNode(98...104)(
nil,
nil,
(98...99),
nil,
ArgumentsNode(100...124)(
[InterpolatedStringNode(100...124)(
ArgumentsNode(100...104)(
[InterpolatedStringNode(100...104)(
(100...104),
[StringNode(105...122)(nil, (105...122), nil, "x\n" + "y\n")],
(122...124)
@ -112,13 +112,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(125...148)(
CallNode(125...131)(
nil,
nil,
(125...126),
nil,
ArgumentsNode(127...148)(
[InterpolatedStringNode(127...148)(
ArgumentsNode(127...131)(
[InterpolatedStringNode(127...131)(
(127...131),
[StringNode(132...146)(nil, (132...146), nil, "\tx\n" + "y\n")],
(146...148)
@ -129,13 +129,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(149...170)(
CallNode(149...155)(
nil,
nil,
(149...150),
nil,
ArgumentsNode(151...170)(
[InterpolatedStringNode(151...170)(
ArgumentsNode(151...155)(
[InterpolatedStringNode(151...155)(
(151...155),
[StringNode(156...168)(nil, (156...168), nil, " x\n" + "\ty\n")],
(168...170)
@ -146,13 +146,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(171...193)(
CallNode(171...177)(
nil,
nil,
(171...172),
nil,
ArgumentsNode(173...193)(
[InterpolatedStringNode(173...193)(
ArgumentsNode(173...177)(
[InterpolatedStringNode(173...177)(
(173...177),
[StringNode(178...191)(nil, (178...191), nil, " x\n" + " y\n")],
(191...193)
@ -163,26 +163,26 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(194...205)(
CallNode(194...200)(
nil,
nil,
(194...195),
nil,
ArgumentsNode(196...205)(
[InterpolatedStringNode(196...205)((196...200), [], (201...205))]
ArgumentsNode(196...200)(
[InterpolatedStringNode(196...200)((196...200), [], (201...205))]
),
nil,
nil,
0,
"p"
),
CallNode(206...222)(
CallNode(206...212)(
nil,
nil,
(206...207),
nil,
ArgumentsNode(208...222)(
[InterpolatedStringNode(208...222)(
ArgumentsNode(208...212)(
[InterpolatedStringNode(208...212)(
(208...212),
[StringNode(213...220)(
nil,
@ -198,13 +198,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(223...241)(
CallNode(223...229)(
nil,
nil,
(223...224),
nil,
ArgumentsNode(225...241)(
[InterpolatedStringNode(225...241)(
ArgumentsNode(225...229)(
[InterpolatedStringNode(225...229)(
(225...229),
[StringNode(230...239)(
nil,
@ -220,13 +220,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(242...261)(
CallNode(242...248)(
nil,
nil,
(242...243),
nil,
ArgumentsNode(244...261)(
[InterpolatedStringNode(244...261)(
ArgumentsNode(244...248)(
[InterpolatedStringNode(244...248)(
(244...248),
[StringNode(249...259)(nil, (249...259), nil, "x\n" + " y\n")],
(259...261)
@ -237,13 +237,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(262...275)(
CallNode(262...268)(
nil,
nil,
(262...263),
nil,
ArgumentsNode(264...275)(
[InterpolatedStringNode(264...275)(
ArgumentsNode(264...268)(
[InterpolatedStringNode(264...268)(
(264...268),
[StringNode(269...273)(nil, (269...273), nil, "x\n")],
(273...275)
@ -254,13 +254,13 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(276...290)(
CallNode(276...282)(
nil,
nil,
(276...277),
nil,
ArgumentsNode(278...290)(
[InterpolatedStringNode(278...290)(
ArgumentsNode(278...282)(
[InterpolatedStringNode(278...282)(
(278...282),
[StringNode(283...288)(nil, (283...288), nil, "ð\n")],
(288...290)
@ -271,26 +271,26 @@ ProgramNode(0...327)(
0,
"p"
),
CallNode(291...300)(
CallNode(291...297)(
nil,
nil,
(291...292),
nil,
ArgumentsNode(293...300)(
[InterpolatedStringNode(293...300)((293...297), [], (298...300))]
ArgumentsNode(293...297)(
[InterpolatedStringNode(293...297)((293...297), [], (298...300))]
),
nil,
nil,
0,
"p"
),
CallNode(301...327)(
CallNode(301...309)(
nil,
nil,
(301...302),
nil,
ArgumentsNode(303...327)(
[InterpolatedXStringNode(303...327)(
ArgumentsNode(303...309)(
[InterpolatedXStringNode(303...309)(
(303...309),
[StringNode(310...318)(nil, (310...318), nil, " x\n"),
EmbeddedStatementsNode(318...324)(

View File

@ -1,7 +1,7 @@
ProgramNode(0...27)(
ProgramNode(0...8)(
[],
StatementsNode(0...27)(
[InterpolatedStringNode(0...27)(
StatementsNode(0...8)(
[InterpolatedStringNode(0...8)(
(0...8),
[StringNode(9...23)(nil, (9...23), nil, "baz\\\n" + "qux\n")],
(23...27)

View File

@ -1,7 +1,7 @@
ProgramNode(0...26)(
ProgramNode(0...8)(
[],
StatementsNode(0...26)(
[InterpolatedStringNode(0...26)(
StatementsNode(0...8)(
[InterpolatedStringNode(0...8)(
(0...8),
[StringNode(9...22)(nil, (9...22), nil, "baz\\\n" + "qux\n")],
(22...26)

View File

@ -1,17 +1,17 @@
ProgramNode(0...66)(
ProgramNode(0...52)(
[],
StatementsNode(0...66)(
[InterpolatedStringNode(0...22)(
StatementsNode(0...52)(
[InterpolatedStringNode(0...8)(
(0...8),
[StringNode(9...17)(nil, (9...17), nil, "foo\n" + "bar\n")],
(17...22)
),
InterpolatedStringNode(23...43)(
InterpolatedStringNode(23...29)(
(23...29),
[StringNode(30...38)(nil, (30...38), nil, "foo\n" + "bar\n")],
(38...43)
),
InterpolatedXStringNode(44...66)(
InterpolatedXStringNode(44...52)(
(44...52),
[StringNode(53...61)(nil, (53...61), nil, "foo\n" + "bar\n")],
(61...66)

View File

@ -1,6 +1,6 @@
ProgramNode(1...444)(
ProgramNode(1...433)(
[],
StatementsNode(1...444)(
StatementsNode(1...433)(
[StringNode(1...6)((1...2), (2...5), (5...6), "\#@1"),
StringNode(9...15)((9...10), (10...14), (14...15), "\#@@1"),
ArrayNode(18...25)(
@ -89,32 +89,32 @@ ProgramNode(1...444)(
SymbolNode(296...303)((296...298), (298...302), (302...303), "\#@@1"),
XStringNode(306...311)((306...307), (307...310), (310...311), "\#@1"),
XStringNode(314...320)((314...315), (315...319), (319...320), "\#@@1"),
InterpolatedStringNode(322...341)(
InterpolatedStringNode(322...331)(
(322...331),
[StringNode(332...336)(nil, (332...336), nil, "\#@1\n")],
(336...341)
),
InterpolatedStringNode(342...362)(
InterpolatedStringNode(342...351)(
(342...351),
[StringNode(352...357)(nil, (352...357), nil, "\#@@1\n")],
(357...362)
),
InterpolatedStringNode(363...382)(
InterpolatedStringNode(363...372)(
(363...372),
[StringNode(373...377)(nil, (373...377), nil, "\#@1\n")],
(377...382)
),
InterpolatedStringNode(383...403)(
InterpolatedStringNode(383...392)(
(383...392),
[StringNode(393...398)(nil, (393...398), nil, "\#@@1\n")],
(398...403)
),
InterpolatedXStringNode(404...423)(
InterpolatedXStringNode(404...413)(
(404...413),
[StringNode(414...418)(nil, (414...418), nil, "\#@1\n")],
(418...423)
),
InterpolatedXStringNode(424...444)(
InterpolatedXStringNode(424...433)(
(424...433),
[StringNode(434...439)(nil, (434...439), nil, "\#@@1\n")],
(439...444)

View File

@ -1,9 +1,9 @@
ProgramNode(0...24)(
ProgramNode(0...6)(
[],
StatementsNode(0...24)(
[InterpolatedStringNode(0...24)(
StatementsNode(0...6)(
[InterpolatedStringNode(0...6)(
(0...6),
[StringNode(7...20)(nil, (7...20), nil, "baz\n" + "qux\n")],
[StringNode(7...20)(nil, (7...20), nil, "bazqux\n")],
(20...24)
)]
)

View File

@ -1,10 +1,9 @@
ProgramNode(0...19)(
ProgramNode(0...7)(
[],
StatementsNode(0...19)(
[InterpolatedStringNode(0...19)(
StatementsNode(0...7)(
[InterpolatedStringNode(0...7)(
(0...7),
[StringNode(8...10)(nil, (8...10), nil, ""),
EmbeddedStatementsNode(10...13)((10...12), nil, (12...13)),
[EmbeddedStatementsNode(10...13)((10...12), nil, (12...13)),
StringNode(13...14)(nil, (13...14), nil, "\n")],
(14...19)
)]

View File

@ -1,15 +1,15 @@
ProgramNode(0...210)(
[],
StatementsNode(0...210)(
[StringNode(0...6)((0...1), (1...5), (5...6), "a\n" + "b"),
[StringNode(0...6)((0...1), (1...5), (5...6), "ab"),
ArrayNode(8...16)(
[SymbolNode(11...15)(nil, (11...15), nil, "a\n" + "b")],
[SymbolNode(11...15)(nil, (11...15), nil, "ab")],
(8...11),
(15...16)
),
StringNode(18...26)((18...21), (21...25), (25...26), "a\n" + "b"),
StringNode(18...26)((18...21), (21...25), (25...26), "ab"),
ArrayNode(28...36)(
[StringNode(31...35)(nil, (31...35), nil, "a\n" + "b")],
[StringNode(31...35)(nil, (31...35), nil, "ab")],
(28...31),
(35...36)
),
@ -19,21 +19,15 @@ ProgramNode(0...210)(
(45...46)
),
StringNode(48...56)((48...51), (51...55), (55...56), "a\\\n" + "b"),
RegularExpressionNode(58...66)(
(58...61),
(61...65),
(65...66),
"a\n" + "b",
0
),
SymbolNode(68...76)((68...71), (71...75), (75...76), "a\n" + "b"),
RegularExpressionNode(58...66)((58...61), (61...65), (65...66), "ab", 0),
SymbolNode(68...76)((68...71), (71...75), (75...76), "ab"),
ArrayNode(78...86)(
[StringNode(81...85)(nil, (81...85), nil, "a\\\n" + "b")],
(78...81),
(85...86)
),
XStringNode(88...96)((88...91), (91...95), (95...96), "a\n" + "b"),
StringNode(98...105)((98...100), (100...104), (104...105), "a\n" + "b"),
XStringNode(88...96)((88...91), (91...95), (95...96), "ab"),
StringNode(98...105)((98...100), (100...104), (104...105), "ab"),
StringNode(107...113)(
(107...108),
(108...112),
@ -44,31 +38,26 @@ ProgramNode(0...210)(
(115...116),
(116...120),
(120...121),
"a\n" + "b",
"ab",
0
),
SymbolNode(123...130)(nil, (125...129), nil, "a\n" + "b"),
SymbolNode(132...139)((132...134), (134...138), (138...139), "a\n" + "b"),
InterpolatedStringNode(141...161)(
SymbolNode(123...130)(nil, (125...129), nil, "ab"),
SymbolNode(132...139)((132...134), (134...138), (138...139), "ab"),
InterpolatedStringNode(141...150)(
(141...150),
[StringNode(151...156)(nil, (151...156), nil, "a\n" + "b\n")],
[StringNode(151...156)(nil, (151...156), nil, "ab\n")],
(156...161)
),
InterpolatedStringNode(162...182)(
InterpolatedStringNode(162...171)(
(162...171),
[StringNode(172...177)(nil, (172...177), nil, "a\\\n" + "b\n")],
(177...182)
),
InterpolatedXStringNode(183...203)(
InterpolatedXStringNode(183...192)(
(183...192),
[StringNode(193...198)(nil, (193...198), nil, "a\n" + "b\n")],
[StringNode(193...198)(nil, (193...198), nil, "ab\n")],
(198...203)
),
XStringNode(204...210)(
(204...205),
(205...209),
(209...210),
"a\n" + "b"
)]
XStringNode(204...210)((204...205), (205...209), (209...210), "ab")]
)
)

View File

@ -1,15 +1,15 @@
ProgramNode(0...21)(
ProgramNode(0...8)(
[],
StatementsNode(0...21)(
[CallNode(0...21)(
StatementsNode(0...8)(
[CallNode(0...8)(
nil,
nil,
(0...1),
nil,
ArgumentsNode(2...21)(
[InterpolatedStringNode(2...21)(
ArgumentsNode(2...8)(
[InterpolatedStringNode(2...8)(
(2...8),
[StringNode(9...19)(nil, (9...19), nil, "x\n" + " y\n")],
[StringNode(9...19)(nil, (9...19), nil, "x\n" + " y\n")],
(19...21)
)]
),

View File

@ -8,7 +8,7 @@ ProgramNode(0...12)(
nil,
ArgumentsNode(2...12)(
[StringConcatNode(2...12)(
InterpolatedStringNode(2...19)(
InterpolatedStringNode(2...6)(
(2...6),
[StringNode(13...17)(nil, (13...17), nil, "x\n")],
(17...19)

View File

@ -1,19 +1,14 @@
ProgramNode(0...56)(
ProgramNode(0...33)(
[],
StatementsNode(0...56)(
[InterpolatedStringNode(0...27)(
StatementsNode(0...33)(
[InterpolatedStringNode(0...4)(
(0...4),
[StringNode(5...25)(
nil,
(5...25),
nil,
" 1 \n" + " 2\n" + " 3\n"
)],
[StringNode(5...25)(nil, (5...25), nil, " 1 2\n" + " 3\n")],
(25...27)
),
InterpolatedStringNode(29...56)(
InterpolatedStringNode(29...33)(
(29...33),
[StringNode(34...54)(nil, (34...54), nil, "1 \n" + "2\n" + "3\n")],
[StringNode(34...54)(nil, (34...54), nil, "1 2\n" + "3\n")],
(54...56)
)]
)

View File

@ -1526,7 +1526,7 @@ void yp_serialize_comment(yp_parser_t *parser, yp_comment_t *comment, yp_buffer_
}
void yp_serialize_comment_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) {
yp_buffer_append_u32(buffer, yp_list_size(&list));
yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list)));
yp_comment_t *comment;
for (comment = (yp_comment_t *) list.head; comment != NULL; comment = (yp_comment_t *) comment->node.next) {
@ -1546,7 +1546,7 @@ void yp_serialize_diagnostic(yp_parser_t *parser, yp_diagnostic_t *diagnostic, y
}
void yp_serialize_diagnostic_list(yp_parser_t *parser, yp_list_t list, yp_buffer_t *buffer) {
yp_buffer_append_u32(buffer, yp_list_size(&list));
yp_buffer_append_u32(buffer, yp_sizet_to_u32(yp_list_size(&list)));
yp_diagnostic_t *diagnostic;
for (diagnostic = (yp_diagnostic_t *) list.head; diagnostic != NULL; diagnostic = (yp_diagnostic_t *) diagnostic->node.next) {

View File

@ -180,22 +180,6 @@ unescape_char(const unsigned char value, const unsigned char flags) {
static const char *
unescape(char *dest, size_t *dest_length, const char *backslash, const char *end, yp_list_t *error_list, const unsigned char flags, bool write_to_str) {
switch (backslash[1]) {
// \a \b \e \f \n \r \s \t \v
case '\r': {
// if this is an \r\n we need to escape both
if (write_to_str) {
dest[(*dest_length)++] = (char) unescape_char(unescape_chars[(unsigned char) backslash[1]], flags);
}
if (backslash + 2 < end && backslash[2] == '\n') {
if (write_to_str) {
dest[(*dest_length)++] = (char) unescape_char(unescape_chars[(unsigned char) backslash[2]], flags);
}
return backslash + 3;
}
return backslash + 2;
}
case 'a':
case 'b':
case 'e':
@ -398,14 +382,23 @@ unescape(char *dest, size_t *dest_length, const char *backslash, const char *end
yp_diagnostic_list_append(error_list, backslash, backslash + 2, "Invalid meta escape sequence");
return backslash + 3;
}
// In this case we're escaping something that doesn't need escaping.
default:
{
if (write_to_str) {
dest[(*dest_length)++] = backslash[1];
}
return backslash + 2;
// \n
case '\n':
return backslash + 2;
// \r
case '\r':
if (backslash + 2 < end && backslash[2] == '\n') {
return backslash + 3;
}
/* fallthrough */
// In this case we're escaping something that doesn't need escaping.
default: {
if (write_to_str) {
dest[(*dest_length)++] = backslash[1];
}
return backslash + 2;
}
}
}
@ -438,26 +431,24 @@ unescape(char *dest, size_t *dest_length, const char *backslash, const char *end
// \c? or \C-? delete, ASCII 7Fh (DEL)
//
YP_EXPORTED_FUNCTION void
yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t length, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list) {
yp_unescape_manipulate_string(yp_parser_t *parser, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list) {
if (unescape_type == YP_UNESCAPE_NONE) {
// If we're not unescaping then we can reference the source directly.
yp_string_shared_init(string, value, value + length);
return;
}
const char *backslash = yp_memchr(value, '\\', length, parser->encoding_changed, &parser->encoding);
const char *backslash = yp_memchr(string->source, '\\', string->length, parser->encoding_changed, &parser->encoding);
if (backslash == NULL) {
// Here there are no escapes, so we can reference the source directly.
yp_string_shared_init(string, value, value + length);
return;
}
// Here we have found an escape character, so we need to handle all escapes
// within the string.
char *allocated = malloc(length);
char *allocated = malloc(string->length);
if (allocated == NULL) {
yp_diagnostic_list_append(error_list, value, value + length, "Failed to allocate memory for unescaping.");
yp_diagnostic_list_append(error_list, string->source, string->source + string->length, "Failed to allocate memory for unescaping.");
return;
}
@ -468,13 +459,13 @@ yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t len
// This is the current position in the source string that we're looking at.
// It's going to move along behind the backslash so that we can copy each
// segment of the string that doesn't contain an escape.
const char *cursor = value;
const char *end = value + length;
const char *cursor = string->source;
const char *end = string->source + string->length;
// For each escape found in the source string, we will handle it and update
// the moving cursor->backslash window.
while (backslash != NULL && backslash + 1 < end) {
assert(dest_length < length);
assert(dest_length < string->length);
// This is the size of the segment of the string from the previous escape
// or the start of the string to the current escape.
@ -520,6 +511,10 @@ yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t len
cursor = end;
}
// If the string was already allocated, then we need to free that memory
// here. That's because we're about to override it with the escaped string.
yp_string_free(string);
// We also need to update the length at the end. This is because every escape
// reduces the length of the final string, and we don't want garbage at the
// end.
@ -530,13 +525,12 @@ YP_EXPORTED_FUNCTION bool
yp_unescape_string(const char *start, size_t length, yp_unescape_type_t unescape_type, yp_string_t *result) {
bool success;
yp_list_t error_list;
yp_list_init(&error_list);
yp_parser_t parser;
yp_parser_init(&parser, start, length, "");
yp_unescape_manipulate_string(&parser, start, length, result, unescape_type, &error_list);
yp_list_t error_list = YP_LIST_EMPTY;
yp_string_shared_init(result, start, start + length);
yp_unescape_manipulate_string(&parser, result, unescape_type, &error_list);
success = yp_list_empty_p(&error_list);
yp_list_free(&error_list);

View File

@ -31,7 +31,7 @@ typedef enum {
// Unescape the contents of the given token into the given string using the
// given unescape mode.
YP_EXPORTED_FUNCTION void yp_unescape_manipulate_string(yp_parser_t *parser, const char *value, size_t length, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list);
YP_EXPORTED_FUNCTION void yp_unescape_manipulate_string(yp_parser_t *parser, yp_string_t *string, yp_unescape_type_t unescape_type, yp_list_t *error_list);
// Accepts a source string and a type of unescaping and returns the unescaped version.
// The caller must yp_string_free(result); after calling this function.

View File

@ -51,6 +51,9 @@ typedef struct {
size_t capacity;
} yp_constant_pool_t;
// Define an empty constant pool.
#define YP_CONSTANT_POOL_EMPTY ((yp_constant_pool_t) { .constants = NULL, .size = 0, .capacity = 0 })
// Initialize a new constant pool with a given capacity.
bool yp_constant_pool_init(yp_constant_pool_t *pool, size_t capacity);

View File

@ -1,28 +1,15 @@
#include "yarp/util/yp_list.h"
// Initializes a new list.
YP_EXPORTED_FUNCTION void
yp_list_init(yp_list_t *list) {
*list = (yp_list_t) { .head = NULL, .tail = NULL };
}
// Returns true if the given list is empty.
YP_EXPORTED_FUNCTION bool
yp_list_empty_p(yp_list_t *list) {
return list->head == NULL;
}
YP_EXPORTED_FUNCTION uint32_t
// Returns the size of the list.
YP_EXPORTED_FUNCTION size_t
yp_list_size(yp_list_t *list) {
yp_list_node_t *node = list->head;
uint32_t length = 0;
while (node != NULL) {
length++;
node = node->next;
}
return length;
return list->size;
}
// Append a node to the given list.
@ -33,7 +20,9 @@ yp_list_append(yp_list_t *list, yp_list_node_t *node) {
} else {
list->tail->next = node;
}
list->tail = node;
list->size++;
}
// Deallocate the internal state of the given list.
@ -47,4 +36,6 @@ yp_list_free(yp_list_t *list) {
free(node);
node = next;
}
list->size = 0;
}

View File

@ -15,9 +15,7 @@
// int value;
// } yp_int_node_t;
//
// yp_list_t list;
// yp_list_init(&list);
//
// yp_list_t list = YP_LIST_EMPTY;
// yp_int_node_t *node = malloc(sizeof(yp_int_node_t));
// node->value = 5;
//
@ -45,18 +43,20 @@ typedef struct yp_list_node {
// This represents the overall linked list. It keeps a pointer to the head and
// tail so that iteration is easy and pushing new nodes is easy.
typedef struct {
size_t size;
yp_list_node_t *head;
yp_list_node_t *tail;
} yp_list_t;
// Initializes a new list.
YP_EXPORTED_FUNCTION void yp_list_init(yp_list_t *list);
// This represents an empty list. It's used to initialize a stack-allocated list
// as opposed to a method call.
#define YP_LIST_EMPTY ((yp_list_t) { .size = 0, .head = NULL, .tail = NULL })
// Returns true if the given list is empty.
YP_EXPORTED_FUNCTION bool yp_list_empty_p(yp_list_t *list);
// Returns the size of the list in O(n) time.
YP_EXPORTED_FUNCTION uint32_t yp_list_size(yp_list_t *list);
// Returns the size of the list.
YP_EXPORTED_FUNCTION size_t yp_list_size(yp_list_t *list);
// Append a node to the given list.
void yp_list_append(yp_list_t *list, yp_list_node_t *node);

View File

@ -35,6 +35,10 @@ typedef struct {
size_t column;
} yp_line_column_t;
#define YP_NEWLINE_LIST_EMPTY ((yp_newline_list_t) { \
.start = NULL, .offsets = NULL, .size = 0, .capacity = 0, .last_offset = 0, .last_index = 0 \
})
// Initialize a new newline list with the given capacity. Returns true if the
// allocation of the offsets succeeds, otherwise returns false.
bool yp_newline_list_init(yp_newline_list_t *list, const char *start, size_t capacity);

View File

@ -1,11 +1,5 @@
#include "yarp/util/yp_state_stack.h"
// Initializes the state stack to an empty stack.
void
yp_state_stack_init(yp_state_stack_t *stack) {
*stack = 0;
}
// Pushes a value onto the stack.
void
yp_state_stack_push(yp_state_stack_t *stack, bool value) {

View File

@ -10,7 +10,7 @@
typedef uint32_t yp_state_stack_t;
// Initializes the state stack to an empty stack.
void yp_state_stack_init(yp_state_stack_t *stack);
#define YP_STATE_STACK_EMPTY ((yp_state_stack_t) 0)
// Pushes a value onto the stack.
void yp_state_stack_push(yp_state_stack_t *stack, bool value);

View File

@ -2706,6 +2706,10 @@ yp_interpolated_string_node_create(yp_parser_t *parser, const yp_token_t *openin
// Append a part to an InterpolatedStringNode node.
static inline void
yp_interpolated_string_node_append(yp_interpolated_string_node_t *node, yp_node_t *part) {
if (node->parts.size == 0 && node->opening_loc.start == NULL) {
node->base.location.start = part->location.start;
}
yp_node_list_append(&node->parts, part);
node->base.location.end = part->location.end;
}
@ -3934,10 +3938,10 @@ yp_symbol_node_label_create(yp_parser_t *parser, const yp_token_t *token) {
yp_token_t label = { .type = YP_TOKEN_LABEL, .start = token->start, .end = token->end - 1 };
node = yp_symbol_node_create(parser, &opening, &label, &closing);
ptrdiff_t length = label.end - label.start;
assert(length >= 0);
assert((label.end - label.start) >= 0);
yp_string_shared_init(&node->unescaped, label.start, label.end);
yp_unescape_manipulate_string(parser, label.start, (size_t) length, &node->unescaped, YP_UNESCAPE_ALL, &parser->error_list);
yp_unescape_manipulate_string(parser, &node->unescaped, YP_UNESCAPE_ALL, &parser->error_list);
break;
}
case YP_TOKEN_MISSING: {
@ -7203,11 +7207,16 @@ parser_lex(yp_parser_t *parser) {
break;
}
case '\\': {
// If we hit escapes, then we need to treat the next token
// literally. In this case we'll skip past the next character and
// find the next breakpoint.
if (breakpoint[1] == '\n') {
// If we hit an escape, then we need to skip past
// however many characters the escape takes up. However
// it's important that if \n or \r\n are escaped that we
// stop looping before the newline and not after the
// newline so that we can still potentially find the
// terminator of the heredoc.
if (breakpoint + 1 < parser->end && breakpoint[1] == '\n') {
breakpoint++;
} else if (breakpoint + 2 < parser->end && breakpoint[1] == '\r' && breakpoint[2] == '\n') {
breakpoint += 2;
} else {
yp_unescape_type_t unescape_type = (quote == YP_HEREDOC_QUOTE_SINGLE) ? YP_UNESCAPE_MINIMAL : YP_UNESCAPE_ALL;
size_t difference = yp_unescape_calculate_difference(breakpoint, parser->end, unescape_type, false, &parser->error_list);
@ -7218,6 +7227,7 @@ parser_lex(yp_parser_t *parser) {
breakpoint = yp_strpbrk(parser, breakpoint + difference, breakpoints, parser->end - (breakpoint + difference));
}
break;
}
case '#': {
@ -7264,10 +7274,10 @@ static yp_regular_expression_node_t *
yp_regular_expression_node_create_and_unescape(yp_parser_t *parser, const yp_token_t *opening, const yp_token_t *content, const yp_token_t *closing, yp_unescape_type_t unescape_type) {
yp_regular_expression_node_t *node = yp_regular_expression_node_create(parser, opening, content, closing);
ptrdiff_t length = content->end - content->start;
assert(length >= 0);
assert((content->end - content->start) >= 0);
yp_string_shared_init(&node->unescaped, content->start, content->end);
yp_unescape_manipulate_string(parser, content->start, (size_t) length, &node->unescaped, unescape_type, &parser->error_list);
yp_unescape_manipulate_string(parser, &node->unescaped, unescape_type, &parser->error_list);
return node;
}
@ -7275,10 +7285,10 @@ static yp_symbol_node_t *
yp_symbol_node_create_and_unescape(yp_parser_t *parser, const yp_token_t *opening, const yp_token_t *content, const yp_token_t *closing, yp_unescape_type_t unescape_type) {
yp_symbol_node_t *node = yp_symbol_node_create(parser, opening, content, closing);
ptrdiff_t length = content->end - content->start;
assert(length >= 0);
assert((content->end - content->start) >= 0);
yp_string_shared_init(&node->unescaped, content->start, content->end);
yp_unescape_manipulate_string(parser, content->start, (size_t) length, &node->unescaped, unescape_type, &parser->error_list);
yp_unescape_manipulate_string(parser, &node->unescaped, unescape_type, &parser->error_list);
return node;
}
@ -7286,10 +7296,10 @@ static yp_string_node_t *
yp_string_node_create_and_unescape(yp_parser_t *parser, const yp_token_t *opening, const yp_token_t *content, const yp_token_t *closing, yp_unescape_type_t unescape_type) {
yp_string_node_t *node = yp_string_node_create(parser, opening, content, closing);
ptrdiff_t length = content->end - content->start;
assert(length >= 0);
assert((content->end - content->start) >= 0);
yp_string_shared_init(&node->unescaped, content->start, content->end);
yp_unescape_manipulate_string(parser, content->start, (size_t) length, &node->unescaped, unescape_type, &parser->error_list);
yp_unescape_manipulate_string(parser, &node->unescaped, unescape_type, &parser->error_list);
return node;
}
@ -7297,10 +7307,10 @@ static yp_x_string_node_t *
yp_xstring_node_create_and_unescape(yp_parser_t *parser, const yp_token_t *opening, const yp_token_t *content, const yp_token_t *closing) {
yp_x_string_node_t *node = yp_xstring_node_create(parser, opening, content, closing);
ptrdiff_t length = content->end - content->start;
assert(length >= 0);
assert((content->end - content->start) >= 0);
yp_string_shared_init(&node->unescaped, content->start, content->end);
yp_unescape_manipulate_string(parser, content->start, (size_t) length, &node->unescaped, YP_UNESCAPE_ALL, &parser->error_list);
yp_unescape_manipulate_string(parser, &node->unescaped, YP_UNESCAPE_ALL, &parser->error_list);
return node;
}
@ -9172,7 +9182,12 @@ parse_string_part(yp_parser_t *parser) {
yp_unescape_type_t unescape_type = YP_UNESCAPE_ALL;
if (parser->lex_modes.current->mode == YP_LEX_HEREDOC) {
if (parser->lex_modes.current->as.heredoc.quote == YP_HEREDOC_QUOTE_SINGLE) {
if (parser->lex_modes.current->as.heredoc.indent == YP_HEREDOC_INDENT_TILDE) {
// If we're in a tilde heredoc, we want to unescape it later
// because we don't want unescaped newlines to disappear
// before we handle them in the dedent.
unescape_type = YP_UNESCAPE_NONE;
} else if (parser->lex_modes.current->as.heredoc.quote == YP_HEREDOC_QUOTE_SINGLE) {
unescape_type = YP_UNESCAPE_MINIMAL;
}
}
@ -9545,14 +9560,30 @@ parse_heredoc_dedent(yp_parser_t *parser, yp_node_t *node, yp_heredoc_quote_t qu
int common_whitespace;
if ((common_whitespace = parse_heredoc_common_whitespace(parser, nodes)) <= 0) return;
// Iterate over all nodes, and trim whitespace accordingly.
for (size_t index = 0; index < nodes->size; index++) {
yp_node_t *node = nodes->nodes[index];
if (!YP_NODE_TYPE_P(node, YP_NODE_STRING_NODE)) continue;
// The next node should be dedented if it's the first node in the list or if
// if follows a string node.
bool dedent_next = true;
// Iterate over all nodes, and trim whitespace accordingly. We're going to
// keep around two indices: a read and a write. If we end up trimming all of
// the whitespace from a node, then we'll drop it from the list entirely.
size_t write_index = 0;
for (size_t read_index = 0; read_index < nodes->size; read_index++) {
yp_node_t *node = nodes->nodes[read_index];
// We're not manipulating child nodes that aren't strings. In this case
// we'll skip past it and indicate that the subsequent node should not
// be dedented.
if (!YP_NODE_TYPE_P(node, YP_NODE_STRING_NODE)) {
nodes->nodes[write_index++] = node;
dedent_next = false;
continue;
}
// Get a reference to the string struct that is being held by the string
// node. This is the value we're going to actual manipulate.
yp_string_t *string = &((yp_string_node_t *) node)->unescaped;
yp_string_t *string = &(((yp_string_node_t *) node)->unescaped);
yp_string_ensure_owned(string);
// Now get the bounds of the existing string. We'll use this as a
@ -9568,7 +9599,6 @@ parse_heredoc_dedent(yp_parser_t *parser, yp_node_t *node, yp_heredoc_quote_t qu
// whitespace, so we'll maintain a pointer to the current position in the
// string that we're writing to.
char *dest_cursor = source_start;
bool dedent_next = (index == 0) || YP_NODE_TYPE_P(nodes->nodes[index - 1], YP_NODE_STRING_NODE);
while (source_cursor < source_end) {
// If we need to dedent the next element within the heredoc or the next
@ -9613,8 +9643,20 @@ parse_heredoc_dedent(yp_parser_t *parser, yp_node_t *node, yp_heredoc_quote_t qu
dedent_next = true;
}
string->length = dest_length;
// We only want to write this node into the list if it has any content.
if (dest_length == 0) {
yp_node_destroy(parser, node);
} else {
string->length = dest_length;
yp_unescape_manipulate_string(parser, string, (quote == YP_HEREDOC_QUOTE_SINGLE) ? YP_UNESCAPE_MINIMAL : YP_UNESCAPE_ALL, &parser->error_list);
nodes->nodes[write_index++] = node;
}
// We always dedent the next node if it follows a string node.
dedent_next = true;
}
nodes->size = write_index;
}
static yp_node_t *
@ -10673,12 +10715,15 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
lex_state_set(parser, YP_LEX_STATE_END);
expect(parser, YP_TOKEN_HEREDOC_END, "Expected a closing delimiter for heredoc.");
if (quote == YP_HEREDOC_QUOTE_BACKTICK) {
assert(YP_NODE_TYPE_P(node, YP_NODE_INTERPOLATED_X_STRING_NODE));
yp_interpolated_xstring_node_closing_set(((yp_interpolated_x_string_node_t *) node), &parser->previous);
node->location = ((yp_interpolated_x_string_node_t *) node)->opening_loc;
} else {
assert(YP_NODE_TYPE_P(node, YP_NODE_INTERPOLATED_STRING_NODE));
yp_interpolated_string_node_closing_set((yp_interpolated_string_node_t *) node, &parser->previous);
node->location = ((yp_interpolated_string_node_t *) node)->opening_loc;
}
// If this is a heredoc that is indented with a ~, then we need to dedent
@ -13190,6 +13235,8 @@ yp_parser_init(yp_parser_t *parser, const char *source, size_t size, const char
.enclosure_nesting = 0,
.lambda_enclosure_nesting = -1,
.brace_nesting = 0,
.do_loop_stack = YP_STATE_STACK_EMPTY,
.accepts_block_stack = YP_STATE_STACK_EMPTY,
.lex_modes = {
.index = 0,
.stack = {{ .mode = YP_LEX_DEFAULT }},
@ -13201,6 +13248,9 @@ yp_parser_init(yp_parser_t *parser, const char *source, size_t size, const char
.current = { .type = YP_TOKEN_EOF, .start = source, .end = source },
.next_start = NULL,
.heredoc_end = NULL,
.comment_list = YP_LIST_EMPTY,
.warning_list = YP_LIST_EMPTY,
.error_list = YP_LIST_EMPTY,
.current_scope = NULL,
.current_context = NULL,
.recovering = false,
@ -13213,16 +13263,12 @@ yp_parser_init(yp_parser_t *parser, const char *source, size_t size, const char
.pattern_matching_newlines = false,
.in_keyword_arg = false,
.filepath_string = filepath_string,
.constant_pool = YP_CONSTANT_POOL_EMPTY,
.newline_list = YP_NEWLINE_LIST_EMPTY
};
yp_state_stack_init(&parser->do_loop_stack);
yp_state_stack_init(&parser->accepts_block_stack);
yp_accepts_block_stack_push(parser, true);
yp_list_init(&parser->warning_list);
yp_list_init(&parser->error_list);
yp_list_init(&parser->comment_list);
// Initialize the constant pool. We're going to completely guess as to the
// number of constants that we'll need based on the size of the input. The
// ratio we chose here is actually less arbitrary than you might think.