summaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-03 23:25:01 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-03 23:25:01 (GMT)
commitbc0f131277af6b6cd65a5e75c3b8a2d9d8b073ad (patch)
tree3bfd4b82d7ea1024b5c5cac8c744212e83038d94 /template
parentf64ba5d5197b8e2db871bbd16750ad7766a3b931 (diff)
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
Diffstat (limited to 'template')
-rw-r--r--template/prelude.c.tmpl12
1 files changed, 8 insertions, 4 deletions
diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl
index 00230ab..8f331d9 100644
--- a/template/prelude.c.tmpl
+++ b/template/prelude.c.tmpl
@@ -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]})"