class Panini::Nonterminal

Attributes

name[R]

Public Class Methods

new(name=nil) click to toggle source

Initialize a nonterminal. Optionally specify a name.

# File lib/nonterminal.rb, line 8
def initialize(name=nil)
  @productions = []
  @name = name
end

Public Instance Methods

add_production(production) click to toggle source

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 { ...} ])
# 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() click to toggle source

The productions for the nonterminal.

# File lib/nonterminal.rb, line 25
def productions
  @productions.dup
end
to_s() click to toggle source
Calls superclass method
# File lib/nonterminal.rb, line 29
def to_s
  name.nil? ? super : @name
end