Sha256: 67de1920664b9aa0f26ee434d6d5cade0f97e25db26a3bb79ed5f2a67f16c9c2

Contents?: true

Size: 1011 Bytes

Versions: 7

Compression:

Stored size: 1011 Bytes

Contents

require_relative 'replace_strings'
  
  def compile_special_keywords(input_file_contents)

    # This method compiles some Ruby specific keywords to Javascript to make it easy to port
    # Ruby code into Javascript
    
    keyword_replacement_map = {

        "nil" => "null",

        "Array.new" => "new Array()"

    }

    special_keywords = keyword_replacement_map.keys

    keyword_map_regex = special_keywords.collect {|name| name.gsub(".","\\.")}

    keyword_map_regex = Regexp.new(keyword_map_regex.join("|"))

    modified_file_contents = input_file_contents.clone

    input_file_contents.each_with_index do |line, index|

      if replace_strings(line).match(keyword_map_regex)

        method_match = line.match(keyword_map_regex).to_a[0]

        if line.split(keyword_map_regex)[0].include?("=")

          line = line.sub(method_match,keyword_replacement_map[method_match])

        end

      end

      modified_file_contents[index] = line

    end

    return modified_file_contents

  end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nilac-0.0.4.3.9.8 lib/nilac/compile_special_keywords.rb
nilac-0.0.4.3.9.7.1 lib/nilac/compile_special_keywords.rb
nilac-0.0.4.3.9.7 lib/nilac/compile_special_keywords.rb
nilac-0.0.4.3.9.6 lib/nilac/compile_special_keywords.rb
nilac-0.0.4.3.9.5 lib/nilac/compile_special_keywords.rb
nilac-0.0.4.3.9.4 lib/nilac/compile_special_keywords.rb
nilac-0.0.4.3.9.3 lib/nilac/compile_special_keywords.rb