summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanga_osyo <manga.osyo@gmail.com>2021-01-17 04:41:01 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-17 12:58:13 +0900
commitb84b253a69537a14e4854e17b6d94ae75c2af050 (patch)
tree1e3dc4c85a0166f0fdc9c3a543885e0f28f3fc19
parent562b97e2f0abed2eb09db00e91e966e3fb3a4a09 (diff)
Fix Ripper with heredoc.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4083
-rw-r--r--ext/ripper/lib/ripper/lexer.rb1
-rw-r--r--test/ripper/test_lexer.rb10
2 files changed, 11 insertions, 0 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 35ef9b088c4..8222684b654 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -130,6 +130,7 @@ class Ripper
@buf = []
@stack = []
super()
+ @buf = @stack.pop unless @stack.empty?
if raise_errors and !@errors.empty?
raise SyntaxError, @errors.map(&:message).join(' ;')
end
diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb
index 9762478c623..79cb194e5b7 100644
--- a/test/ripper/test_lexer.rb
+++ b/test/ripper/test_lexer.rb
@@ -90,6 +90,16 @@ class TestRipper::Lexer < Test::Unit::TestCase
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
end
+ def test_stack_at_on_heredoc_beg
+ src = "a <<b"
+ expect = %I[
+ on_ident
+ on_sp
+ on_heredoc_beg
+ ]
+ assert_equal expect, Ripper.lex(src).map {|e| e[1]}
+ end
+
def test_slice
assert_equal "string\#{nil}\n",
Ripper.slice(%(<<HERE\nstring\#{nil}\nHERE), "heredoc_beg .*? nl $(.*?) heredoc_end", 1)