Class: Panini::Nonterminal
- Inherits:
-
Object
- Object
- Panini::Nonterminal
- Defined in:
- lib/nonterminal.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#add_production(production) ⇒ Object
Add a production to the nonterminal.
-
#initialize(name = nil) ⇒ Nonterminal
constructor
Initialize a nonterminal.
-
#productions ⇒ Object
The productions for the nonterminal.
- #to_s ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ Nonterminal
Initialize a nonterminal. Optionally specify a name.
8 9 10 11 |
# File 'lib/nonterminal.rb', line 8 def initialize(name=nil) @productions = [] @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/nonterminal.rb', line 5 def name @name end |
Instance Method Details
#add_production(production) ⇒ Object
Add a production to the nonterminal. It must be an array, but the array can contain any type of Ruby object.
nonterminal.add_production([1, 'a', lambda { ...} ])
18 19 20 21 22 |
# File 'lib/nonterminal.rb', line 18 def add_production(production) raise ArgumentError, "The production must be an Array." unless production.class == Array @productions << production.dup nil end |
#productions ⇒ Object
The productions for the nonterminal.
25 26 27 |
# File 'lib/nonterminal.rb', line 25 def productions @productions.dup end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/nonterminal.rb', line 29 def to_s name.nil? ? super : @name end |