<commit_before>module Treetop
  module Compiler
    class GrammarCompiler
      def compile(source_path, target_path = source_path.gsub(/treetop\Z/, 'rb'))
        File.open(target_path, 'w') do |target_file|
          target_file.write(ruby_source(source_path))
        end
      end
      
      def ruby_source(source_path)
        File.open(source_path) do |source_file|
          parser = MetagrammarParser.new
          result = parser.parse(source_file.read)
          unless result
            raise RuntimeError.new(parser.terminal_failures.map {|failure| failure.to_s}.join("\n"))
          end
          result.compile
        end
      end
    end
  end

  def self.load(file)
    load_grammar file
  end
end<commit_msg>When processing a .tt file, the source file may be overwritten.<commit_after>module Treetop
  module Compiler
    class GrammarCompiler
      def compile(source_path, target_path = source_path.gsub(/\.(treetop|tt)\Z/, '.rb'))
        File.open(target_path, 'w') do |target_file|
          target_file.write(ruby_source(source_path))
        end
      end
      
      def ruby_source(source_path)
        File.open(source_path) do |source_file|
          parser = MetagrammarParser.new
          result = parser.parse(source_file.read)
          unless result
            raise RuntimeError.new(parser.terminal_failures.map {|failure| failure.to_s}.join("\n"))
          end
          result.compile
        end
      end
    end
  end

  def self.load(file)
    load_grammar file
  end
end
{'fraction_non_alphanumeric': 0.08869908015768725, 'fraction_numerical': 0.0, 'mean_word_length': 2.3253275109170306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6638659', 'n_tokens_mistral': 468, 'n_tokens_neox': 459, 'n_words': 99}