mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
prelude.c.tmpl: require_relative
* template/prelude.c.tmpl (Prelude#translate): support for require_relative and comments followed by #. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f64ba5d519
commit
bc0f131277
1 changed files with 8 additions and 4 deletions
|
@ -42,10 +42,14 @@ class Prelude
|
|||
result = [@preludes.size, @vpath.strip(filename), lines, sub]
|
||||
@vpath.foreach(filename) do |line|
|
||||
@preludes[filename] ||= result
|
||||
line.sub!(/(?:^|\s+)\#(?:$|\s.*)/, '')
|
||||
line.sub!(/require\s*\(?\s*(["'])(.*?)\1\)?/) do
|
||||
orig, path = $&, $2
|
||||
path = translate(path, true) rescue nil
|
||||
line.sub!(/(?:^|\s+)\#(?:$|[#\s].*)/, '')
|
||||
line.sub!(/require(_relative)?\s*\(?\s*(["'])(.*?)(?:\.rb)?\2\)?/) do
|
||||
orig, rel, path = $&, $2, $3
|
||||
if rel
|
||||
path = File.join(File.dirname(filename), path)
|
||||
nil while path.gsub!(%r'(\A|/)(?!\.\.?/)[^/]+/\.\.(?:/|\z)', '')
|
||||
end
|
||||
path = translate("#{path}.rb", true) rescue nil
|
||||
if path
|
||||
@have_sublib = true
|
||||
"TMP_RUBY_PREFIX.require(#{path[0]})"
|
||||
|
|
Loading…
Reference in a new issue