Sha256: a6a2822704e98abbf0a24803e4f4b9a6cae69c8adc5e27bdb1fdf3456c60cb3d

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

module Unparser
  class Emitter

    # Emitter for various variable accesses
    class Variable < self

      handle :ivar, :lvar, :cvar, :gvar, :back_ref

      children :name

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        write(name.to_s)
      end

    end # Access

    # Emitter for constant access
    class Const < self

      handle :const

      children :scope, :name

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        emit_scope
        write(name.to_s)
      end

      # Emit parent
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_scope
        return unless scope
        visit(scope)
        if scope.type != :cbase
          write(T_DCL)
        end
      end
    end

    # Emitter for nth_ref nodes (regexp captures)
    class NthRef < self
      PREFIX = '$'.freeze
      handle :nth_ref

      children :name

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        write(PREFIX)
        write(name.to_s)
      end

    end # NthRef

  end # Emitter
end # Unparser

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
unparser-0.1.12 lib/unparser/emitter/variable.rb
unparser-0.1.11 lib/unparser/emitter/variable.rb
unparser-0.1.10 lib/unparser/emitter/variable.rb
unparser-0.1.9 lib/unparser/emitter/variable.rb
unparser-0.1.8 lib/unparser/emitter/variable.rb
unparser-0.1.7 lib/unparser/emitter/variable.rb
unparser-0.1.6 lib/unparser/emitter/variable.rb