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_lint.rb | |
parent | d9d6dd5f4a73363ea5d353ecda142f77ed4eba5a (diff) | |
parent | 1e330f16c21c45eff375ba3b12f966c76ba0b393 (diff) | |
download | coderay-1d445c70edf8d5c878f9a830dcd29f5a3e179923.tar.gz |
Merge branch 'master' into upstream
Diffstat (limited to 'lib/coderay/encoders/debug_lint.rb')
-rw-r--r-- | lib/coderay/encoders/debug_lint.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/coderay/encoders/debug_lint.rb b/lib/coderay/encoders/debug_lint.rb new file mode 100644 index 0000000..0ac89ef --- /dev/null +++ b/lib/coderay/encoders/debug_lint.rb @@ -0,0 +1,55 @@ +module CodeRay +module Encoders + + # = Debug Lint Encoder + # + # Debug encoder with additional checks for: + # + # - empty tokens + # - incorrect nesting + # + # It will raise an InvalidTokenStream exception when any of the above occurs. + # + # See also: Encoders::Debug + class DebugLint < Debug + + 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? + super + end + + def begin_group kind + @opened << kind + super + end + + def end_group kind + raise IncorrectTokenGroupNesting, "We are inside #{@opened.inspect}, not #{kind} (end_group)" if @opened.pop != kind + super + end + + def begin_line kind + @opened << kind + super + end + + def end_line kind + raise IncorrectTokenGroupNesting, "We are inside #{@opened.inspect}, not #{kind} (end_line)" if @opened.pop != kind + super + end + + end + +end +end |