Class: Regexp::Expression::Sequence
- Inherits:
-
Subexpression
- Object
- Base
- Subexpression
- Regexp::Expression::Sequence
- 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.
Direct Known Subclasses
Alternative, CharacterSet::IntersectedSequence, Conditional::Branch
Instance Attribute Summary
Attributes inherited from Subexpression
Attributes inherited from Base
#conditional_level, #level, #nesting_level, #options, #quantifier, #set_level, #token, #type
Class Method Summary collapse
- .add_to(subexpression, options = {}) ⇒ Object
- .at_levels(level, set_level, conditional_level) ⇒ Object
Instance Method Summary collapse
-
#initialize(*args) ⇒ Sequence
constructor
TODO: this override is here for backwards compatibility, remove in 2.0.0.
- #quantify(token, text, min = nil, max = nil, mode = :greedy) ⇒ Object
- #starts_at ⇒ Object (also: #ts)
- #text ⇒ Object
Methods inherited from Subexpression
#<<, #dig, #each_expression, #flat_map, #initialize_clone, #strfregexp_tree, #te, #to_h, #to_s, #traverse
Methods inherited from Base
#ascii_classes?, #attributes, #case_insensitive?, #coded_offset, #default_classes?, #free_spacing?, #full_length, #greedy?, #initialize_clone, #is?, #match, #matches?, #multiline?, #offset, #one_of?, #possessive?, #quantified?, #quantifier_affix, #quantity, #reluctant?, #strfregexp, #terminal?, #to_re, #to_s, #type?, #unicode_classes?
Constructor Details
#initialize(*args) ⇒ Sequence
TODO: this override is here for backwards compatibility, remove in 2.0.0
11 12 13 14 15 16 17 18 |
# 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 |
Class Method Details
.add_to(subexpression, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/regexp_parser/expression/sequence.rb', line 21 def add_to(subexpression, = {}) sequence = at_levels( subexpression.level, subexpression.set_level, [:conditional_level] || subexpression.conditional_level ) sequence.nesting_level = subexpression.nesting_level + 1 subexpression.expressions << sequence sequence end |
.at_levels(level, set_level, conditional_level) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/regexp_parser/expression/sequence.rb', line 32 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(token, text, min = nil, max = nil, mode = :greedy) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/regexp_parser/expression/sequence.rb', line 56 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 ⇒ Object Also known as: ts
51 52 53 |
# File 'lib/regexp_parser/expression/sequence.rb', line 51 def starts_at expressions.first.starts_at end |
#text ⇒ Object
47 48 49 |
# File 'lib/regexp_parser/expression/sequence.rb', line 47 def text to_s end |