Class: Regexp::Expression::Conditional::Expression
Instance Attribute Summary
#expressions
Attributes inherited from Base
#conditional_level, #level, #nesting_level, #options, #quantifier, #set_level, #text, #token, #ts, #type
Instance Method Summary
collapse
#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?
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_sequence ⇒ Object
Also known as:
branch
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
|
#branches ⇒ Object
40
41
42
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 40
def branches
select { |subexp| subexp.is_a?(Sequence) }
end
|
#condition ⇒ Object
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
|
#reference ⇒ Object
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
|