Sha256: 67b640623499c9275448ac2d8f015e048524d00af0db40eb607fe63383983646

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 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.nesting_level = exp.nesting_level + 1
        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

12 entries across 12 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.6.1/lib/regexp_parser/expression/sequence.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.6.1/lib/regexp_parser/expression/sequence.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/regexp_parser-2.6.1/lib/regexp_parser/expression/sequence.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/regexp_parser-2.5.0/lib/regexp_parser/expression/sequence.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/regexp_parser-2.5.0/lib/regexp_parser/expression/sequence.rb
regexp_parser-2.6.2 lib/regexp_parser/expression/sequence.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/regexp_parser-2.5.0/lib/regexp_parser/expression/sequence.rb
regexp_parser-2.6.1 lib/regexp_parser/expression/sequence.rb
regexp_parser-2.6.0 lib/regexp_parser/expression/sequence.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/regexp_parser-2.5.0/lib/regexp_parser/expression/sequence.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/regexp_parser-2.5.0/lib/regexp_parser/expression/sequence.rb
regexp_parser-2.5.0 lib/regexp_parser/expression/sequence.rb