File tree Expand file tree Collapse file tree 3 files changed +56
-15
lines changed Expand file tree Collapse file tree 3 files changed +56
-15
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ h2. Changes in 1.1
20
20
* Override Bootstrap's pre word-break setting for line numbers [#102, thanks to lightswitch05]
21
21
* Fixed @:docstring@ token type style
22
22
* @Plugin@ does not warn about fallback when default is defined
23
+ * @Debug@ encoder refactored; use @DebugLint@ if you want strict checking now
23
24
24
25
h2. Changes in 1.0.9
25
26
Original file line number Diff line number Diff line change @@ -18,14 +18,7 @@ class Debug < Encoder
18
18
19
19
FILE_EXTENSION = 'raydebug'
20
20
21
- def initialize options = { }
22
- super
23
- @opened = [ ]
24
- end
25
-
26
21
def text_token text , kind
27
- raise 'empty token' if $CODERAY_DEBUG && text . empty?
28
-
29
22
if kind == :space
30
23
@out << text
31
24
else
@@ -36,26 +29,18 @@ def text_token text, kind
36
29
end
37
30
38
31
def begin_group kind
39
- @opened << kind if $CODERAY_DEBUG
40
-
41
32
@out << "#{ kind } <"
42
33
end
43
34
44
35
def end_group kind
45
- raise "We are inside #{ @opened . inspect } , not #{ kind } " if $CODERAY_DEBUG && @opened . pop != kind
46
-
47
36
@out << '>'
48
37
end
49
38
50
39
def begin_line kind
51
- @opened << kind if $CODERAY_DEBUG
52
-
53
40
@out << "#{ kind } ["
54
41
end
55
42
56
43
def end_line kind
57
- raise "We are inside #{ @opened . inspect } , not #{ kind } " if $CODERAY_DEBUG && @opened . pop != kind
58
-
59
44
@out << ']'
60
45
end
61
46
Original file line number Diff line number Diff line change
1
+ module CodeRay
2
+ module Encoders
3
+
4
+ # = Debug Lint Encoder
5
+ #
6
+ # Debug encoder with additional checks for:
7
+ #
8
+ # - empty tokens
9
+ # - incorrect nesting
10
+ #
11
+ # It will raise an InvalidTokenStream exception when any of the above occurs.
12
+ #
13
+ # See also: Encoders::Debug
14
+ class DebugLint < Debug
15
+
16
+ register_for :debug_lint
17
+
18
+ InvalidTokenStream = Class . new StandardError
19
+ EmptyToken = Class . new InvalidTokenStream
20
+ IncorrectTokenGroupNesting = Class . new InvalidTokenStream
21
+
22
+ def initialize options = { }
23
+ super
24
+ @opened = [ ]
25
+ end
26
+
27
+ def text_token text , kind
28
+ raise EmptyToken , 'empty token' if text . empty?
29
+ super
30
+ end
31
+
32
+ def begin_group kind
33
+ @opened << kind
34
+ super
35
+ end
36
+
37
+ def end_group kind
38
+ raise IncorrectTokenGroupNesting , "We are inside #{ @opened . inspect } , not #{ kind } " if @opened . pop != kind
39
+ super
40
+ end
41
+
42
+ def begin_line kind
43
+ @opened << kind
44
+ super
45
+ end
46
+
47
+ def end_line kind
48
+ raise IncorrectTokenGroupNesting , "We are inside #{ @opened . inspect } , not #{ kind } " if @opened . pop != kind
49
+ super
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
You can’t perform that action at this time.
0 commit comments