coderay 0.7.1.147 → 0.7.2.165
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/coderay +54 -56
- data/demo/suite.rb +54 -54
- data/lib/coderay.rb +187 -187
- data/lib/coderay/duo.rb +29 -29
- data/lib/coderay/encoder.rb +173 -173
- data/lib/coderay/encoders/_map.rb +8 -8
- data/lib/coderay/encoders/count.rb +21 -21
- data/lib/coderay/encoders/debug.rb +46 -46
- data/lib/coderay/encoders/div.rb +20 -20
- data/lib/coderay/encoders/html.rb +249 -245
- data/lib/coderay/encoders/html/classes.rb +73 -73
- data/lib/coderay/encoders/html/css.rb +65 -65
- data/lib/coderay/encoders/html/numerization.rb +122 -122
- data/lib/coderay/encoders/html/output.rb +195 -195
- data/lib/coderay/encoders/null.rb +26 -26
- data/lib/coderay/encoders/page.rb +21 -21
- data/lib/coderay/encoders/span.rb +20 -20
- data/lib/coderay/encoders/statistic.rb +81 -81
- data/lib/coderay/encoders/text.rb +33 -33
- data/lib/coderay/encoders/tokens.rb +44 -44
- data/lib/coderay/encoders/xml.rb +71 -71
- data/lib/coderay/encoders/yaml.rb +22 -22
- data/lib/coderay/helpers/filetype.rb +152 -153
- data/lib/coderay/helpers/gzip_simple.rb +67 -68
- data/lib/coderay/helpers/plugin.rb +297 -297
- data/lib/coderay/helpers/word_list.rb +46 -47
- data/lib/coderay/scanner.rb +238 -238
- data/lib/coderay/scanners/_map.rb +15 -14
- data/lib/coderay/scanners/c.rb +163 -155
- data/lib/coderay/scanners/delphi.rb +131 -129
- data/lib/coderay/scanners/html.rb +174 -167
- data/lib/coderay/scanners/nitro_xhtml.rb +130 -0
- data/lib/coderay/scanners/plaintext.rb +15 -15
- data/lib/coderay/scanners/rhtml.rb +73 -65
- data/lib/coderay/scanners/ruby.rb +404 -397
- data/lib/coderay/scanners/ruby/patterns.rb +216 -216
- data/lib/coderay/scanners/xml.rb +18 -18
- data/lib/coderay/style.rb +20 -20
- data/lib/coderay/styles/_map.rb +3 -3
- data/lib/coderay/styles/cycnus.rb +18 -18
- data/lib/coderay/styles/murphy.rb +18 -18
- data/lib/coderay/tokens.rb +322 -322
- metadata +86 -86
- data/lib/coderay/scanners/nitro_html.rb +0 -125
- data/lib/coderay/scanners/yaml.rb +0 -85
@@ -1,14 +1,15 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Scanners
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
map :cpp => :c,
|
5
|
+
:plain => :plaintext,
|
6
|
+
:pascal => :delphi,
|
7
|
+
:irb => :ruby,
|
8
|
+
:xml => :html,
|
9
|
+
:xhtml => :nitro_xhtml,
|
10
|
+
:nitro => :nitro_xhtml
|
11
|
+
|
12
|
+
default :plain
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/coderay/scanners/c.rb
CHANGED
@@ -1,155 +1,163 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Scanners
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
class C < Scanner
|
5
|
+
|
6
|
+
register_for :c
|
7
|
+
|
8
|
+
RESERVED_WORDS = [
|
9
|
+
'asm', 'break', 'case', 'continue', 'default', 'do', 'else',
|
10
|
+
'for', 'goto', 'if', 'return', 'switch', 'while',
|
11
|
+
'struct', 'union', 'enum', 'typedef',
|
12
|
+
'static', 'register', 'auto', 'extern',
|
13
|
+
'sizeof',
|
14
|
+
'volatile', 'const', # C89
|
15
|
+
'inline', 'restrict', # C99
|
16
|
+
]
|
17
|
+
|
18
|
+
PREDEFINED_TYPES = [
|
19
|
+
'int', 'long', 'short', 'char', 'void',
|
20
|
+
'signed', 'unsigned', 'float', 'double',
|
21
|
+
'bool', 'complex', # C99
|
22
|
+
]
|
23
|
+
|
24
|
+
PREDEFINED_CONSTANTS = [
|
25
|
+
'EOF', 'NULL',
|
26
|
+
'true', 'false', # C99
|
27
|
+
]
|
28
|
+
|
29
|
+
IDENT_KIND = WordList.new(:ident).
|
30
|
+
add(RESERVED_WORDS, :reserved).
|
31
|
+
add(PREDEFINED_TYPES, :pre_type).
|
32
|
+
add(PREDEFINED_CONSTANTS, :pre_constant)
|
33
|
+
|
34
|
+
ESCAPE = / [rbfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x
|
35
|
+
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x
|
36
|
+
|
37
|
+
def scan_tokens tokens, options
|
38
|
+
|
39
|
+
state = :initial
|
40
|
+
|
41
|
+
until eos?
|
42
|
+
|
43
|
+
kind = nil
|
44
|
+
match = nil
|
45
|
+
|
46
|
+
case state
|
47
|
+
|
48
|
+
when :initial
|
49
|
+
|
50
|
+
if scan(/ \s+ | \\\n /x)
|
51
|
+
kind = :space
|
52
|
+
|
53
|
+
elsif scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
|
54
|
+
kind = :comment
|
55
|
+
|
56
|
+
elsif match = scan(/ \# \s* if \s* 0 /x)
|
57
|
+
match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
|
58
|
+
kind = :comment
|
59
|
+
|
60
|
+
elsif scan(/ [-+*\/=<>?:;,!&^|()\[\]{}~%]+ | \.(?!\d) /x)
|
61
|
+
kind = :operator
|
62
|
+
|
63
|
+
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
64
|
+
kind = IDENT_KIND[match]
|
65
|
+
if kind == :ident and check(/:(?!:)/)
|
66
|
+
match << scan(/:/)
|
67
|
+
kind = :label
|
68
|
+
end
|
69
|
+
|
70
|
+
elsif match = scan(/L?"/)
|
71
|
+
tokens << [:open, :string]
|
72
|
+
if match[0] == ?L
|
73
|
+
tokens << ['L', :modifier]
|
74
|
+
match = '"'
|
75
|
+
end
|
76
|
+
state = :string
|
77
|
+
kind = :delimiter
|
78
|
+
|
79
|
+
elsif scan(/#\s*(\w*)/)
|
80
|
+
kind = :preprocessor # FIXME multiline preprocs
|
81
|
+
state = :include_expected if self[1] == 'include'
|
82
|
+
|
83
|
+
elsif scan(/ L?' (?: [^\'\n\\] | \\ #{ESCAPE} )? '? /ox)
|
84
|
+
kind = :char
|
85
|
+
|
86
|
+
elsif scan(/0[xX][0-9A-Fa-f]+/)
|
87
|
+
kind = :hex
|
88
|
+
|
89
|
+
elsif scan(/(?:0[0-7]+)(?![89.eEfF])/)
|
90
|
+
kind = :oct
|
91
|
+
|
92
|
+
elsif scan(/(?:\d+)(?![.eEfF])/)
|
93
|
+
kind = :integer
|
94
|
+
|
95
|
+
elsif scan(/\d[fF]?|\d*\.\d+(?:[eE][+-]?\d+)?[fF]?|\d+[eE][+-]?\d+[fF]?/)
|
96
|
+
kind = :float
|
97
|
+
|
98
|
+
else
|
99
|
+
getch
|
100
|
+
kind = :error
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
when :string
|
105
|
+
if scan(/[^\\\n"]+/)
|
106
|
+
kind = :content
|
107
|
+
elsif scan(/"/)
|
108
|
+
tokens << ['"', :delimiter]
|
109
|
+
tokens << [:close, :string]
|
110
|
+
state = :initial
|
111
|
+
next
|
112
|
+
elsif scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
|
113
|
+
kind = :char
|
114
|
+
elsif scan(/ \\ | $ /x)
|
115
|
+
tokens << [:close, :string]
|
116
|
+
kind = :error
|
117
|
+
state = :initial
|
118
|
+
else
|
119
|
+
raise_inspect "else case \" reached; %p not handled." % peek(1), tokens
|
120
|
+
end
|
121
|
+
|
122
|
+
when :include_expected
|
123
|
+
if scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
|
124
|
+
kind = :include
|
125
|
+
state = :initial
|
126
|
+
|
127
|
+
elsif match = scan(/\s+/)
|
128
|
+
kind = :space
|
129
|
+
state = :initial if match.index ?\n
|
130
|
+
|
131
|
+
else
|
132
|
+
getch
|
133
|
+
kind = :error
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
else
|
138
|
+
raise_inspect 'Unknown state', tokens
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
match ||= matched
|
143
|
+
if $DEBUG and not kind
|
144
|
+
raise_inspect 'Error token %p in line %d' %
|
145
|
+
[[match, kind], line], tokens
|
146
|
+
end
|
147
|
+
raise_inspect 'Empty token', tokens unless match
|
148
|
+
|
149
|
+
tokens << [match, kind]
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
if state == :string
|
154
|
+
tokens << [:close, :string]
|
155
|
+
end
|
156
|
+
|
157
|
+
tokens
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
end
|
@@ -1,129 +1,131 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Scanners
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
class Delphi < Scanner
|
5
|
+
|
6
|
+
register_for :delphi
|
7
|
+
|
8
|
+
RESERVED_WORDS = [
|
9
|
+
'and', 'array', 'as', 'at', 'asm', 'at', 'begin', 'case', 'class',
|
10
|
+
'const', 'constructor', 'destructor', 'dispinterface', 'div', 'do',
|
11
|
+
'downto', 'else', 'end', 'except', 'exports', 'file', 'finalization',
|
12
|
+
'finally', 'for', 'function', 'goto', 'if', 'implementation', 'in',
|
13
|
+
'inherited', 'initialization', 'inline', 'interface', 'is', 'label',
|
14
|
+
'library', 'mod', 'nil', 'not', 'object', 'of', 'or', 'out', 'packed',
|
15
|
+
'procedure', 'program', 'property', 'raise', 'record', 'repeat',
|
16
|
+
'resourcestring', 'set', 'shl', 'shr', 'string', 'then', 'threadvar',
|
17
|
+
'to', 'try', 'type', 'unit', 'until', 'uses', 'var', 'while', 'with',
|
18
|
+
'xor', 'on'
|
19
|
+
]
|
20
|
+
|
21
|
+
DIRECTIVES = [
|
22
|
+
'absolute', 'abstract', 'assembler', 'at', 'automated', 'cdecl',
|
23
|
+
'contains', 'deprecated', 'dispid', 'dynamic', 'export',
|
24
|
+
'external', 'far', 'forward', 'implements', 'local',
|
25
|
+
'near', 'nodefault', 'on', 'overload', 'override',
|
26
|
+
'package', 'pascal', 'platform', 'private', 'protected', 'public',
|
27
|
+
'published', 'read', 'readonly', 'register', 'reintroduce',
|
28
|
+
'requires', 'resident', 'safecall', 'stdcall', 'stored', 'varargs',
|
29
|
+
'virtual', 'write', 'writeonly'
|
30
|
+
]
|
31
|
+
|
32
|
+
IDENT_KIND = CaseIgnoringWordList.new(:ident).
|
33
|
+
add(RESERVED_WORDS, :reserved).
|
34
|
+
add(DIRECTIVES, :directive)
|
35
|
+
|
36
|
+
def scan_tokens tokens, options
|
37
|
+
|
38
|
+
state = :initial
|
39
|
+
|
40
|
+
until eos?
|
41
|
+
|
42
|
+
kind = nil
|
43
|
+
match = nil
|
44
|
+
|
45
|
+
if state == :initial
|
46
|
+
|
47
|
+
if scan(/ \s+ /x)
|
48
|
+
kind = :space
|
49
|
+
|
50
|
+
elsif scan(%r! \{ \$ [^}]* \}? | \(\* \$ (?: .*? \*\) | .* ) !mx)
|
51
|
+
kind = :preprocessor
|
52
|
+
|
53
|
+
elsif scan(%r! // [^\n]* | \{ [^}]* \}? | \(\* (?: .*? \*\) | .* ) !mx)
|
54
|
+
kind = :comment
|
55
|
+
|
56
|
+
elsif scan(/ [-+*\/=<>:;,.@\^|\(\)\[\]]+ /x)
|
57
|
+
kind = :operator
|
58
|
+
|
59
|
+
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
60
|
+
kind = IDENT_KIND[match]
|
61
|
+
|
62
|
+
elsif match = scan(/ ' ( [^\n']|'' ) (?:'|$) /x)
|
63
|
+
tokens << [:open, :char]
|
64
|
+
tokens << ["'", :delimiter]
|
65
|
+
tokens << [self[1], :content]
|
66
|
+
tokens << ["'", :delimiter]
|
67
|
+
tokens << [:close, :char]
|
68
|
+
next
|
69
|
+
|
70
|
+
elsif match = scan(/ ' /x)
|
71
|
+
tokens << [:open, :string]
|
72
|
+
state = :string
|
73
|
+
kind = :delimiter
|
74
|
+
|
75
|
+
elsif scan(/ \# (?: \d+ | \$[0-9A-Fa-f]+ ) /x)
|
76
|
+
kind = :char
|
77
|
+
|
78
|
+
elsif scan(/ \$ [0-9A-Fa-f]+ /x)
|
79
|
+
kind = :hex
|
80
|
+
|
81
|
+
elsif scan(/ (?: \d+ ) (?![eE]|\.[^.]) /x)
|
82
|
+
kind = :integer
|
83
|
+
|
84
|
+
elsif scan(/ \d+ (?: \.\d+ (?: [eE][+-]? \d+ )? | [eE][+-]? \d+ ) /x)
|
85
|
+
kind = :float
|
86
|
+
|
87
|
+
else
|
88
|
+
kind = :error
|
89
|
+
getch
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
elsif state == :string
|
94
|
+
if scan(/[^\n']+/)
|
95
|
+
kind = :content
|
96
|
+
elsif scan(/''/)
|
97
|
+
kind = :char
|
98
|
+
elsif scan(/'/)
|
99
|
+
tokens << ["'", :delimiter]
|
100
|
+
tokens << [:close, :string]
|
101
|
+
state = :initial
|
102
|
+
next
|
103
|
+
elsif scan(/\n/)
|
104
|
+
state = :initial
|
105
|
+
else
|
106
|
+
raise "else case \' reached; %p not handled." % peek(1), tokens
|
107
|
+
end
|
108
|
+
|
109
|
+
else
|
110
|
+
raise 'else-case reached', tokens
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
match ||= matched
|
115
|
+
if $DEBUG and not kind
|
116
|
+
raise_inspect 'Error token %p in line %d' %
|
117
|
+
[[match, kind], line], tokens
|
118
|
+
end
|
119
|
+
raise_inspect 'Empty token', tokens unless match
|
120
|
+
|
121
|
+
tokens << [match, kind]
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
tokens
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|