summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-04 06:16:13 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-04 06:16:13 +0000
commitf3b24b5b7f88ecfdefcd898f01ea1cfb2ee418f3 (patch)
treeab559843c641b0e40cead2df451d3fc39b56a517 /lib/rdoc
parent5a7c4d2a78f78804a0508c56fbdf26738251bb5b (diff)
* lib/rdoc/cross_reference.rb: Fixed matching of C#=== or #===. RDoc
bug #164 * test/rdoc/test_rdoc_cross_reference.rb: Test for above. * lib/rdoc/parser/changelog.rb: Fixed parsing of dates. RDoc bug #165 * test/rdoc/test_rdoc_parser_changelog.rb: Test for above. * lib/rdoc/parser.rb: Fixed parsing multibyte files with incomplete characters at byte 1024. [ruby-trunk - Bug #6393] Fixed handling of -E. [ruby-trunk - Bug #6392] * test/rdoc/test_rdoc_options.rb: Test for above. * test/rdoc/test_rdoc_parser.rb: ditto. * test/rdoc/test_rdoc_parser_c.rb: ditto. * test/rdoc/test_rdoc_parser_changelog.rb: ditto. * test/rdoc/test_rdoc_parser_markdown.rb: ditto. * test/rdoc/test_rdoc_parser_rd.rb: ditto. * test/rdoc/test_rdoc_rdoc.rb: ditto. * lib/rdoc/tom_doc.rb: Fixed parsing of [] in TomDoc arguments list. RDoc bug #167 * test/rdoc/test_rdoc_tom_doc.rb: Test for above. * lib/rdoc.rb: Update version. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/cross_reference.rb2
-rw-r--r--lib/rdoc/parser.rb35
-rw-r--r--lib/rdoc/parser/changelog.rb10
-rw-r--r--lib/rdoc/tom_doc.rb2
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(/.*/)