Sha256: 509548ccac21b18683cc3a8e98901d78643eb3113aa87fa50cfa3d3f6bb94bb2

Contents?: true

Size: 1.01 KB

Versions: 53

Compression:

Stored size: 1.01 KB

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 put "/#{ str }/#{ opts.join }"
        end
        put "new RegExp(#{ str.inspect }"
      else
        put 'new RegExp('

        parts.each_with_index do |part, index|
          put ' + ' unless index == 0

          if part.type == :str
            str = part.children.first 
            str = str.gsub(/ #.*/,'').gsub(/\s/,'') if extended
            put str.inspect
          else
            parse part
          end
        end
      end

      unless opts.empty?
        put ", #{ opts.join.inspect}"
      end

      put ')'
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
ruby2js-3.0.8 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.7 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.6 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.5 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.4 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.3 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.2 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.1 lib/ruby2js/converter/regexp.rb
ruby2js-3.0.0 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.24 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.23 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.22 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.21 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.20 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.19 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.18 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.17 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.16 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.15 lib/ruby2js/converter/regexp.rb
ruby2js-2.1.14 lib/ruby2js/converter/regexp.rb