Sha256: 949ecde78baf189bdd2724ee6b685db87da75bc510163c0218261a6fd78e7c07

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 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)
        write(T_DCL) if scope.type != :cbase
      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

2 entries across 2 versions & 1 rubygems

Version Path
unparser-0.1.14 lib/unparser/emitter/variable.rb
unparser-0.1.13 lib/unparser/emitter/variable.rb