Skip to content

Commit b607e3a

Browse files
committed
Handle empty programs in ripper translation
1 parent a35eadc commit b607e3a

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lib/prism/translation/ripper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,9 @@ def visit_pre_execution_node(node)
22162216

22172217
# The top-level program node.
22182218
def visit_program_node(node)
2219-
statements = visit(node.statements)
2219+
body = node.statements.body
2220+
body << nil if body.empty?
2221+
statements = visit_statements_node_body(body)
22202222

22212223
bounds(node.location)
22222224
on_program(statements)

test/prism/ripper_test.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,16 @@ class RipperTest < TestCase
2424
"seattlerb/parse_pattern_058.txt",
2525

2626
# Ripper cannot handle named capture groups in regular expressions.
27+
"regex.txt",
2728
"regex_char_width.txt",
2829
"whitequark/lvar_injecting_match.txt"
2930
]
3031

31-
skips = incorrect | %w[
32+
heredocs = %w[
3233
dos_endings.txt
33-
embdoc_no_newline_at_end.txt
3434
heredocs_leading_whitespace.txt
3535
heredocs_nested.txt
3636
heredocs_with_ignored_newlines.txt
37-
if.txt
38-
modules.txt
39-
regex.txt
40-
rescue.txt
41-
seattlerb/TestRubyParserShared.txt
42-
seattlerb/block_call_dot_op2_brace_block.txt
43-
seattlerb/block_command_operation_colon.txt
44-
seattlerb/block_command_operation_dot.txt
45-
seattlerb/defn_oneliner_eq2.txt
46-
seattlerb/defs_oneliner_eq2.txt
4737
seattlerb/heredoc__backslash_dos_format.txt
4838
seattlerb/heredoc_backslash_nl.txt
4939
seattlerb/heredoc_nested.txt
@@ -54,29 +44,39 @@ class RipperTest < TestCase
5444
seattlerb/heredoc_squiggly_tabs.txt
5545
seattlerb/heredoc_squiggly_tabs_extra.txt
5646
seattlerb/heredoc_squiggly_visually_blank_lines.txt
57-
seattlerb/if_elsif.txt
5847
spanning_heredoc.txt
5948
tilde_heredocs.txt
49+
whitequark/dedenting_heredoc.txt
50+
whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt
51+
whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt
52+
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
53+
whitequark/slash_newline_in_heredocs.txt
54+
]
55+
56+
skips = incorrect | heredocs | %w[
57+
if.txt
58+
modules.txt
59+
rescue.txt
60+
seattlerb/TestRubyParserShared.txt
61+
seattlerb/block_call_dot_op2_brace_block.txt
62+
seattlerb/block_command_operation_colon.txt
63+
seattlerb/block_command_operation_dot.txt
64+
seattlerb/defn_oneliner_eq2.txt
65+
seattlerb/defs_oneliner_eq2.txt
66+
seattlerb/if_elsif.txt
6067
unparser/corpus/literal/block.txt
6168
unparser/corpus/literal/class.txt
62-
unparser/corpus/literal/empty.txt
6369
unparser/corpus/literal/if.txt
6470
unparser/corpus/literal/kwbegin.txt
6571
unparser/corpus/literal/module.txt
6672
unparser/corpus/literal/send.txt
6773
unparser/corpus/literal/while.txt
6874
unparser/corpus/semantic/dstr.txt
6975
unparser/corpus/semantic/while.txt
70-
whitequark/dedenting_heredoc.txt
71-
whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt
72-
whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt
73-
whitequark/empty_stmt.txt
7476
whitequark/if_elsif.txt
7577
whitequark/parser_bug_640.txt
76-
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
7778
whitequark/parser_slash_slash_n_escaping_in_literals.txt
7879
whitequark/send_block_chain_cmd.txt
79-
whitequark/slash_newline_in_heredocs.txt
8080
]
8181

8282
relatives.each do |relative|

0 commit comments

Comments
 (0)