comparison vendor/gems/coderay-1.0.0/lib/coderay/encoders/debug.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents
children
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 module CodeRay
2 module Encoders
3
4 # = Debug Encoder
5 #
6 # Fast encoder producing simple debug output.
7 #
8 # It is readable and diff-able and is used for testing.
9 #
10 # You cannot fully restore the tokens information from the
11 # output, because consecutive :space tokens are merged.
12 # Use Tokens#dump for caching purposes.
13 #
14 # See also: Scanners::Debug
15 class Debug < Encoder
16
17 register_for :debug
18
19 FILE_EXTENSION = 'raydebug'
20
21 def initialize options = {}
22 super
23 @opened = []
24 end
25
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
35
36 def begin_group kind
37 @opened << kind
38 @out << kind.to_s << '<'
39 end
40
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
49
50 def begin_line kind
51 @out << kind.to_s << '['
52 end
53
54 def end_line kind
55 @out << ']'
56 end
57
58 end
59
60 end
61 end