Sha256: 71cbe5909ec87ab930370be6a94a813a52ee98246135335379a5b94750aa0f53

Contents?: true

Size: 895 Bytes

Versions: 2

Compression:

Stored size: 895 Bytes

Contents

module Sequitur
  module Formatter
  
    # Superclass for grammar formatters.
    class BaseFormatter
      # The IO output stream in which the formatter's result will be sent.
      attr(:output)

      # Constructor.
      # [anIO] an output IO where the formatter's result will be placed.
      def initialize(anIO)
        @output = anIO
      end

      public
      
      # Given a grammar or a grammar visitor, perform the visit
      # and render the visit events in the output stream.
      def render(aGrmOrVisitor)
        if aGrmOrVisitor.kind_of?(GrammarVisitor)
          a_visitor = aGrmOrVisitor
        else
          a_visitor = aGrmOrVisitor.visitor
        end
        
        a_visitor.subscribe(self)
        a_visitor.start
        a_visitor.unsubscribe(self)
      end
    
    end # class
  end # module
end # module

# End of file

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sequitur-0.1.03 lib/sequitur/formatter/base_formatter.rb
sequitur-0.1.02 lib/sequitur/formatter/base_formatter.rb