Sha256: e0d7b61a9f254bbb40d7dbe3e1a52f31e108df24e2c11723b31000dbd253d9f3

Contents?: true

Size: 994 Bytes

Versions: 23

Compression:

Stored size: 994 Bytes

Contents

module Ruby2JS
  class Converter

    # (regexp
    #   (str "x")
    #   (regopt :i))

    handle :regexp do |*parts, opt|
      extended = false
      opts = opt.children
      if opts.include? :x
        opts = opts.dup - [:x]
        extended = true
      end

      if parts.all? {|part| part.type == :str}
        str = parts.map {|part| part.children.first}.join
        str = str.gsub(/ #.*/,'').gsub(/\s/,'') if extended
        unless str.include? '/'
          return "/#{ str }/#{ opts.join }"
        end
        str = str.inspect
      else
        parts.map! do |part|
          if part.type == :str
            str = part.children.first 
            str = str.gsub(/ #.*/,'').gsub(/\s/,'') if extended
            str.inspect
          else
            parse part
          end
        end
        str = parts.join(' + ')
      end

      if opts.empty?
        "new RegExp(#{ str })"
      else
        "new RegExp(#{ str }, #{ opts.join.inspect})"
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ruby2js-1.15.1 lib/ruby2js/converter/regexp.rb
ruby2js-1.15.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.14.1 lib/ruby2js/converter/regexp.rb
ruby2js-1.14.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.13.1 lib/ruby2js/converter/regexp.rb
ruby2js-1.13.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.12.2 lib/ruby2js/converter/regexp.rb
ruby2js-1.12.1 lib/ruby2js/converter/regexp.rb
ruby2js-1.12.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.11.1 lib/ruby2js/converter/regexp.rb
ruby2js-1.11.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.10.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.9.3 lib/ruby2js/converter/regexp.rb
ruby2js-1.9.2 lib/ruby2js/converter/regexp.rb
ruby2js-1.9.1 lib/ruby2js/converter/regexp.rb
ruby2js-1.9.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.8.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.7.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.6.0 lib/ruby2js/converter/regexp.rb
ruby2js-1.5.0 lib/ruby2js/converter/regexp.rb