<commit_before>require 'set'
require 'opal/parser'
require 'opal/fragment'
require 'opal/nodes'

module Opal
  def self.compile(source, options = {})
    Compiler.new(source, options).compile
  end

  class Compiler
    # Generated code gets indented with two spaces on each scope
    INDENT = '  '

    # All compare method nodes - used to optimize performance of
    # math comparisons
    COMPARE = %w[< > <= >=]

    # defines a compiler option, also creating method of form 'name?'
    def self.compiler_option(name, default_value, options = {})
      mid          = options[:as]
      valid_values = options[:valid_values]
      define_method(mid || name) do
        value = @options.fetch(name) { default_value }
        raise ArgumentError if valid_values and not(valid_values.include?(value))
        value
      end
    end

    # used for __FILE__ directives as well as finding relative require()
    compiler_option :file, '(file)'

    # adds method stubs for all used methods in file
    compiler_option :method_missing, true, :as => :method_missing?

    # adds an arity check to every method definition
    compiler_option :arity_check, false, :as => :arity_check?

    # checks every constant access, delagating to const_missing if needed
    compiler_option :const_missing, false, :as => :const_missing?

    # compile top level local vars with support for irb style vars
    compiler_option :irb, false, :as => :irb?

    # how to handle dynamic requires (:error, :warning, :ignore)
    compiler_option :dynamic_require_severity, :error, :valid_values => [:error, :warning, :ignore]

    # Prepare the code for future requires
    compiler_option :requirable, false, :as => :requirable?

    attr_reader :result, :fragments

    # Current scope
    attr_accessor :scope

    # Current case_stmt
    attr_reader :case_stmt

    # Any content in __END__ special construct
    attr_reader :eof_content

    def initialize(source, options = {})
      @source = source
      @indent = ''
      @unique = 0
      @options = options
    end

    # Compile some ruby code to a string.
    def compile
      @parser = Parser.new

      @sexp = s(:top, @parser.parse(@source, self.file) || s(:nil))
      @eof_content = @parser.lexer.eof_content

      @fragments = process(@sexp).flatten

      @result = @fragments.map(&:code).join('')
    end

    def source_map(source_file = nil)
      Opal::SourceMap.new(@fragments, source_file || self.file)
    end

    # Any helpers required by this file
    def helpers
      @helpers ||= Set.new([:breaker, :slice])
    end

    # Method calls made in this file
    def method_calls
      @method_calls ||= Set.new
    end

    # This is called when a parsing/processing error occurs. This
    # method simply appends the filename and curent line number onto
    # the message and raises it.
    def error(msg, line = nil)
      raise SyntaxError, "#{msg} :#{file}:#{line}"
    end

    # This is called when a parsing/processing warning occurs. This
    # method simply appends the filename and curent line number onto
    # the message and issues a warning.
    def warning(msg, line = nil)
      warn "#{msg} :#{file}:#{line}"
    end

    # Instances of `Scope` can use this to determine the current
    # scope indent. The indent is used to keep generated code easily
    # readable.
    def parser_indent
      @indent
    end

    # Create a new sexp using the given parts. Even though this just
    # returns an array, it must be used incase the internal structure
    # of sexps does change.
    def s(*parts)
      Sexp.new(parts)
    end

    def fragment(str, sexp = nil)
      Fragment.new(str, sexp)
    end

    # Used to generate a unique id name per file. These are used
    # mainly to name method bodies for methods that use blocks.
    def unique_temp
      "TMP_#{@unique += 1}"
    end
<commit_msg>Add a “WARNING” prefix to warnings<commit_after>require 'set'
require 'opal/parser'
require 'opal/fragment'
require 'opal/nodes'

module Opal
  def self.compile(source, options = {})
    Compiler.new(source, options).compile
  end

  class Compiler
    # Generated code gets indented with two spaces on each scope
    INDENT = '  '

    # All compare method nodes - used to optimize performance of
    # math comparisons
    COMPARE = %w[< > <= >=]

    # defines a compiler option, also creating method of form 'name?'
    def self.compiler_option(name, default_value, options = {})
      mid          = options[:as]
      valid_values = options[:valid_values]
      define_method(mid || name) do
        value = @options.fetch(name) { default_value }
        raise ArgumentError if valid_values and not(valid_values.include?(value))
        value
      end
    end

    # used for __FILE__ directives as well as finding relative require()
    compiler_option :file, '(file)'

    # adds method stubs for all used methods in file
    compiler_option :method_missing, true, :as => :method_missing?

    # adds an arity check to every method definition
    compiler_option :arity_check, false, :as => :arity_check?

    # checks every constant access, delagating to const_missing if needed
    compiler_option :const_missing, false, :as => :const_missing?

    # compile top level local vars with support for irb style vars
    compiler_option :irb, false, :as => :irb?

    # how to handle dynamic requires (:error, :warning, :ignore)
    compiler_option :dynamic_require_severity, :error, :valid_values => [:error, :warning, :ignore]

    # Prepare the code for future requires
    compiler_option :requirable, false, :as => :requirable?

    attr_reader :result, :fragments

    # Current scope
    attr_accessor :scope

    # Current case_stmt
    attr_reader :case_stmt

    # Any content in __END__ special construct
    attr_reader :eof_content

    def initialize(source, options = {})
      @source = source
      @indent = ''
      @unique = 0
      @options = options
    end

    # Compile some ruby code to a string.
    def compile
      @parser = Parser.new

      @sexp = s(:top, @parser.parse(@source, self.file) || s(:nil))
      @eof_content = @parser.lexer.eof_content

      @fragments = process(@sexp).flatten

      @result = @fragments.map(&:code).join('')
    end

    def source_map(source_file = nil)
      Opal::SourceMap.new(@fragments, source_file || self.file)
    end

    # Any helpers required by this file
    def helpers
      @helpers ||= Set.new([:breaker, :slice])
    end

    # Method calls made in this file
    def method_calls
      @method_calls ||= Set.new
    end

    # This is called when a parsing/processing error occurs. This
    # method simply appends the filename and curent line number onto
    # the message and raises it.
    def error(msg, line = nil)
      raise SyntaxError, "#{msg} :#{file}:#{line}"
    end

    # This is called when a parsing/processing warning occurs. This
    # method simply appends the filename and curent line number onto
    # the message and issues a warning.
    def warning(msg, line = nil)
      warn "WARNING: #{msg} :#{file}:#{line}"
    end

    # Instances of `Scope` can use this to determine the current
    # scope indent. The indent is used to keep generated code easily
    # readable.
    def parser_indent
      @indent
    end

    # Create a new sexp using the given parts. Even though this just
    # returns an array, it must be used incase the internal structure
    # of sexps does change.
    def s(*parts)
      Sexp.new(parts)
    end

    def fragment(str, sexp = nil)
      Fragment.new(str, sexp)
    end

    # Used to generate a unique id name per file. These are used
    # mainly to name method bodies for methods that use blocks.
    def unique_temp
      "TMP_#{@unique += 1}"
    end

{'fraction_non_alphanumeric': 0.09012599640010285, 'fraction_numerical': 0.0005142710208279763, 'mean_word_length': 2.8720756595321055, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '73250', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2231, 'n_words': 828}