diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2013-06-23 13:29:01 +0200 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2013-06-23 13:29:01 +0200 |
commit | 1d445c70edf8d5c878f9a830dcd29f5a3e179923 (patch) | |
tree | 75ad0b7db37981acd3bf54984353e70229e351ad /lib/coderay/encoders/debug.rb | |
parent | d9d6dd5f4a73363ea5d353ecda142f77ed4eba5a (diff) | |
parent | 1e330f16c21c45eff375ba3b12f966c76ba0b393 (diff) | |
download | coderay-1d445c70edf8d5c878f9a830dcd29f5a3e179923.tar.gz |
Merge branch 'master' into upstream
Diffstat (limited to 'lib/coderay/encoders/debug.rb')
-rw-r--r-- | lib/coderay/encoders/debug.rb | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb index 62f9f0a..f4db330 100644 --- a/lib/coderay/encoders/debug.rb +++ b/lib/coderay/encoders/debug.rb @@ -9,7 +9,6 @@ module Encoders # # 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 class Debug < Encoder @@ -18,37 +17,26 @@ module Encoders FILE_EXTENSION = 'raydebug' - def initialize options = {} - super - @opened = [] - end - def text_token text, kind if kind == :space @out << text else - # TODO: Escape ( - text = text.gsub(/[)\\]/, '\\\\\0') if text.index(/[)\\]/) - @out << kind.to_s << '(' << text << ')' + text = text.gsub('\\', '\\\\\\\\') if text.index('\\') + text = text.gsub(')', '\\\\)') if text.index(')') + @out << "#{kind}(#{text})" end end def begin_group kind - @opened << kind - @out << kind.to_s << '<' + @out << "#{kind}<" end def end_group kind - if @opened.last != kind - puts @out - raise "we are inside #{@opened.inspect}, not #{kind}" - end - @opened.pop @out << '>' end def begin_line kind - @out << kind.to_s << '[' + @out << "#{kind}[" end def end_line kind |