Sha256: fbde68314a3505edd30a5c0f4d29b8d03a2be38a9a413bc254272efc6652fe19

Contents?: true

Size: 1.85 KB

Versions: 12

Compression:

Stored size: 1.85 KB

Contents

module Unparser
  class Emitter
    class Literal

      # Base class for primitive emitters
      class Primitive < self

        children :value

      private

        # Emitter for primitives based on Object#inspect
        class Inspect < self

          handle :float, :sym, :int

        private

          # Dispatch value
          #
          # @return [undefined]
          #
          # @api private
          #
          def dispatch
            buffer.append(value.inspect)
          end

        end # Inspect

        # Literal emitter with macro regeneration base class
        class MacroSafe < self

        private

          # Perform dispatch
          #
          # @return [undefined]
          #
          # @api private
          #
          def dispatch
            if(source == macro)
              write(macro)
              return
            end
            write(value.inspect)
          end

          # Return source, if present
          #
          # @return [String]
          #   if present
          #
          # @return [nil]
          #   otherwise
          #
          # @api private
          #
          def source
            location = node.location || return
            expression = location.expression || return
            expression.source
          end

          # Return marco
          #
          # @return [String]
          #
          # @api private
          #
          def macro
            self.class::MACRO
          end

          # String macro safe emitter
          class String < self
            MACRO = '__FILE__'.freeze
            handle :str
          end # String

          # Integer macro safe emitter
          class Integer < self
            MACRO = '__LINE__'.freeze
            handle :int
          end # Integer

        end # MacroSave
      end # Primitive
    end # Literal
  end # Emitter
end # Unparser

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
unparser-0.1.3 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.2 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.1 lib/unparser/emitter/literal/primitive.rb
unparser-0.1.0 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.18 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.16 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.15 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.14 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.13 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.12 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.11 lib/unparser/emitter/literal/primitive.rb
unparser-0.0.10 lib/unparser/emitter/literal/primitive.rb