Class: Regexp::Expression::Alternation

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

Overview

This is not a subexpression really, but considering it one simplifies the API when it comes to handling the alternatives.

Instance Attribute Summary

Attributes inherited from Subexpression

#expressions

Attributes inherited from Base

#level, #options, #quantifier, #text, #token, #ts, #type

Instance Method Summary collapse

Methods inherited from Subexpression

#[], #clone, #each, #each_with_index, #first, #initialize, #insert, #last, #length

Methods inherited from Base

#case_insensitive?, #clone, #coded_offset, #free_spacing?, #full_length, #greedy?, #initialize, #multiline?, #offset, #possessive?, #quantified?, #quantity, #reluctant?, #terminal?, #to_re

Constructor Details

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

Instance Method Details

#<<(exp) ⇒ Object



10
11
12
# File 'lib/regexp_parser/expression/classes/alternation.rb', line 10

def <<(exp)
  @expressions.last << exp
end

#alternative(exp = nil) ⇒ Object



14
15
16
# File 'lib/regexp_parser/expression/classes/alternation.rb', line 14

def alternative(exp = nil)
  @expressions << (exp ? exp : Sequence.new)
end

#alternativesObject



18
19
20
# File 'lib/regexp_parser/expression/classes/alternation.rb', line 18

def alternatives
  @expressions
end

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



22
23
24
# File 'lib/regexp_parser/expression/classes/alternation.rb', line 22

def quantify(token, text, min = nil, max = nil, mode = :greedy)
  alternatives.last.last.quantify(token, text, min, max, mode)
end

#starts_atObject



6
7
8
# File 'lib/regexp_parser/expression/classes/alternation.rb', line 6

def starts_at
  @expressions.first.starts_at
end

#to_s(format = :full) ⇒ Object



26
27
28
# File 'lib/regexp_parser/expression/classes/alternation.rb', line 26

def to_s(format = :full)
  alternatives.map{|e| e.to_s(format)}.join('|')
end