CodeRay::Encoders::Debug

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

Constants

FILE_EXTENSION

Public Class Methods

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

Public Instance Methods

begin_group(kind) click to toggle source
    # File lib/coderay/encoders/debug.rb, line 36
36:     def begin_group kind
37:       @opened << kind
38:       @out << kind.to_s << '<'
39:     end
begin_line(kind) click to toggle source
    # File lib/coderay/encoders/debug.rb, line 50
50:     def begin_line kind
51:       @out << kind.to_s << '['
52:     end
end_group(kind) click to toggle 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
end_line(kind) click to toggle source
    # File lib/coderay/encoders/debug.rb, line 54
54:     def end_line kind
55:       @out << ']'
56:     end
text_token(text, kind) click to toggle 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 \
32:         @out << kind.to_s << '(' << text << ')'
33:       end
34:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.