Skip to content

Commit

Permalink
prelude.c.tmpl: require_relative
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Dec 3, 2014
1 parent f64ba5d commit bc0f131
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions template/prelude.c.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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]})"
Expand Down

0 comments on commit bc0f131

Please sign in to comment.