summaryrefslogtreecommitdiff
path: root/lib/coderay/encoders/debug_lint.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/coderay/encoders/debug_lint.rb')
-rw-r--r--lib/coderay/encoders/debug_lint.rb31
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/coderay/encoders/debug_lint.rb b/lib/coderay/encoders/debug_lint.rb
index eeb2a92..2c14186 100644
--- a/lib/coderay/encoders/debug_lint.rb
+++ b/lib/coderay/encoders/debug_lint.rb
@@ -1,6 +1,8 @@
module CodeRay
module Encoders
+ load :lint
+
# = Debug Lint Encoder
#
# Debug encoder with additional checks for:
@@ -15,17 +17,8 @@ module Encoders
register_for :debug_lint
- InvalidTokenStream = Class.new StandardError
- 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?
+ raise Lint::EmptyToken, 'empty token' if text.empty?
super
end
@@ -35,7 +28,8 @@ module Encoders
end
def end_group kind
- raise IncorrectTokenGroupNesting, "We are inside #{@opened.inspect}, not #{kind}" if @opened.pop != kind
+ raise Lint::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 +39,20 @@ module Encoders
end
def end_line kind
- raise IncorrectTokenGroupNesting, "We are inside #{@opened.inspect}, not #{kind}" if @opened.pop != kind
+ raise Lint::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