summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.y6
-rw-r--r--test/ripper/test_lexer.rb20
-rw-r--r--test/ruby/test_syntax.rb8
3 files changed, 34 insertions, 0 deletions
diff --git a/parse.y b/parse.y
index 4e79784203..3f76ed19f7 100644
--- a/parse.y
+++ b/parse.y
@@ -6732,6 +6732,12 @@ parser_here_document(struct parser_params *parser, NODE *here)
newtok();
if (c == '#') {
int t = parser_peek_variable_name(parser);
+ if (heredoc_line_indent != -1) {
+ if (heredoc_indent > heredoc_line_indent) {
+ heredoc_indent = heredoc_line_indent;
+ }
+ heredoc_line_indent = -1;
+ }
if (t) return t;
tokadd('#');
c = nextc();
diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb
index f900ee935d..2a1c7881e4 100644
--- a/test/ripper/test_lexer.rb
+++ b/test/ripper/test_lexer.rb
@@ -70,4 +70,24 @@ class TestRipper::Lexer < Test::Unit::TestCase
]
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
end
+
+ def test_expr_at_beginning_in_heredoc
+ src = <<~'E'
+ <<~B
+ a
+ #{1}
+ B
+ E
+ expect = %I[
+ on_heredoc_beg
+ on_nl
+ on_tstring_content
+ on_embexpr_beg
+ on_int
+ on_embexpr_end
+ on_tstring_content
+ on_heredoc_end
+ ]
+ assert_equal expect, Ripper.lex(src).map {|e| e[1]}
+ end
end
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 57cc5b9611..62b8d65441 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -659,6 +659,14 @@ e"
end
end
+ def test_dedented_heredoc_expr_at_beginning
+ result = " a\n" \
+ '#{1}'"\n"
+ expected = " a\n" \
+ '#{1}'"\n"
+ assert_dedented_heredoc(expected, result)
+ end
+
def test_lineno_after_heredoc
bug7559 = '[ruby-dev:46737]'
expected, _, actual = __LINE__, <<eom, __LINE__