Class: Rley::RGN::RepetitionNode
Overview
A RGN syntax node representing an expression quantified by a ?, * or +.
Constant Summary
collapse
- Repetition2suffix =
{
zero_or_one: '_qmark',
zero_or_more: '_star',
exactly_one: '',
one_or_more: '_plus'
}.freeze
Instance Attribute Summary collapse
#constraints, #subnodes
Attributes inherited from ASTNode
#annotation
Instance Method Summary
collapse
#size
Methods inherited from ASTNode
#annotation_to_text, #done!
Constructor Details
#initialize(child, theRepetition) ⇒ RepetitionNode
Returns a new instance of RepetitionNode.
21
22
23
24
|
# File 'lib/rley/rgn/repetition_node.rb', line 21
def initialize(child, theRepetition)
super([child])
@repetition = theRepetition
end
|
Instance Attribute Details
#repetition ⇒ Symbol
Returns one of: :zero_or_one, :zero_or_more, :one_or_more.
10
11
12
|
# File 'lib/rley/rgn/repetition_node.rb', line 10
def repetition
@repetition
end
|
Instance Method Details
#accept(visitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
45
46
47
|
# File 'lib/rley/rgn/repetition_node.rb', line 45
def accept(visitor)
visitor.visit_repetition_node(self)
end
|
27
28
29
|
# File 'lib/rley/rgn/repetition_node.rb', line 27
def child
subnodes[0]
end
|
#name ⇒ String
32
33
34
35
|
# File 'lib/rley/rgn/repetition_node.rb', line 32
def name
child_name = subnodes[0].name
"rep_#{child_name}#{Repetition2suffix[repetition]}"
end
|
#suffix_plus ⇒ Object
57
58
59
|
# File 'lib/rley/rgn/repetition_node.rb', line 57
def suffix_plus
Repetition2suffix[:one_or_more]
end
|
#suffix_qmark ⇒ Object
49
50
51
|
# File 'lib/rley/rgn/repetition_node.rb', line 49
def suffix_qmark
Repetition2suffix[:zero_or_one]
end
|
#suffix_star ⇒ Object
53
54
55
|
# File 'lib/rley/rgn/repetition_node.rb', line 53
def suffix_star
Repetition2suffix[:zero_or_more]
end
|
#to_text ⇒ String
38
39
40
41
|
# File 'lib/rley/rgn/repetition_node.rb', line 38
def to_text
child_text = subnodes[0].to_text
"rep_#{child_text}#{Repetition2suffix[repetition]}"
end
|