Sha256: fc2868c64e41d36083dfa3ecfc52e84d26e1cca7a616331132470f14794e9141

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

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

4 entries across 4 versions & 1 rubygems

Version Path
unparser-0.2.8 lib/unparser/emitter/variable.rb
unparser-0.2.7 lib/unparser/emitter/variable.rb
unparser-0.2.6 lib/unparser/emitter/variable.rb
unparser-0.2.5 lib/unparser/emitter/variable.rb