Skip to content

Commit

Permalink
Fix parsing of multiple methods on the same line
Browse files Browse the repository at this point in the history
When a two class methods existed on the same line the second method
would be omitted and the remainder of the file may experience other
parsing mistakes.

This occurred when the second method required altering the lex state in
a way read_directive didn't reproduce.  This would cause incorrect
parsing of tokens as when tokens are ungotten the tokens are not
re-lexed.

Now when read_directive encounters a "def" token it assumes no
directives are present (as only one directive is allowed per line).

Fixes ruby#221
  • Loading branch information
drbrain committed Aug 17, 2013
1 parent bf40767 commit c5a2039
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions History.rdoc
Expand Up @@ -43,6 +43,7 @@
* Fixed text that is missing whitespace for TomDoc. Bug #248 by Noel Cower.
* The RDoc methods now store the method they are aliased to. Bug #206 by
Jeremy Stephens.
* Fixed parsing of multiple methods on the same line. Bug #221 by derula.

=== 4.0.1 / 2013-03-27

Expand Down
3 changes: 2 additions & 1 deletion lib/rdoc/parser/ruby.rb
Expand Up @@ -1796,7 +1796,8 @@ def read_directive allowed
tokens << tk

case tk
when TkNL then return
when TkNL, TkDEF then
return
when TkCOMMENT then
return unless tk.text =~ /\s*:?([\w-]+):\s*(.*)/

Expand Down
26 changes: 26 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Expand Up @@ -2980,6 +2980,32 @@ def z
assert_equal 2, @top_level.classes.first.method_list.length
end

def test_scan_method_semi_method
content = <<-CONTENT
class A
def self.m() end; def self.m=() end
end
class B
def self.m() end
end
CONTENT

util_parser content

@parser.scan

a = @store.find_class_named 'A'
assert a, 'missing A'

assert_equal 2, a.method_list.length

b = @store.find_class_named 'B'
assert b, 'missing B'

assert_equal 1, b.method_list.length
end

def test_scan_markup_override
content = <<-CONTENT
# *awesome*
Expand Down

0 comments on commit c5a2039

Please sign in to comment.