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, #extract_quantifier_target, #flat_map, #initialize, #initialize_copy, #inner_match_length, #match_length, #strfregexp_tree, #te, #to_h, #traverse

Methods inherited from Base

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

Methods included from Shared

#==, #base_length, #coded_offset, #ends_at, #full_length, #human_name, included, #initialize_copy, #inspect, #is?, #negated?, #negative?, #nesting_level=, #offset, #one_of?, #optional?, #parts, #pre_quantifier_decoration, #pretty_print, #pretty_print_instance_variables, #quantified?, #quantifier=, #quantifier_affix, #starts_at, #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,
    ts:                params[:ts],
  )
  sequence.options = active_opts
  exp.expressions << sequence
  sequence
end

Instance Method Details

#quantify(token, *args) ⇒ Object



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

def quantify(token, *args)
  extract_quantifier_target(token.text).quantify(token, *args)
end

#tsObject



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

def ts
  (head = expressions.first) ? head.ts : @ts
end