Sha256: 0255172256df96592498ec064803245e7413769e69694adfcc281ade48fedab6

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 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(subexpression, params = {}, active_opts = {})
        sequence = at_levels(
          subexpression.level,
          subexpression.set_level,
          params[:conditional_level] || subexpression.conditional_level
        )
        sequence.nesting_level = subexpression.nesting_level + 1
        sequence.options = active_opts
        subexpression.expressions << sequence
        sequence
      end

      def at_levels(level, set_level, conditional_level)
        token = Regexp::Token.new(
          :expression,
          :sequence,
          '',
          nil, # ts
          nil, # te
          level,
          set_level,
          conditional_level
        )
        new(token)
      end
    end

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

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

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

Version data entries

14 entries across 10 versions & 5 rubygems

Version Path
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/regexp_parser-2.1.1/lib/regexp_parser/expression/sequence.rb
regexp_parser-2.1.1 lib/regexp_parser/expression/sequence.rb
regexp_parser-2.1.0 lib/regexp_parser/expression/sequence.rb