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, #human_name, included, #initialize_copy, #is?, #nesting_level=, #offset, #one_of?, #optional?, #parts, #quantified?, #quantifier=, #quantifier_affix, #terminal?, #to_s, #token_class, #type?

Constructor Details

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

Class Method Details

.add_to(exp, 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(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

Instance Method Details

#quantify(*args) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/regexp_parser/expression/sequence.rb', line 28

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



23
24
25
# File 'lib/regexp_parser/expression/sequence.rb', line 23

def starts_at
  expressions.first.starts_at
end