<commit_before>require 'opal/lexer'
require 'opal/grammar'
require 'opal/scope'

module Opal

  class Parser
    INDENT = '  '

    LEVEL = [:stmt, :stmt_closure, :list, :expr, :recv]

    COMPARE = %w[< > <= >=]

    # Reserved javascript keywords - we cannot create variables with the
    # same name
    RESERVED = %w(
      break case catch continue debugger default delete do else finally for
      function if in instanceof new return switch this throw try typeof var let
      void while with class enum export extends import super true false native
      const
    )

    STATEMENTS = [:xstr, :dxstr]

    attr_reader :grammar

    attr_reader :requires

    def parse(source, file = '(file)')
      @grammar  = Grammar.new
      @requires = []
      @comments = false
      @file     = file
      @line     = 1
      @indent   = ''
      @unique   = 0

      @helpers  = {
        :breaker  => true,
        :slice    => true
      }

      top @grammar.parse(source, file)
    end

    def warn(msg)
      puts "#{msg} :#{@file}:#{@line}"
    end

    def error(msg)
      raise "#{msg} :#{@file}:#{@line}"
    end

    def parser_indent
      @indent
    end

    def s(*parts)
      sexp = Sexp.new(parts)
      sexp.line = @line
      sexp
    end

    def mid_to_jsid(mid)
      if RESERVED.include?(mid) or /\=|\+|\-|\*|\/|\!|\?|\<|\>|\&|\||\^|\%|\~|\[/ =~ mid.to_s
        "['$#{mid}']"
      else
        '.$' + mid
      end
    end

    # guaranteed unique id per file..
    def unique_temp
      "TMP_#{@unique += 1}"
    end

    def top(sexp, options = {})
      code = nil
      vars = []

      in_scope(:top) do
        indent {
          code = @indent + process(s(:scope, sexp), :stmt)
        }

        vars << "__opal = Opal"
        vars << "self = __opal.top"
        vars << "__scope = __opal"
        vars << "nil = __opal.nil"
        vars << "def = #{current_self}._klass.prototype" if @scope.defines_defn
        vars.concat @helpers.keys.map { |h| "__#{h} = __opal.#{h}" }
<commit_msg>Stop wrapping reserved method names that don't need to be<commit_after>require 'opal/lexer'
require 'opal/grammar'
require 'opal/scope'

module Opal

  class Parser
    INDENT = '  '

    LEVEL = [:stmt, :stmt_closure, :list, :expr, :recv]

    COMPARE = %w[< > <= >=]

    # Reserved javascript keywords - we cannot create variables with the
    # same name
    RESERVED = %w(
      break case catch continue debugger default delete do else finally for
      function if in instanceof new return switch this throw try typeof var let
      void while with class enum export extends import super true false native
      const
    )

    STATEMENTS = [:xstr, :dxstr]

    attr_reader :grammar

    attr_reader :requires

    def parse(source, file = '(file)')
      @grammar  = Grammar.new
      @requires = []
      @comments = false
      @file     = file
      @line     = 1
      @indent   = ''
      @unique   = 0

      @helpers  = {
        :breaker  => true,
        :slice    => true
      }

      top @grammar.parse(source, file)
    end

    def warn(msg)
      puts "#{msg} :#{@file}:#{@line}"
    end

    def error(msg)
      raise "#{msg} :#{@file}:#{@line}"
    end

    def parser_indent
      @indent
    end

    def s(*parts)
      sexp = Sexp.new(parts)
      sexp.line = @line
      sexp
    end

    def mid_to_jsid(mid)
      if /\=|\+|\-|\*|\/|\!|\?|\<|\>|\&|\||\^|\%|\~|\[/ =~ mid.to_s
        "['$#{mid}']"
      else
        '.$' + mid
      end
    end

    # guaranteed unique id per file..
    def unique_temp
      "TMP_#{@unique += 1}"
    end

    def top(sexp, options = {})
      code = nil
      vars = []

      in_scope(:top) do
        indent {
          code = @indent + process(s(:scope, sexp), :stmt)
        }

        vars << "__opal = Opal"
        vars << "self = __opal.top"
        vars << "__scope = __opal"
        vars << "nil = __opal.nil"
        vars << "def = #{current_self}._klass.prototype" if @scope.defines_defn
        vars.concat @helpers.keys.map { |h| "__#{h} = __opal.#{h}" }

{'fraction_non_alphanumeric': 0.14640748031496062, 'fraction_numerical': 0.0014763779527559055, 'mean_word_length': 1.9098067287043665, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959667', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1368, 'n_words': 373}