Sha256: 27e95ff36e77e696d7716c8806260692ea2d80a214a9cfa3f64d48c3efcf8ae6

Contents?: true

Size: 967 Bytes

Versions: 4

Compression:

Stored size: 967 Bytes

Contents

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

      # Constructor.
      # @param anIO [IO] 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.
      # @param aGrmOrVisitor [DynamicGrammar or GrammarVisitor]
      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

4 entries across 4 versions & 1 rubygems

Version Path
sequitur-0.1.17 lib/sequitur/formatter/base_formatter.rb
sequitur-0.1.16 lib/sequitur/formatter/base_formatter.rb
sequitur-0.1.15 lib/sequitur/formatter/base_formatter.rb
sequitur-0.1.14 lib/sequitur/formatter/base_formatter.rb