Class CodeRay::Encoders::Debug
In: lib/coderay/encoders/debug.rb
Parent: Encoder

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

Methods

Constants

FILE_EXTENSION = 'raydebug'

Public Class methods

[Source]

    # File lib/coderay/encoders/debug.rb, line 21
21:     def initialize options = {}
22:       super
23:       @opened = []
24:     end

Public Instance methods

[Source]

    # File lib/coderay/encoders/debug.rb, line 36
36:     def begin_group kind
37:       @opened << kind
38:       @out << kind.to_s << '<'
39:     end

[Source]

    # File lib/coderay/encoders/debug.rb, line 50
50:     def begin_line kind
51:       @out << kind.to_s << '['
52:     end

[Source]

    # File lib/coderay/encoders/debug.rb, line 41
41:     def end_group kind
42:       if @opened.last != kind
43:         puts @out
44:         raise "we are inside #{@opened.inspect}, not #{kind}"
45:       end
46:       @opened.pop
47:       @out << '>'
48:     end

[Source]

    # File lib/coderay/encoders/debug.rb, line 54
54:     def end_line kind
55:       @out << ']'
56:     end

[Source]

    # File lib/coderay/encoders/debug.rb, line 26
26:     def text_token text, kind
27:       if kind == :space
28:         @out << text
29:       else
30:         # TODO: Escape (
31:         text = text.gsub(/[)\\]/, '\\\\\0')  # escape ) and          @out << kind.to_s << '(' << text << ')'
32:       end
33:     end

[Validate]