File tree 4 files changed +25
-26
lines changed
4 files changed +25
-26
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ module Scanners
5
5
6
6
# = Debug Scanner
7
7
#
8
- # Interprets the output of the Encoders::Debug encoder.
8
+ # Interprets the output of the Encoders::Debug encoder (basically the inverse function) .
9
9
class Debug < Scanner
10
10
11
11
register_for :debug
@@ -31,21 +31,24 @@ def scan_tokens encoder, options
31
31
if @known_token_kinds . include? self [ 1 ]
32
32
encoder . text_token self [ 2 ] . gsub ( /\\ (.)/m , '\1' ) , self [ 1 ] . to_sym
33
33
else
34
- encoder . text_token matched , :error
34
+ encoder . text_token matched , :unknown
35
35
end
36
36
37
37
elsif match = scan ( / (\w +) ([<\[ ]) /x )
38
38
if @known_token_kinds . include? self [ 1 ]
39
39
kind = self [ 1 ] . to_sym
40
- opened_tokens << kind
41
- case self [ 2 ]
42
- when '<'
43
- encoder . begin_group kind
44
- when '['
45
- encoder . begin_line kind
46
- else
47
- raise 'CodeRay bug: This case should not be reached.'
48
- end
40
+ else
41
+ kind = :unknown
42
+ end
43
+
44
+ opened_tokens << kind
45
+ case self [ 2 ]
46
+ when '<'
47
+ encoder . begin_group kind
48
+ when '['
49
+ encoder . begin_line kind
50
+ else
51
+ raise 'CodeRay bug: This case should not be reached.'
49
52
end
50
53
51
54
elsif !opened_tokens . empty? && match = scan ( / > /x )
Original file line number Diff line number Diff line change 3
3
module CodeRay
4
4
module Scanners
5
5
6
- # = Debug Scanner
6
+ # = Raydebug Scanner
7
7
#
8
- # Parses the output of the Encoders::Debug encoder.
8
+ # Highlights the output of the Encoders::Debug encoder.
9
9
class Raydebug < Scanner
10
10
11
11
register_for :raydebug
@@ -43,17 +43,12 @@ def scan_tokens encoder, options
43
43
encoder . text_token match , :operator if match = scan ( /\) / )
44
44
45
45
elsif match = scan ( / (\w +) ([<\[ ]) /x )
46
- kind = self [ 1 ]
47
- case self [ 2 ]
48
- when '<'
49
- encoder . text_token kind , :class
50
- when '['
51
- encoder . text_token kind , :class
46
+ encoder . text_token self [ 1 ] , :class
47
+ if @known_token_kinds . include? self [ 1 ]
48
+ kind = self [ 1 ] . to_sym
52
49
else
53
- raise 'CodeRay bug: This case should not be reached.'
50
+ kind = :unknown
54
51
end
55
- # FIXME: cache attack
56
- kind = kind . to_sym
57
52
opened_tokens << kind
58
53
encoder . begin_group kind
59
54
encoder . text_token self [ 2 ] , :operator
Original file line number Diff line number Diff line change @@ -80,5 +80,6 @@ module CodeRay
80
80
:plain => false # almost all scanners
81
81
)
82
82
83
- TokenKinds [ :method ] = TokenKinds [ :function ]
83
+ TokenKinds [ :method ] = TokenKinds [ :function ]
84
+ TokenKinds [ :unknown ] = TokenKinds [ :plain ]
84
85
end
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ def test_creation
51
51
end
52
52
53
53
TEST_INPUT = <<-'DEBUG' . chomp
54
- integer(10)operator((\\\))string<content(test)>head [
54
+ integer(10)operator((\\\))string<content(test)>test [
55
55
56
56
57
57
method([])]
@@ -62,10 +62,10 @@ def test_creation
62
62
[ :begin_group , :string ] ,
63
63
[ 'test' , :content ] ,
64
64
[ :end_group , :string ] ,
65
- [ :begin_line , :head ] ,
65
+ [ :begin_line , :unknown ] ,
66
66
[ "\n \n \t \n " , :space ] ,
67
67
[ "[]" , :method ] ,
68
- [ :end_line , :head ] ,
68
+ [ :end_line , :unknown ] ,
69
69
] . flatten
70
70
71
71
def test_filtering_text_tokens
You can’t perform that action at this time.
0 commit comments