To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 27 / 273ac825eb891aaec6af1c5e2e94f14d0663c303.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (1.18 KB)
| 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 |