Skip to content

Commit

Permalink
- lexer.rl: accept tabs before closing heredoc delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich committed Jan 12, 2024
1 parent 717b38c commit 9e37e3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/parser/lexer/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Parser
class Lexer::Literal
DELIMITERS = { '(' => ')', '[' => ']', '{' => '}', '<' => '>' }
SPACE = ' '.ord
TAB = "\t".ord

TYPES = {
# type start token interpolate?
Expand Down Expand Up @@ -247,7 +248,7 @@ def delimiter?(delimiter)
# E
# because there are not enough leading spaces in the closing delimiter.
delimiter.end_with?(@end_delim) &&
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE }
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE || c == TAB }
elsif @indent
@end_delim == delimiter.lstrip
else
Expand Down
8 changes: 8 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11488,4 +11488,12 @@ def test_anonymous_params_in_nested_scopes
'def b(**) ->(**) {c()} end',
SINCE_3_3)
end

def test_parser_bug_989
assert_parses(
s(:str, "\t\tcontent\n"),
"\t<<-HERE\n\t\tcontent\n\tHERE",
%q{},
ALL_VERSIONS)
end
end

0 comments on commit 9e37e3d

Please sign in to comment.