From c5a2039acf7dc4dfb8101aff4acb667033fd58ba Mon Sep 17 00:00:00 2001 From: Eric Hodel Date: Fri, 16 Aug 2013 17:48:58 -0700 Subject: [PATCH] Fix parsing of multiple methods on the same line 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 #221 --- History.rdoc | 1 + lib/rdoc/parser/ruby.rb | 3 ++- test/test_rdoc_parser_ruby.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/History.rdoc b/History.rdoc index 658c5d8a5f..db759d1d4b 100644 --- a/History.rdoc +++ b/History.rdoc @@ -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 diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index beb5ad7fae..4c6da37a63 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -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*(.*)/ diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index 5b326069d1..1ee547b4ed 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -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*