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 and Conditional branches.

Direct Known Subclasses

Alternative, Conditional::Branch

Instance Attribute Summary

Attributes inherited from Subexpression

#expressions

Attributes inherited from Base

#conditional_level, #level, #options, #quantifier, #set_level, #token, #ts, #type

Instance Method Summary collapse

Methods inherited from Subexpression

#<<, #[], #all?, #clone, #each, #each_expression, #each_with_index, #empty?, #first, #insert, #last, #length, #map, #strfregexp_tree, #te, #to_h, #to_s, #traverse, #ts

Methods inherited from Base

#ascii_classes?, #case_insensitive?, #clone, #coded_offset, #default_classes?, #free_spacing?, #full_length, #greedy?, #is?, #match, #matches?, #multiline?, #offset, #one_of?, #possessive?, #quantified?, #quantity, #reluctant?, #strfregexp, #terminal?, #to_h, #to_re, #to_s, #type?, #unicode_classes?

Constructor Details

#initialize(level, set_level, conditional_level) ⇒ Sequence

Returns a new instance of Sequence.



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

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

Instance Method Details

#quantify(token, text, min = nil, max = nil, mode = :greedy) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/regexp_parser/expression/sequence.rb', line 31

def quantify(token, text, min = nil, max = nil, mode = :greedy)
  offset = -1
  target = expressions[offset]
  while target and target.is_a?(FreeSpace)
    target = expressions[offset -= 1]
  end

  raise ArgumentError.new("No valid target found for '#{text}' " +
                          "quantifier") unless target

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

#starts_atObject



27
28
29
# File 'lib/regexp_parser/expression/sequence.rb', line 27

def starts_at
  @expressions.first.starts_at
end

#textObject



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

def text
  to_s
end