Sha256: 35f4f45f74074076e54e9c7b87190a3c150b05fdf863beecab874914c82dc22d

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

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

6 entries across 6 versions & 1 rubygems

Version Path
unparser-0.1.5 lib/unparser/emitter/variable.rb
unparser-0.1.4 lib/unparser/emitter/variable.rb
unparser-0.1.3 lib/unparser/emitter/variable.rb
unparser-0.1.2 lib/unparser/emitter/variable.rb
unparser-0.1.1 lib/unparser/emitter/variable.rb
unparser-0.1.0 lib/unparser/emitter/variable.rb