Sha256: ac87723182062bca4846447f0f0b030bd639a6d8e0db04c43e2f1e1a39a6b618

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 KB

Contents

module Regexp::Expression

  # A sequence of expressions. Differs from a Subexpressions by how it handles
  # quantifiers, as it applies them to its last element instead of itself as
  # a whole subexpression.
  #
  # Used as the base class for the Alternation alternatives and Conditional
  # branches.
  class Sequence < Regexp::Expression::Subexpression
    def initialize(level, set_level, conditional_level)
      super Regexp::Token.new(
        :expression,
        :sequence,
        '',
        nil, # ts
        nil, # te
        level,
        set_level,
        conditional_level
      )
    end

    def text
      to_s
    end

    def starts_at
      @expressions.first.starts_at
    end

    def quantify(token, text, min = nil, max = nil, mode = :greedy)
      offset = -1
      target = expressions[offset]
      while target and target.is_a?(FreeSpace)
        target = expressions[offset -= 1]
      end

      raise ArgumentError.new("No valid target found for '#{text}' " +
                              "quantifier") unless target

      target.quantify(token, text, min, max, mode)
    end
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
regexp_parser-0.4.13 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.12 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.11 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.10 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.9 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.8 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.7 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.6 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.5 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.4 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.3 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.2 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.1 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.4.0 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.3.6 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.3.5 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.3.4 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.3.3 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.3.2 lib/regexp_parser/expression/sequence.rb
regexp_parser-0.3.1 lib/regexp_parser/expression/sequence.rb