Sha256: 7e2e99d15479bdafddb1e8b9a2303665f05aea95b7d6d974ed84af46aec3ad42

Contents?: true

Size: 1.1 KB

Versions: 3

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, Conditional
  # branches, and CharacterSet::Intersection intersected sequences.
  class Sequence < Regexp::Expression::Subexpression
    class << self
      def add_to(exp, params = {}, active_opts = {})
        sequence = construct(
          level:             exp.level,
          set_level:         exp.set_level,
          conditional_level: params[:conditional_level] || exp.conditional_level,
        )
        sequence.options = active_opts
        exp.expressions << sequence
        sequence
      end
    end

    def starts_at
      expressions.first.starts_at
    end
    alias :ts :starts_at

    def quantify(*args)
      target = expressions.reverse.find { |exp| !exp.is_a?(FreeSpace) }
      target or raise Regexp::Parser::Error,
        "No valid target found for '#{text}' quantifier"

      target.quantify(*args)
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
call_your_name-0.1.0 vendor/bundle/ruby/3.1.0/gems/regexp_parser-2.7.0/lib/regexp_parser/expression/sequence.rb
zilla-0.2.0 vendor/bundle/ruby/3.2.0/gems/regexp_parser-2.7.0/lib/regexp_parser/expression/sequence.rb
regexp_parser-2.7.0 lib/regexp_parser/expression/sequence.rb