Class: Regexp::Expression::Conditional::Expression

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

Instance Attribute Summary

Attributes inherited from Subexpression

#expressions

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Subexpression

#dig, #each_expression, #flat_map, #initialize, #initialize_clone, #strfregexp_tree, #te, #to_h, #traverse

Methods inherited from Base

#ascii_classes?, #attributes, #case_insensitive?, #coded_offset, #default_classes?, #free_spacing?, #full_length, #greedy?, #initialize, #initialize_clone, #is?, #match, #matches?, #multiline?, #offset, #one_of?, #possessive?, #quantified?, #quantifier_affix, #quantify, #quantity, #reluctant?, #strfregexp, #terminal?, #to_re, #type?, #unicode_classes?

Constructor Details

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

Instance Method Details

#<<(exp) ⇒ Object



21
22
23
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 21

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

#add_sequenceObject Also known as: branch

Raises:



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

def add_sequence
  raise TooManyBranches.new if branches.length == 2
  Branch.add_to(self, { conditional_level: conditional_level + 1 })
end

#branchesObject



40
41
42
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 40

def branches
  select { |subexp| subexp.is_a?(Sequence) }
end

#conditionObject



36
37
38
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 36

def condition
  find { |subexp| subexp.is_a?(Condition) }
end

#condition=(exp) ⇒ Object



31
32
33
34
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 31

def condition=(exp)
  expressions.delete(condition)
  expressions.unshift(exp)
end

#referenceObject



44
45
46
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 44

def reference
  condition.reference
end

#to_s(format = :full) ⇒ Object



48
49
50
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 48

def to_s(format = :full)
  "#{text}#{condition}#{branches.join('|')})#{quantifier_affix(format)}"
end