Class: Rley::RGN::RepetitionNode

Inherits:
CompositeNode show all
Defined in:
lib/rley/rgn/repetition_node.rb

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

Attributes inherited from CompositeNode

#constraints, #subnodes

Attributes inherited from ASTNode

#annotation

Instance Method Summary collapse

Methods inherited from CompositeNode

#size

Methods inherited from ASTNode

#annotation_to_text, #done!

Constructor Details

#initialize(child, theRepetition) ⇒ RepetitionNode

Returns a new instance of RepetitionNode.

Parameters:

  • child (Array<ASTNode>)

    sequence of AST nodes

  • theRepetition (Symbol)

    how many times the child node can be repeated



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

#repetitionSymbol

Returns one of: :zero_or_one, :zero_or_more, :one_or_more.

Returns:

  • (Symbol)

    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.

Parameters:



45
46
47
# File 'lib/rley/rgn/repetition_node.rb', line 45

def accept(visitor)
  visitor.visit_repetition_node(self)
end

#childRGN::ASTNode

Returns:



27
28
29
# File 'lib/rley/rgn/repetition_node.rb', line 27

def child
  subnodes[0]
end

#nameString

Returns:

  • (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_plusObject



57
58
59
# File 'lib/rley/rgn/repetition_node.rb', line 57

def suffix_plus
  Repetition2suffix[:one_or_more]
end

#suffix_qmarkObject



49
50
51
# File 'lib/rley/rgn/repetition_node.rb', line 49

def suffix_qmark
  Repetition2suffix[:zero_or_one]
end

#suffix_starObject



53
54
55
# File 'lib/rley/rgn/repetition_node.rb', line 53

def suffix_star
  Repetition2suffix[:zero_or_more]
end

#to_textString

Returns:

  • (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