Class: CodeRay::Encoders::Debug
- Defined in:
- lib/coderay/encoders/debug.rb
Overview
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
Constant Summary collapse
- FILE_EXTENSION =
'raydebug'
Constants inherited from Encoder
Instance Attribute Summary
Attributes inherited from Encoder
Attributes included from Plugin
Instance Method Summary collapse
- #begin_group(kind) ⇒ Object
- #begin_line(kind) ⇒ Object
- #end_group(kind) ⇒ Object
- #end_line(kind) ⇒ Object
-
#initialize(options = {}) ⇒ Debug
constructor
A new instance of Debug.
- #text_token(text, kind) ⇒ Object
Methods inherited from Encoder
#<<, const_missing, #encode, #encode_tokens, file_extension, #file_extension, #token
Methods included from Plugin
#aliases, #plugin_host, #register_for, #title
Constructor Details
#initialize(options = {}) ⇒ Debug
Returns a new instance of Debug.
21 22 23 24 |
# File 'lib/coderay/encoders/debug.rb', line 21 def initialize = {} super @opened = [] end |
Instance Method Details
#begin_group(kind) ⇒ Object
36 37 38 39 |
# File 'lib/coderay/encoders/debug.rb', line 36 def begin_group kind @opened << kind @out << kind.to_s << '<' end |
#begin_line(kind) ⇒ Object
50 51 52 |
# File 'lib/coderay/encoders/debug.rb', line 50 def begin_line kind @out << kind.to_s << '[' end |
#end_group(kind) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/coderay/encoders/debug.rb', line 41 def end_group kind if @opened.last != kind puts @out raise "we are inside #{@opened.inspect}, not #{kind}" end @opened.pop @out << '>' end |
#end_line(kind) ⇒ Object
54 55 56 |
# File 'lib/coderay/encoders/debug.rb', line 54 def end_line kind @out << ']' end |
#text_token(text, kind) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/coderay/encoders/debug.rb', line 26 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 |