annotate vendor/plugins/coderay-0.9.2/lib/coderay/encoders/debug.rb @ 877:e97cef3bd5d0 bug_70

Close obsolete branch bug_70
author Chris Cannam
date Wed, 30 Mar 2011 10:48:32 +0100
parents 513646585e45
children
rev   line source
Chris@0 1 module CodeRay
Chris@0 2 module Encoders
Chris@0 3
Chris@0 4 # = Debug Encoder
Chris@0 5 #
Chris@0 6 # Fast encoder producing simple debug output.
Chris@0 7 #
Chris@0 8 # It is readable and diff-able and is used for testing.
Chris@0 9 #
Chris@0 10 # You cannot fully restore the tokens information from the
Chris@0 11 # output, because consecutive :space tokens are merged.
Chris@0 12 # Use Tokens#dump for caching purposes.
Chris@0 13 class Debug < Encoder
Chris@0 14
Chris@0 15 include Streamable
Chris@0 16 register_for :debug
Chris@0 17
Chris@0 18 FILE_EXTENSION = 'raydebug'
Chris@0 19
Chris@0 20 protected
Chris@0 21 def text_token text, kind
Chris@0 22 if kind == :space
Chris@0 23 text
Chris@0 24 else
Chris@0 25 text = text.gsub(/[)\\]/, '\\\\\0') # escape ) and \
Chris@0 26 "#{kind}(#{text})"
Chris@0 27 end
Chris@0 28 end
Chris@0 29
Chris@0 30 def open_token kind
Chris@0 31 "#{kind}<"
Chris@0 32 end
Chris@0 33
Chris@0 34 def close_token kind
Chris@0 35 ">"
Chris@0 36 end
Chris@0 37
Chris@0 38 def begin_line kind
Chris@0 39 "#{kind}["
Chris@0 40 end
Chris@0 41
Chris@0 42 def end_line kind
Chris@0 43 "]"
Chris@0 44 end
Chris@0 45
Chris@0 46 end
Chris@0 47
Chris@0 48 end
Chris@0 49 end