summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-06 23:26:42 +0000
committerdave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-06 23:26:42 +0000
commit73d7365091db9e6e118fe5916dfddd0a125668a3 (patch)
tree94c64c4845e5e260922caf550c4ebea7afa3c264
parent4c88c6c8c14cfafa005d0c2e5274ab5f40c3ffd9 (diff)
downloadruby-73d7365091db9e6e118fe5916dfddd0a125668a3.tar.gz
ruby-73d7365091db9e6e118fe5916dfddd0a125668a3.tar.xz
ruby-73d7365091db9e6e118fe5916dfddd0a125668a3.zip
Check for shebang line in file that would otherwise be treated as plain text
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@5393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--lib/rdoc/parsers/parserfactory.rb14
2 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 8549261a2..17bf7d7e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jan 7 08:21:04 2004 Dave Thomas <dave@pragprog.com>
+
+ * lib/rdoc/parsers/parserfactory.rb: Check for shebang
+ line in files that would otherwise be treated as
+ plain text.
+
Tue Jan 6 21:51:37 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (fptr_finalize): should save errno just after failure.
diff --git a/lib/rdoc/parsers/parserfactory.rb b/lib/rdoc/parsers/parserfactory.rb
index b19bd0ca9..00a82cf4b 100644
--- a/lib/rdoc/parsers/parserfactory.rb
+++ b/lib/rdoc/parsers/parserfactory.rb
@@ -13,7 +13,7 @@ module RDoc
# The initialize method takes a file name to be used, the body of the
# file, and an RDoc::Options object. The scan method is then called
# to return an appropriately parsed TopLevel code object.
-
+ #
# The ParseFactory is used to redirect to the correct parser given a filename
# extension. This magic works because individual parsers have to register
# themselves with us as they are loaded in. The do this using the following
@@ -37,6 +37,10 @@ module RDoc
# end
# end
# end
+ #
+ # Just to make life interesting, if we suspect a plain text file, we
+ # also look for a shebang line just in case it's a potential
+ # shell script
@@ -74,6 +78,14 @@ module RDoc
# SimpleParser for ones that we don't know
def ParserFactory.parser_for(top_level, file_name, body, options, stats)
+ # If no extension, look for shebang
+ if file_name !~ /\.\w+$/ && body =~ %r{\A#!(.+)}
+ shebang = $1
+ case shebang
+ when %r{env\s+ruby}, %r{/ruby}
+ file_name = "dummy.rb"
+ end
+ end
parser_description = can_parse(file_name)
if parser_description
parser = parser_description.parser