Sha256: 3167eb5f12c78c629fe4322acdeddd8371d127601f7b4326872c518a4b77ad5d

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8

module Unparser
  class Emitter

    # Emitter for various variable accesses
    class Variable < self
      include Terminated

      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
      include Terminated

      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)
        write(T_DCL) unless scope.type.equal?(:cbase)
      end
    end

    # Emitter for nth_ref nodes (regexp captures)
    class NthRef < self
      include Terminated

      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

6 entries across 6 versions & 1 rubygems

Version Path
unparser-0.2.4 lib/unparser/emitter/variable.rb
unparser-0.2.3 lib/unparser/emitter/variable.rb
unparser-0.2.2 lib/unparser/emitter/variable.rb
unparser-0.2.1 lib/unparser/emitter/variable.rb
unparser-0.2.0 lib/unparser/emitter/variable.rb
unparser-0.1.16 lib/unparser/emitter/variable.rb