1
0
Fork 0
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:
nobu 2014-12-03 23:25:01 +00:00
parent f64ba5d519
commit bc0f131277

View file

@ -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]})"