Permalink
Browse files

- Regexps with options other than /o were not showing flags. (smorss)

[git-p4: depot-paths = "//src/ruby2ruby/dev/": change = 6649]
  • Loading branch information...
1 parent 2fc7884 commit 8d6dd777f3c53f8379d4d39f44dc355aec38f05f @zenspider zenspider committed Sep 22, 2011
Showing with 41 additions and 3 deletions.
  1. +29 −3 lib/ruby2ruby.rb
  2. +12 −0 test/test_ruby2ruby.rb
View
@@ -3,6 +3,26 @@
require 'rubygems'
require 'sexp_processor'
+# REFACTOR: stolen from ruby_parser
+class Regexp
+ unless defined? ENC_NONE then
+ ENC_NONE = /x/n.options
+ ENC_EUC = /x/e.options
+ ENC_SJIS = /x/s.options
+ ENC_UTF8 = /x/u.options
+
+ CODES = {
+ EXTENDED => 'x',
+ IGNORECASE => 'i',
+ MULTILINE => 'm',
+ ENC_NONE => 'n',
+ ENC_EUC => 'e',
+ ENC_SJIS => 's',
+ ENC_UTF8 => 'u',
+ }
+ end
+end
+
class Ruby2Ruby < SexpProcessor
VERSION = '1.3.0'
LINE_LENGTH = 78
@@ -348,8 +368,15 @@ def process_dot3(exp)
"(#{process exp.shift}...#{process exp.shift})"
end
+ def re_opt options
+ bits = (0..8).map { |n| options[n] * 2**n }
+ bits.delete 0
+ bits.map { |n| Regexp::CODES[n] }.join
+ end
+
def process_dregx(exp)
- "/" << util_dthing(:dregx, exp) << "/"
+ options = re_opt exp.pop if Fixnum === exp.last
+ "/" << util_dthing(:dregx, exp) << "/#{options}"
end
def process_dregx_once(exp)
@@ -936,8 +963,7 @@ def util_dthing(type, exp)
raise "unknown type: #{pt.inspect}"
end
else
- # HACK: raise "huh?: #{pt.inspect}" -- hitting # constants in regexps
- # do nothing for now
+ raise "unhandled value in d-thing: #{pt.inspect}"
end
end
@@ -230,6 +230,18 @@ def test_resbody_short_with_begin_end
util_compare inn, out
end
+ def test_regexp_options
+ inn = s(:match3,
+ s(:dregx,
+ "abc",
+ s(:evstr, s(:call, nil, :x, s(:arglist))),
+ s(:str, "def"),
+ 4),
+ s(:str, "a"))
+ out = '"a" =~ /abc#{x}def/m'
+ util_compare inn, out
+ end
+
def test_resbody_short_with_rescue_args
inn = s(:rescue,
s(:call, nil, :blah, s(:arglist)),

0 comments on commit 8d6dd77

Please sign in to comment.