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

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

Instance Attribute Summary collapse

Attributes inherited from Subexpression

#expressions

Instance Method Summary collapse

Methods inherited from Subexpression

#dig, #each_expression, #extract_quantifier_target, #flat_map, #initialize, #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?, #quantify, #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, #inspect, #is?, #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

Instance Attribute Details

#referenced_expressionObject

Returns the value of attribute referenced_expression.



28
29
30
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 28

def referenced_expression
  @referenced_expression
end

Instance Method Details

#<<(exp) ⇒ Object



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

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

#add_sequence(active_opts = {}, params = { ts: 0 }) ⇒ Object Also known as: branch

Raises:



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

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

#branchesObject



50
51
52
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 50

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

#conditionObject



46
47
48
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 46

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

#condition=(exp) ⇒ Object



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

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

#initialize_copy(orig) ⇒ Object



58
59
60
61
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 58

def initialize_copy(orig)
  self.referenced_expression = orig.referenced_expression.dup
  super
end

#referenceObject



54
55
56
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 54

def reference
  condition.reference
end