Sha256: af1f2b61341a8e212cb4317eb94b4acab4a4c1af8d94a7295c228d76022595eb

Contents?: true

Size: 1012 Bytes

Versions: 6

Compression:

Stored size: 1012 Bytes

Contents

module Unparser
  class Emitter

    # Emitter for postconditions
    class Post < self

      handle :while_post, :until_post

      children :condition, :body

      MAP = {
        :while_post => K_WHILE,
        :until_post => K_UNTIL
      }.freeze

      handle(*MAP.keys)

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        visit(body)
        write(WS, MAP.fetch(node.type), WS)
        visit(condition)
      end
    end

    # Base class for while and until emitters
    class Repetition < self

      MAP = {
        :while => K_WHILE,
        :until => K_UNTIL
      }.freeze

      handle(*MAP.keys)

      children :condition, :body

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        write(MAP.fetch(node.type), WS)
        visit(condition)
        emit_body
        k_end
      end

    end # Repetition
  end # Emitter
end # Unparser

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unparser-0.1.3 lib/unparser/emitter/repetition.rb
unparser-0.1.2 lib/unparser/emitter/repetition.rb
unparser-0.1.1 lib/unparser/emitter/repetition.rb
unparser-0.1.0 lib/unparser/emitter/repetition.rb
unparser-0.0.18 lib/unparser/emitter/repetition.rb
unparser-0.0.16 lib/unparser/emitter/repetition.rb