Skip to content

Commit a1631aa

Browse files
authored
Merge pull request #586 from aycabta/check-nil-text-token
Check nil text token
2 parents 7f66f34 + 9d98bfe commit a1631aa

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/rdoc/parser/ripper_state_lex.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ def get_squashed_tk
341341
@heredoc_queue << retrieve_heredoc_info(tk)
342342
@inner_lex.lex_state = EXPR_END unless RIPPER_HAS_LEX_STATE
343343
when :on_nl, :on_ignored_nl, :on_comment, :on_heredoc_end then
344-
unless @heredoc_queue.empty?
344+
if !@heredoc_queue.empty?
345345
get_heredoc_tk(*@heredoc_queue.shift)
346+
elsif tk[:text].nil? # :on_ignored_nl sometimes gives nil
347+
tk[:text] = ''
346348
end
347349
when :on_words_beg then
348350
tk = get_words_tk(tk)

test/test_rdoc_parser_ruby.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,36 @@ def sum(n)
306306
assert_equal @top_level, sum.file
307307
end
308308

309+
def test_parse_on_ignored_nl_with_nil_text
310+
util_parser <<ruby
311+
class Foo
312+
def meth
313+
variable # comment
314+
.chain
315+
end
316+
end
317+
ruby
318+
319+
expected = <<EXPECTED
320+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">meth</span>
321+
<span class="ruby-identifier">variable</span> <span class="ruby-comment"># comment</span>
322+
.<span class="ruby-identifier">chain</span>
323+
<span class="ruby-keyword">end</span>
324+
EXPECTED
325+
expected = expected.rstrip
326+
327+
@parser.scan
328+
329+
foo = @store.find_class_named 'Foo'
330+
meth = foo.method_list.first
331+
332+
assert_equal 'meth', meth.name
333+
assert_equal @top_level, meth.file
334+
335+
markup_code = meth.markup_code.sub(/^.*\n/, '')
336+
assert_equal expected, markup_code
337+
end
338+
309339
def test_parse_redefined_op_with_constant
310340
klass = RDoc::NormalClass.new 'Foo'
311341
klass.parent = @top_level

0 commit comments

Comments
 (0)