<commit_before>module Pegarus
  def pattern(spec)
    case spec
    when Array
      Set.new spec.join
    when Integer
      Any.new spec
    when String
      Character.new spec
    when Range
      case spec.first
      when Integer
        AnyRange.new spec
      when String
        CharacterRange.new spec
      end
    when Symbol
      variable spec
    when Pattern
      spec
    when true
      Always.new
    when false
      Never.new
    when nil
      nil
    else
      raise ParseError, "unknown specification type for Pattern: #{spec.inspect}"
    end
  end
  module_function :pattern

  class Pattern
    include Instructions

    def match(subject)
      compile subject
    end

    def compile(subject)
      g = Generator.new

      g.name = :match
      g.file = :"(pegarus)"
      g.set_line 1

      g.required_args = 1
      g.total_args = 1
      g.splat_index = nil

      g.local_count = 2
      g.local_names = [:subject, :index]

      g.push 0
      g.set_index

      bytecode(g)
      finish(g)

      g.encode Rubinius::InstructionSequence::Encoder
      cm = g.package Rubinius::CompiledMethod
      puts cm.decode if $DEBUG

      ss = Rubinius::StaticScope.new Object
      Rubinius.attach_method :match, cm, ss, self

      match subject
    end<commit_msg>Fixed encoding bytecode due to Rubinius code change.<commit_after>module Pegarus
  def pattern(spec)
    case spec
    when Array
      Set.new spec.join
    when Integer
      Any.new spec
    when String
      Character.new spec
    when Range
      case spec.first
      when Integer
        AnyRange.new spec
      when String
        CharacterRange.new spec
      end
    when Symbol
      variable spec
    when Pattern
      spec
    when true
      Always.new
    when false
      Never.new
    when nil
      nil
    else
      raise ParseError, "unknown specification type for Pattern: #{spec.inspect}"
    end
  end
  module_function :pattern

  class Pattern
    include Instructions

    def match(subject)
      compile subject
    end

    def compile(subject)
      g = Generator.new

      g.name = :match
      g.file = :"(pegarus)"
      g.set_line 1

      g.required_args = 1
      g.total_args = 1
      g.splat_index = nil

      g.local_count = 2
      g.local_names = [:subject, :index]

      g.push 0
      g.set_index

      bytecode(g)
      finish(g)

      g.encode
      cm = g.package Rubinius::CompiledMethod
      puts cm.decode if $DEBUG

      ss = Rubinius::StaticScope.new Object
      Rubinius.attach_method :match, cm, ss, self

      match subject
    end
{'fraction_non_alphanumeric': 0.061295296838858905, 'fraction_numerical': 0.0038550501156515036, 'mean_word_length': 1.8516483516483517, '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': '6575273', 'n_tokens_mistral': 803, 'n_tokens_neox': 767, 'n_words': 235}