Sha256: a1fe343a1f49cd9cc92ba55b2033cc9ce2f7f8df3107d05dbed209cedffbf28a

Contents?: true

Size: 804 Bytes

Versions: 7

Compression:

Stored size: 804 Bytes

Contents

module Regexp::Expression
  class Quantifier
    MODES = [: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_clone(other)
      other.instance_variable_set(:@text, 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?
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
tdiary-5.0.13 vendor/bundle/gems/regexp_parser-1.3.0/lib/regexp_parser/expression/quantifier.rb
regexp_parser-1.4.0 lib/regexp_parser/expression/quantifier.rb
tdiary-5.0.12.1 vendor/bundle/gems/regexp_parser-1.3.0/lib/regexp_parser/expression/quantifier.rb
tdiary-5.0.11 vendor/bundle/gems/regexp_parser-1.3.0/lib/regexp_parser/expression/quantifier.rb
regexp_parser-1.3.0 lib/regexp_parser/expression/quantifier.rb
regexp_parser-1.2.0 lib/regexp_parser/expression/quantifier.rb
regexp_parser-1.1.0 lib/regexp_parser/expression/quantifier.rb