Sha256: 4e077df3af93397eb7163e6d069b493bcc857997c08ab549ca0aa3fe406c891c

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

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

      # Test if child should be emitted with explicit begin nodes
      #
      # @return [true]
      #
      # @api private
      #
      def needs_begin?
        true
      end

      # 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

2 entries across 2 versions & 1 rubygems

Version Path
unparser-0.0.7 lib/unparser/emitter/repetition.rb
unparser-0.0.6 lib/unparser/emitter/repetition.rb