Sha256: 82c1ae413d470457c9cdc93003090016d1773ae1bd2e7ab5eb31dda2b6523341

Contents?: true

Size: 970 Bytes

Versions: 9

Compression:

Stored size: 970 Bytes

Contents

module Regexp::Expression
  class Quantifier
    MODES = %i[greedy possessive reluctant]

    attr_reader :token, :text, :min, :max, :mode

    def initialize(token, text, min, max, mode)
      @token = token
      @text  = text
      @mode  = mode
      @min   = min
      @max   = max
    end

    def initialize_copy(orig)
      @text = orig.text.dup
      super
    end

    def to_s
      text.dup
    end
    alias :to_str :to_s

    def to_h
      {
        token: token,
        text:  text,
        mode:  mode,
        min:   min,
        max:   max,
      }
    end

    MODES.each do |mode|
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{mode}?
          mode.equal?(:#{mode})
        end
      RUBY
    end
    alias :lazy? :reluctant?

    def ==(other)
      other.class == self.class &&
        other.token == token &&
        other.mode == mode &&
        other.min == min &&
        other.max == max
    end
    alias :eq :==
  end
end

Version data entries

9 entries across 9 versions & 5 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/regexp_parser-2.2.1/lib/regexp_parser/expression/quantifier.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/regexp_parser-2.2.1/lib/regexp_parser/expression/quantifier.rb
regexp_parser-2.3.1 lib/regexp_parser/expression/quantifier.rb
regexp_parser-2.3.0 lib/regexp_parser/expression/quantifier.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/regexp_parser-2.2.1/lib/regexp_parser/expression/quantifier.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/regexp_parser-2.2.1/lib/regexp_parser/expression/quantifier.rb
regexp_parser-2.2.1 lib/regexp_parser/expression/quantifier.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/regexp_parser-2.2.0/lib/regexp_parser/expression/quantifier.rb
regexp_parser-2.2.0 lib/regexp_parser/expression/quantifier.rb