class Regexp::Expression::Sequence

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.

Public Class Methods

add_to(subexpression, params = {}, active_opts = {}) click to toggle source
# File lib/regexp_parser/expression/sequence.rb, line 21
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
at_levels(level, set_level, conditional_level) click to toggle source
# File lib/regexp_parser/expression/sequence.rb, line 33
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
new(*args) click to toggle source

TODO: this override is here for backwards compatibility, remove in 2.0.0

Calls superclass method Regexp::Expression::Subexpression::new
# File lib/regexp_parser/expression/sequence.rb, line 11
def initialize(*args)
  if args.count == 3
    warn('WARNING: Sequence.new without a Regexp::Token argument is '\
         'deprecated and will be removed in 2.0.0.')
    return self.class.at_levels(*args)
  end
  super
end

Public Instance Methods

quantify(token, text, min = nil, max = nil, mode = :greedy) click to toggle source
# File lib/regexp_parser/expression/sequence.rb, line 53
def quantify(token, text, min = nil, max = nil, mode = :greedy)
  offset = -1
  target = expressions[offset]
  while target.is_a?(FreeSpace)
    target = expressions[offset -= 1]
  end

  target || raise(ArgumentError, "No valid target found for '#{text}' "\
                                 'quantifier')

  target.quantify(token, text, min, max, mode)
end
starts_at() click to toggle source
# File lib/regexp_parser/expression/sequence.rb, line 48
def starts_at
  expressions.first.starts_at
end
Also aliased as: ts
ts()
Alias for: starts_at