<commit_before>
module Pawa
  class Translator
    def initialize(target_file)
      @target_file = target_file
      @pointer = 0
    end
    attr_accessor :target_file, :pointer
    def source_file
      target_file.translated_file
    end
    def config
      target_file.translated_file.folder_map.config
    end
    def translation
      @translation ||= source_file.syntax.get_translation_for(target_file.syntax)
    end
    def operations
      @operations ||= translation.operations.clone
    end
    def reg_next_operation(exclude=[])
      return @reg_next_operation if @reg_next_operation and exclude.empty? and @reg_for_nb == operations.length
      reg_strs = []
      operations.each_with_index do |op, index|
        if op.findable? and not exclude.include?(index)
          reg_strs.push "(?<o#{index}>#{op.start_reg.source})"
        end
      end
      reg_strs.push '(?<eol>\n)'
      Regexp.new(reg_strs.join('|')).tap do |reg|
        @reg_next_operation = reg if exclude.empty?
        @reg_for_nb = operations.length
      end
    end
    def edited_content
      @edited_content ||= source_file.content
    end
    def check_new_operation
      if m = match_pawa_comment(pointer)
        operations.unshift(Operations::Operation.new_from_string(m[:op]).tap do |op|
          op.startPos = pointer
        end)
        edited_content.slice!(m.begin(:comment)...m.end(:comment))
      end
    end<commit_msg>fix cache reg_next_operation<commit_after>
module Pawa
  class Translator
    def initialize(target_file)
      @target_file = target_file
      @pointer = 0
    end
    attr_accessor :target_file, :pointer
    def source_file
      target_file.translated_file
    end
    def config
      target_file.translated_file.folder_map.config
    end
    def translation
      @translation ||= source_file.syntax.get_translation_for(target_file.syntax)
    end
    def operations
      @operations ||= translation.operations.clone
    end
    def reg_next_operation(exclude=[])
      return @reg_next_operation if @reg_next_operation and exclude.empty? and @reg_for_nb == operations.length
      reg_strs = []
      operations.each_with_index do |op, index|
        if op.findable? and not exclude.include?(index)
          reg_strs.push "(?<o#{index}>#{op.start_reg.source})"
        end
      end
      reg_strs.push '(?<eol>\n)'
      Regexp.new(reg_strs.join('|')).tap do |reg|
        @reg_next_operation = reg if exclude.empty?
        @reg_for_nb = operations.length
      end
    end
    def edited_content
      @edited_content ||= source_file.content
    end
    def check_new_operation
      if m = match_pawa_comment(pointer)
        operations.unshift(Operations::Operation.new_from_string(m[:op]).tap do |op|
          op.startPos = pointer
        end)
        @reg_for_nb = nil
        edited_content.slice!(m.begin(:comment)...m.end(:comment))
      end
    end
{'fraction_non_alphanumeric': 0.09720785935884178, 'fraction_numerical': 0.0006894174422612892, 'mean_word_length': 2.7688311688311686, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1643037', 'n_tokens_mistral': 921, 'n_tokens_neox': 904, 'n_words': 183}