Sha256: 06d9fcb4c281bba8e36259222e468fb5c056f79a5fff8937e5a96d5b27ba40dc

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

module Antelope
  module Generator

    # Generates an output file, mainly for debugging.  Included always
    # as a generator for a grammar.
    class Info < Base

      register_as "info"

      # Defines singleton method for every mod that the grammar passed
      # to the generator.
      #
      # @see Generator#initialize
      def initialize(*)
        super
        mods.each do |k, v|
          define_singleton_method (k) { v }
        end
      end

      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

      # Actually performs the generation.  Uses the template in
      # output.erb, and generates the file `<file>.output`.
      #
      # @return [void]
      def generate
        template "info", "#{file}.inf"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
antelope-0.3.2 lib/antelope/generator/info.rb
antelope-0.3.0 lib/antelope/generator/info.rb
antelope-0.2.4 lib/antelope/generator/info.rb
antelope-0.2.3 lib/antelope/generator/info.rb
antelope-0.2.2 lib/antelope/generator/info.rb