module Antelope::Generator

Contains the classes that generate parsers. This contains a registery of all of the generators available to antelope.

Public Instance Methods

directives() click to toggle source

Returns a hash of all of the directives that are available in the generators of this module.

@see .generators @return [Hash]

# File lib/antelope/generator.rb, line 24
def directives
  generators.values.map(&:directives).
    inject({}, :merge)
end
generators() click to toggle source

Returns a hash of all of the generators registered within this module. If a generator is accessed that does not exist on the hash, it by default returns the {Generator::Null} class.

@return [Hash<(Symbol, String) => Generator::Base>]

# File lib/antelope/generator.rb, line 16
def generators
  @_generators ||= Hash.new { |h, k| h[k] = Generator::Null }
end
register_generator(generator, *names) click to toggle source

Registers a generator with the given names. If multiple names are given, they are assigned the generator as a value in the {#generators} hash; otherwise, the one name is assigned the generator as a value.

@param generator [Generator::Base] the generator class to

associate the key with.

@param name [String, Symbol] a name to associate the generator

with.
# File lib/antelope/generator.rb, line 38
def register_generator(generator, *names)
  names = [names].flatten
  raise ArgumentError,
    "Requires at least one name" unless names.any?
  raise ArgumentError,
    "All name values must be a Symbol or string" unless names.
    all? {|_| [Symbol, String].include?(_.class) }

  names.each do |name|
    generators[name.to_s.downcase] = generator
  end
end