Class: Regexp::Expression::Sequence

Inherits:
Subexpression show all
Defined in:
lib/regexp_parser/expression/sequence.rb

Overview

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.

Instance Attribute Summary

Attributes inherited from Subexpression

#expressions

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Subexpression

#<<, #dig, #each_expression, #flat_map, #initialize, #initialize_copy, #inner_match_length, #match_length, #parts, #strfregexp_tree, #te, #to_h, #traverse

Methods inherited from Base

#ascii_classes?, #case_insensitive?, #default_classes?, #free_spacing?, #greedy?, #initialize, #initialize_copy, #match, #match?, #multiline?, #possessive?, #quantity, #reluctant?, #repetitions, #strfregexp, #to_h, #to_re, #unicode_classes?, #unquantified_clone

Methods included from Shared

#==, #base_length, #coded_offset, #full_length, included, #initialize_copy, #is?, #nesting_level=, #offset, #one_of?, #parts, #quantified?, #quantifier_affix, #terminal?, #to_s, #type?

Constructor Details

This class inherits a constructor from Regexp::Expression::Subexpression

Class Method Details

.add_to(subexpression, params = {}, active_opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/regexp_parser/expression/sequence.rb', line 10

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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/regexp_parser/expression/sequence.rb', line 22

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

Instance Method Details

#quantify(*args) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/regexp_parser/expression/sequence.rb', line 42

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

#starts_atObject Also known as: ts



37
38
39
# File 'lib/regexp_parser/expression/sequence.rb', line 37

def starts_at
  expressions.first.starts_at
end