summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2013-06-23 05:53:53 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2013-06-23 05:53:53 +0200
commite7df328cb49fd09a4e5d0f02e877e3270a8703ed (patch)
tree180a43a50bef12da35f6667a2bd31ad84bd8f202
parent39c074f171eeca1c91aa89757a3f3a12fc78323b (diff)
downloadcoderay-e7df328cb49fd09a4e5d0f02e877e3270a8703ed.tar.gz
DebugLint check open tokens at the end
-rw-r--r--lib/coderay/encoders/debug_lint.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/coderay/encoders/debug_lint.rb b/lib/coderay/encoders/debug_lint.rb
index 0ac89ef..17a0795 100644
--- a/lib/coderay/encoders/debug_lint.rb
+++ b/lib/coderay/encoders/debug_lint.rb
@@ -19,11 +19,6 @@ module Encoders
EmptyToken = Class.new InvalidTokenStream
IncorrectTokenGroupNesting = Class.new InvalidTokenStream
- def initialize options = {}
- super
- @opened = []
- end
-
def text_token text, kind
raise EmptyToken, 'empty token' if text.empty?
super
@@ -35,7 +30,8 @@ module Encoders
end
def end_group kind
- raise IncorrectTokenGroupNesting, "We are inside #{@opened.inspect}, not #{kind} (end_group)" if @opened.pop != kind
+ raise IncorrectTokenGroupNesting, 'We are inside %s, not %p (end_group)' % [@opened.reverse.map(&:inspect).join(' < '), kind] if @opened.last != kind
+ @opened.pop
super
end
@@ -45,7 +41,20 @@ module Encoders
end
def end_line kind
- raise IncorrectTokenGroupNesting, "We are inside #{@opened.inspect}, not #{kind} (end_line)" if @opened.pop != kind
+ raise IncorrectTokenGroupNesting, 'We are inside %s, not %p (end_line)' % [@opened.reverse.map(&:inspect).join(' < '), kind] if @opened.last != kind
+ @opened.pop
+ super
+ end
+
+ protected
+
+ def setup options
+ super
+ @opened = []
+ end
+
+ def finish options
+ raise 'Some tokens still open at end of token stream: %p' % [@opened] unless @opened.empty?
super
end