Skip to content

Commit a964703

Browse files
authored
Merge pull request #3921 from Earlopain/revert-3918
Revert "Fix lexing for unterminated strings/heredocs etc."
2 parents 0a3b560 + ed48f6d commit a964703

4 files changed

Lines changed: 3 additions & 79 deletions

File tree

src/prism.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9856,15 +9856,6 @@ parser_lex(pm_parser_t *parser) {
98569856
// We'll check if we're at the end of the file. If we are, then we
98579857
// need to return the EOF token.
98589858
if (parser->current.end >= parser->end) {
9859-
// We may be missing closing tokens. We should pop modes one by one
9860-
// to do the appropriate cleanup like moving next_start for heredocs.
9861-
// Only when no mode is remaining will we actually emit the EOF token.
9862-
if (parser->lex_modes.current->mode != PM_LEX_DEFAULT) {
9863-
lex_mode_pop(parser);
9864-
parser_lex(parser);
9865-
return;
9866-
}
9867-
98689859
// If we hit EOF, but the EOF came immediately after a newline,
98699860
// set the start of the token to the newline. This way any EOF
98709861
// errors will be reported as happening on that line rather than

test/prism/errors/unterminated_heredoc_and_embexpr.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/prism/errors/unterminated_heredoc_and_embexpr_2.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/prism/lex_test.rb

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -48,58 +48,11 @@ def test_parse_lex_file
4848
end
4949

5050
if RUBY_VERSION >= "3.3"
51-
def test_lex_compat
52-
source = "foo bar"
53-
prism = Prism.lex_compat(source, version: "current").value
54-
ripper = Ripper.lex(source)
51+
def test_lex_compare
52+
prism = Prism.lex_compat(File.read(__FILE__), version: "current").value
53+
ripper = Ripper.lex(File.read(__FILE__))
5554
assert_equal(ripper, prism)
5655
end
5756
end
58-
59-
def test_lex_interpolation_unterminated
60-
assert_equal(
61-
%i[STRING_BEGIN EMBEXPR_BEGIN EOF],
62-
token_types('"#{')
63-
)
64-
65-
assert_equal(
66-
%i[STRING_BEGIN EMBEXPR_BEGIN IGNORED_NEWLINE EOF],
67-
token_types('"#{' + "\n")
68-
)
69-
end
70-
71-
def test_lex_interpolation_unterminated_with_content
72-
# FIXME: Emits EOL twice.
73-
assert_equal(
74-
%i[STRING_BEGIN EMBEXPR_BEGIN CONSTANT EOF EOF],
75-
token_types('"#{C')
76-
)
77-
78-
assert_equal(
79-
%i[STRING_BEGIN EMBEXPR_BEGIN CONSTANT NEWLINE EOF],
80-
token_types('"#{C' + "\n")
81-
)
82-
end
83-
84-
def test_lex_heredoc_unterminated
85-
code = <<~'RUBY'.strip
86-
<<A+B
87-
#{C
88-
RUBY
89-
90-
assert_equal(
91-
%i[HEREDOC_START EMBEXPR_BEGIN CONSTANT HEREDOC_END PLUS CONSTANT NEWLINE EOF],
92-
token_types(code)
93-
)
94-
95-
assert_equal(
96-
%i[HEREDOC_START EMBEXPR_BEGIN CONSTANT NEWLINE HEREDOC_END PLUS CONSTANT NEWLINE EOF],
97-
token_types(code + "\n")
98-
)
99-
end
100-
101-
def token_types(code)
102-
Prism.lex(code).value.map { |token, _state| token.type }
103-
end
10457
end
10558
end

0 commit comments

Comments
 (0)