diff options
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/cross_reference.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/parser.rb | 35 | ||||
-rw-r--r-- | lib/rdoc/parser/changelog.rb | 10 | ||||
-rw-r--r-- | lib/rdoc/tom_doc.rb | 2 |
4 files changed, 37 insertions, 12 deletions
diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb index c6f127387c..2cb0571732 100644 --- a/lib/rdoc/cross_reference.rb +++ b/lib/rdoc/cross_reference.rb @@ -18,7 +18,7 @@ class RDoc::CrossReference # # See CLASS_REGEXP_STR - METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%)(?:\([\w.+*/=<>-]*\))?' + METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===)(?:\([\w.+*/=<>-]*\))?' ## # Regular expressions matching text that should potentially have diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 506b5e7d1b..47ecd746d0 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -58,7 +58,7 @@ class RDoc::Parser old_ext = old_ext.sub(/^\.(.*)/, '\1') new_ext = new_ext.sub(/^\.(.*)/, '\1') - parser = can_parse "xxx.#{old_ext}" + parser = can_parse_by_name "xxx.#{old_ext}" return false unless parser RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser] @@ -77,14 +77,14 @@ class RDoc::Parser have_encoding = s.respond_to? :encoding - if have_encoding then - return false if s.encoding != Encoding::ASCII_8BIT and s.valid_encoding? - end - return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") if have_encoding then - s.force_encoding Encoding.default_external + mode = "r" + s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. + encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] + mode = "r:#{encoding}" if encoding + s = File.open(file, mode) {|f| f.gets(nil, 1024)} not s.valid_encoding? else @@ -131,23 +131,36 @@ class RDoc::Parser zip_signature == "PK\x03\x04" or zip_signature == "PK\x05\x06" or zip_signature == "PK\x07\x08" + rescue + false end ## # Return a parser that can handle a particular extension - def self.can_parse(file_name) - parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }.last + def self.can_parse file_name + parser = can_parse_by_name file_name # HACK Selenium hides a jar file using a .txt extension return if parser == RDoc::Parser::Simple and zip? file_name + parser + end + + ## + # Returns a parser that can handle the extension for +file_name+. This does + # not depend upon the file being readable. + + def self.can_parse_by_name file_name + _, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name } + # The default parser must not parse binary files ext_name = File.extname file_name return parser if ext_name.empty? + if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then case check_modeline file_name - when 'rdoc' then # continue + when nil, 'rdoc' then # continue else return nil end end @@ -173,6 +186,8 @@ class RDoc::Parser type = $1 end + return nil if /coding:/i =~ type + type.downcase rescue ArgumentError # invalid byte sequence, etc. end @@ -204,6 +219,8 @@ class RDoc::Parser return unless parser parser.new top_level, file_name, content, options, stats + rescue SystemCallError + nil end ## diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index fd7114daee..782d8f09bf 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -102,7 +102,12 @@ class RDoc::Parser::ChangeLog < RDoc::Parser def group_entries entries entries.group_by do |title, _| - Time.parse(title).strftime "%Y-%m-%d" + begin + Time.parse(title).strftime '%Y-%m-%d' + rescue NoMethodError, ArgumentError + time, = title.split ' ', 2 + Time.parse(time).strftime '%Y-%m-%d' + end end end @@ -139,6 +144,9 @@ class RDoc::Parser::ChangeLog < RDoc::Parser time = Time.parse entry_name # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other" entry_name = nil unless entry_name =~ /#{time.year}/ + rescue NoMethodError + time, = entry_name.split ' ', 2 + time = Time.parse time rescue ArgumentError entry_name = nil end diff --git a/lib/rdoc/tom_doc.rb b/lib/rdoc/tom_doc.rb index b95ef25d99..3a5a098ae8 100644 --- a/lib/rdoc/tom_doc.rb +++ b/lib/rdoc/tom_doc.rb @@ -218,7 +218,7 @@ class RDoc::TomDoc < RDoc::Markup::Parser @tokens << [:HEADER, 3, *token_pos(pos)] [:TEXT, @s[1], *token_pos(pos)] - when @s.scan(/([:\w]\w*)[ ]+- /) then + when @s.scan(/([:\w][\w\[\]]*)[ ]+- /) then [:NOTE, @s[1], *token_pos(pos)] else @s.scan(/.*/) |