Sha256: 76ab7b8874ef1d568f4766e9e1fe0a9bb89b8925f3322a2c2e3380f6a5d88be0

Contents?: true

Size: 1.18 KB

Versions: 29

Compression:

Stored size: 1.18 KB

Contents

module CodeRay
module Encoders
  
  # = Debug Encoder
  #
  # Fast encoder producing simple debug output.
  #
  # It is readable and diff-able and is used for testing.
  #
  # You cannot fully restore the tokens information from the
  # output, because consecutive :space tokens are merged.
  # Use Tokens#dump for caching purposes.
  # 
  # See also: Scanners::Debug
  class Debug < Encoder
    
    register_for :debug
    
    FILE_EXTENSION = 'raydebug'
    
    def initialize options = {}
      super
      @opened = []
    end
    
    def text_token text, kind
      if kind == :space
        @out << text
      else
        # TODO: Escape (
        text = text.gsub(/[)\\]/, '\\\\\0')  # escape ) and \
        @out << kind.to_s << '(' << text << ')'
      end
    end
    
    def begin_group kind
      @opened << kind
      @out << kind.to_s << '<'
    end
    
    def end_group kind
      if @opened.last != kind
        puts @out
        raise "we are inside #{@opened.inspect}, not #{kind}"
      end
      @opened.pop
      @out << '>'
    end
    
    def begin_line kind
      @out << kind.to_s << '['
    end
    
    def end_line kind
      @out << ']'
    end
    
  end
  
end
end

Version data entries

29 entries across 29 versions & 4 rubygems

Version Path
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/coderay-1.0.9/lib/coderay/encoders/debug.rb
coderay-1.0.9 lib/coderay/encoders/debug.rb
coderay-1.0.9.rc1 lib/coderay/encoders/debug.rb
coderay-1.0.8 lib/coderay/encoders/debug.rb
coderay-1.0.8.rc1 lib/coderay/encoders/debug.rb
coderay-1.0.7 lib/coderay/encoders/debug.rb
coderay-1.0.7.rc2 lib/coderay/encoders/debug.rb
coderay-1.0.7.rc1 lib/coderay/encoders/debug.rb
coderay-1.0.6 lib/coderay/encoders/debug.rb
coderay-1.0.6.rc1 lib/coderay/encoders/debug.rb
coderay-1.0.5 lib/coderay/encoders/debug.rb
coderay-1.0.5.rc1 lib/coderay/encoders/debug.rb
coderay-1.0.4 lib/coderay/encoders/debug.rb