From df21150ed089f1e3d1d35badde23b2d905a421cd Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Thu, 13 Jun 2013 04:35:39 +0200 Subject: speedup/tweak debug encoder --- lib/coderay/encoders/debug.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'lib/coderay/encoders/debug.rb') diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb index c03d3fb..94d52af 100644 --- a/lib/coderay/encoders/debug.rb +++ b/lib/coderay/encoders/debug.rb @@ -25,34 +25,37 @@ module Encoders def text_token text, kind raise 'empty token' if $CODERAY_DEBUG && text.empty? + 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 << '<' + @opened << kind if $CODERAY_DEBUG + + @out << "#{kind}<" end def end_group kind - if @opened.last != kind - puts @out - raise "we are inside #{@opened.inspect}, not #{kind}" - end - @opened.pop + raise "We are inside #{@opened.inspect}, not #{kind}" if $CODERAY_DEBUG && @opened.pop != kind + @out << '>' end def begin_line kind - @out << kind.to_s << '[' + @opened << kind if $CODERAY_DEBUG + + @out << "#{kind}[" end def end_line kind + raise "We are inside #{@opened.inspect}, not #{kind}" if $CODERAY_DEBUG && @opened.pop != kind + @out << ']' end -- cgit v1.2.1 From 88b812274a808f69675445a9265dab1d4e41cc44 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Thu, 13 Jun 2013 04:46:11 +0200 Subject: refactor check functionality to DebugLint encoder --- lib/coderay/encoders/debug.rb | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'lib/coderay/encoders/debug.rb') diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb index 94d52af..61520a1 100644 --- a/lib/coderay/encoders/debug.rb +++ b/lib/coderay/encoders/debug.rb @@ -18,14 +18,7 @@ module Encoders FILE_EXTENSION = 'raydebug' - def initialize options = {} - super - @opened = [] - end - def text_token text, kind - raise 'empty token' if $CODERAY_DEBUG && text.empty? - if kind == :space @out << text else @@ -36,26 +29,18 @@ module Encoders end def begin_group kind - @opened << kind if $CODERAY_DEBUG - @out << "#{kind}<" end def end_group kind - raise "We are inside #{@opened.inspect}, not #{kind}" if $CODERAY_DEBUG && @opened.pop != kind - @out << '>' end def begin_line kind - @opened << kind if $CODERAY_DEBUG - @out << "#{kind}[" end def end_line kind - raise "We are inside #{@opened.inspect}, not #{kind}" if $CODERAY_DEBUG && @opened.pop != kind - @out << ']' end -- cgit v1.2.1 From e423275749744fb2cf768087a07b4c839eaf4734 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Thu, 13 Jun 2013 05:33:14 +0200 Subject: remove dump/undump functionality --- lib/coderay/encoders/debug.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/coderay/encoders/debug.rb') diff --git a/lib/coderay/encoders/debug.rb b/lib/coderay/encoders/debug.rb index 61520a1..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 -- cgit v1.2.1