Sha256: 92fc36d5f2916d5b5cd76a6f9c86e49e9e68b0b364802493ea7b57c425645889

Contents?: true

Size: 1.26 KB

Versions: 14

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 :parent, :name

    private

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

      # Emit parent
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_parent
        return unless parent
        visit(parent)
        if parent.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

14 entries across 14 versions & 1 rubygems

Version Path
unparser-0.0.18 lib/unparser/emitter/variable.rb
unparser-0.0.16 lib/unparser/emitter/variable.rb
unparser-0.0.15 lib/unparser/emitter/variable.rb
unparser-0.0.14 lib/unparser/emitter/variable.rb
unparser-0.0.13 lib/unparser/emitter/variable.rb
unparser-0.0.12 lib/unparser/emitter/variable.rb
unparser-0.0.11 lib/unparser/emitter/variable.rb
unparser-0.0.10 lib/unparser/emitter/variable.rb
unparser-0.0.8 lib/unparser/emitter/variable.rb
unparser-0.0.7 lib/unparser/emitter/variable.rb
unparser-0.0.6 lib/unparser/emitter/variable.rb
unparser-0.0.5 lib/unparser/emitter/variable.rb
unparser-0.0.4 lib/unparser/emitter/variable.rb
unparser-0.0.3 lib/unparser/emitter/variable.rb