Skip to content

Commit c61f13c

Browse files
authored
- lexer.rl: accept tabs before closing heredoc delimiter (#990)
1 parent 717b38c commit c61f13c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/parser/lexer/literal.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Parser
66
class Lexer::Literal
77
DELIMITERS = { '(' => ')', '[' => ']', '{' => '}', '<' => '>' }
88
SPACE = ' '.ord
9+
TAB = "\t".ord
910

1011
TYPES = {
1112
# type start token interpolate?
@@ -247,7 +248,7 @@ def delimiter?(delimiter)
247248
# E
248249
# because there are not enough leading spaces in the closing delimiter.
249250
delimiter.end_with?(@end_delim) &&
250-
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE }
251+
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE || c == TAB }
251252
elsif @indent
252253
@end_delim == delimiter.lstrip
253254
else

test/test_parser.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11488,4 +11488,12 @@ def test_anonymous_params_in_nested_scopes
1148811488
'def b(**) ->(**) {c()} end',
1148911489
SINCE_3_3)
1149011490
end
11491+
11492+
def test_parser_bug_989
11493+
assert_parses(
11494+
s(:str, "\t\tcontent\n"),
11495+
"\t<<-HERE\n\t\tcontent\n\tHERE",
11496+
%q{},
11497+
ALL_VERSIONS)
11498+
end
1149111499
end

test/test_runner_rewrite.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
class TestRunnerRewrite < Minitest::Test
1212
def assert_rewriter_output(path, args, input: 'input.rb', output: 'output.rb', expected_output: '', expected_error: '')
13-
@ruby_rewrite = BASE_DIR.expand_path + '../bin/ruby-rewrite'
14-
@test_dir = BASE_DIR + path
13+
@ruby_rewrite = ::BASE_DIR.expand_path + '../bin/ruby-rewrite'
14+
@test_dir = ::BASE_DIR + path
1515
@fixtures_dir = @test_dir + 'fixtures'
1616

17-
Dir.mktmpdir("parser", BASE_DIR.expand_path.to_s) do |tmp_dir|
17+
Dir.mktmpdir("parser", ::BASE_DIR.expand_path.to_s) do |tmp_dir|
1818
tmp_dir = Pathname.new(tmp_dir)
1919
sample_file = tmp_dir + "#{path}.rb"
2020
sample_file_expanded = sample_file.expand_path

0 commit comments

Comments
 (0)