Class: Antelope::Generator::Output

Inherits:
Base
  • Object
show all
Defined in:
lib/antelope/generator/output.rb

Overview

Generates an output file, mainly for debugging. Included always as a generator for a grammar.

Instance Attribute Summary

Attributes inherited from Base

#file, #grammar, #mods

Instance Method Summary collapse

Methods inherited from Base

#productions, register_as, source_root, #table, #template

Constructor Details

#initializeOutput

Defines singleton method for every mod that the grammar passed to the generator.

See Also:

  • Generator#initialize


18
19
20
21
22
23
# File 'lib/antelope/generator/output.rb', line 18

def initialize(*)
  super
  mods.each do |k, v|
    define_singleton_method (k) { v }
  end
end

Instance Method Details

#generatevoid

This method returns an undefined value.

Actually performs the generation. Uses the template in output.erb, and generates the file <file>.output.



44
45
46
# File 'lib/antelope/generator/output.rb', line 44

def generate
  template "output.erb", "#{file}.output"
end

#unused_symbolsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/antelope/generator/output.rb', line 25

def unused_symbols
  @_unused_symbols ||= begin
    used = grammar.all_productions.map(&:items).flatten.uniq
    all  = grammar.symbols.map do |s|
      if Symbol === s
        grammar.find_token(s)
      else
        s
      end
    end

    all - used - [grammar.find_token(:"$start")]
  end
end