mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Check for shebang line in file that would otherwise be treated as plain text
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
41383f13ce
commit
4cc80cdd0b
2 changed files with 19 additions and 1 deletions
|
|
@ -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 22:13:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Tue Jan 6 22:13:34 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_mod_modfunc): should break if m has no super class.
|
* eval.c (rb_mod_modfunc): should break if m has no super class.
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module RDoc
|
||||||
# The initialize method takes a file name to be used, the body of the
|
# 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
|
# file, and an RDoc::Options object. The scan method is then called
|
||||||
# to return an appropriately parsed TopLevel code object.
|
# to return an appropriately parsed TopLevel code object.
|
||||||
|
#
|
||||||
# The ParseFactory is used to redirect to the correct parser given a filename
|
# The ParseFactory is used to redirect to the correct parser given a filename
|
||||||
# extension. This magic works because individual parsers have to register
|
# extension. This magic works because individual parsers have to register
|
||||||
# themselves with us as they are loaded in. The do this using the following
|
# themselves with us as they are loaded in. The do this using the following
|
||||||
|
|
@ -37,6 +37,10 @@ module RDoc
|
||||||
# end
|
# end
|
||||||
# end
|
# 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
|
# SimpleParser for ones that we don't know
|
||||||
|
|
||||||
def ParserFactory.parser_for(top_level, file_name, body, options, stats)
|
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)
|
parser_description = can_parse(file_name)
|
||||||
if parser_description
|
if parser_description
|
||||||
parser = parser_description.parser
|
parser = parser_description.parser
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue