Sha256: ab833ae1ad103c679eddc6265b64f8de052c0101ddd25a807c31d90baf0f5ad8

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 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 Output < Base

      register_as "output"

      has_directive "output.show-lookahead", Boolean

      # 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 "output", "#{file}.output"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
antelope-0.2.0 lib/antelope/generator/output.rb
antelope-0.1.11 lib/antelope/generator/output.rb
antelope-0.1.10 lib/antelope/generator/output.rb
antelope-0.1.9 lib/antelope/generator/output.rb