Module: Antelope::Generator

Extended by:
Generator
Included in:
Generator, Group
Defined in:
lib/antelope/generator.rb,
lib/antelope/generator/c.rb,
lib/antelope/generator/base.rb,
lib/antelope/generator/html.rb,
lib/antelope/generator/info.rb,
lib/antelope/generator/null.rb,
lib/antelope/generator/ruby.rb,
lib/antelope/generator/error.rb,
lib/antelope/generator/group.rb,
lib/antelope/generator/output.rb,
lib/antelope/generator/c_header.rb,
lib/antelope/generator/c_source.rb,
lib/antelope/generator/base/extra.rb,
lib/antelope/generator/base/coerce.rb

Overview

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

Defined Under Namespace

Classes: Base, C, CHeader, CSource, Error, Group, HTML, Info, Null, Output, Ruby

Instance Method Summary collapse

Instance Method Details

#directivesHash

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

Returns:

  • (Hash)

See Also:



24
25
26
27
# File 'lib/antelope/generator.rb', line 24

def directives
  generators.values.map(&:directives).
    inject({}, :merge)
end

#generatorsHash<(Symbol, String) => Generator::Base>

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 Null class.

Returns:



16
17
18
# File 'lib/antelope/generator.rb', line 16

def generators
  @_generators ||= Hash.new { |h, k| h[k] = Generator::Null }
end

#register_generator(generator, *names) ⇒ Object

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.

Parameters:

  • generator (Generator::Base)

    the generator class to associate the key with.

  • name (String, Symbol)

    a name to associate the generator with.

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
# 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