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,216 +1,216 @@
|
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
end
|
216
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
module Ruby::Patterns # :nodoc:
|
5
|
+
|
6
|
+
RESERVED_WORDS = %w[
|
7
|
+
and def end in or unless begin
|
8
|
+
defined? ensure module redo super until
|
9
|
+
BEGIN break do next rescue then
|
10
|
+
when END case else for retry
|
11
|
+
while alias class elsif if not return
|
12
|
+
undef yield
|
13
|
+
]
|
14
|
+
|
15
|
+
DEF_KEYWORDS = %w[ def ]
|
16
|
+
UNDEF_KEYWORDS = %w[ undef ]
|
17
|
+
MODULE_KEYWORDS = %w[class module]
|
18
|
+
DEF_NEW_STATE = WordList.new(:initial).
|
19
|
+
add(DEF_KEYWORDS, :def_expected).
|
20
|
+
add(UNDEF_KEYWORDS, :undef_expected).
|
21
|
+
add(MODULE_KEYWORDS, :module_expected)
|
22
|
+
|
23
|
+
IDENTS_ALLOWING_REGEXP = %w[
|
24
|
+
and or not while until unless if then elsif when sub sub! gsub gsub! scan slice slice! split
|
25
|
+
]
|
26
|
+
REGEXP_ALLOWED = WordList.new(false).
|
27
|
+
add(IDENTS_ALLOWING_REGEXP, :set)
|
28
|
+
|
29
|
+
PREDEFINED_CONSTANTS = %w[
|
30
|
+
nil true false self
|
31
|
+
DATA ARGV ARGF __FILE__ __LINE__
|
32
|
+
]
|
33
|
+
|
34
|
+
IDENT_KIND = WordList.new(:ident).
|
35
|
+
add(RESERVED_WORDS, :reserved).
|
36
|
+
add(PREDEFINED_CONSTANTS, :pre_constant)
|
37
|
+
|
38
|
+
IDENT = /[a-z_][\w_]*/i
|
39
|
+
|
40
|
+
METHOD_NAME = / #{IDENT} [?!]? /ox
|
41
|
+
METHOD_NAME_OPERATOR = /
|
42
|
+
\*\*? # multiplication and power
|
43
|
+
| [-+]@? # plus, minus
|
44
|
+
| [\/%&|^`~] # division, modulo or format strings, &and, |or, ^xor, `system`, tilde
|
45
|
+
| \[\]=? # array getter and setter
|
46
|
+
| << | >> # append or shift left, shift right
|
47
|
+
| <=?>? | >=? # comparison, rocket operator
|
48
|
+
| ===? # simple equality and case equality
|
49
|
+
/ox
|
50
|
+
METHOD_NAME_EX = / #{IDENT} (?:[?!]|=(?!>))? | #{METHOD_NAME_OPERATOR} /ox
|
51
|
+
INSTANCE_VARIABLE = / @ #{IDENT} /ox
|
52
|
+
CLASS_VARIABLE = / @@ #{IDENT} /ox
|
53
|
+
OBJECT_VARIABLE = / @@? #{IDENT} /ox
|
54
|
+
GLOBAL_VARIABLE = / \$ (?: #{IDENT} | [1-9]\d* | 0\w* | [~&+`'=\/,;_.<>!@$?*":\\] | -[a-zA-Z_0-9] ) /ox
|
55
|
+
PREFIX_VARIABLE = / #{GLOBAL_VARIABLE} |#{OBJECT_VARIABLE} /ox
|
56
|
+
VARIABLE = / @?@? #{IDENT} | #{GLOBAL_VARIABLE} /ox
|
57
|
+
|
58
|
+
QUOTE_TO_TYPE = {
|
59
|
+
'`' => :shell,
|
60
|
+
'/'=> :regexp,
|
61
|
+
}
|
62
|
+
QUOTE_TO_TYPE.default = :string
|
63
|
+
|
64
|
+
REGEXP_MODIFIERS = /[mixounse]*/
|
65
|
+
REGEXP_SYMBOLS = /[|?*+?(){}\[\].^$]/
|
66
|
+
|
67
|
+
DECIMAL = /\d+(?:_\d+)*/
|
68
|
+
OCTAL = /0_?[0-7]+(?:_[0-7]+)*/
|
69
|
+
HEXADECIMAL = /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/
|
70
|
+
BINARY = /0b[01]+(?:_[01]+)*/
|
71
|
+
|
72
|
+
EXPONENT = / [eE] [+-]? #{DECIMAL} /ox
|
73
|
+
FLOAT_SUFFIX = / #{EXPONENT} | \. #{DECIMAL} #{EXPONENT}? /ox
|
74
|
+
FLOAT_OR_INT = / #{DECIMAL} (?: #{FLOAT_SUFFIX} () )? /ox
|
75
|
+
NUMERIC = / [-+]? (?: (?=0) (?: #{OCTAL} | #{HEXADECIMAL} | #{BINARY} ) | #{FLOAT_OR_INT} ) /ox
|
76
|
+
|
77
|
+
SYMBOL = /
|
78
|
+
:
|
79
|
+
(?:
|
80
|
+
#{METHOD_NAME_EX}
|
81
|
+
| #{PREFIX_VARIABLE}
|
82
|
+
| ['"]
|
83
|
+
)
|
84
|
+
/ox
|
85
|
+
|
86
|
+
# TODO investigste \M, \c and \C escape sequences
|
87
|
+
# (?: M-\\C-|C-\\M-|M-\\c|c\\M-|c|C-|M-)? (?: \\ (?: [0-7]{3} | x[0-9A-Fa-f]{2} | . ) )
|
88
|
+
# assert_equal(225, ?\M-a)
|
89
|
+
# assert_equal(129, ?\M-\C-a)
|
90
|
+
ESCAPE = /
|
91
|
+
[abefnrstv]
|
92
|
+
| M-\\C-|C-\\M-|M-\\c|c\\M-|c|C-|M-
|
93
|
+
| [0-7]{1,3}
|
94
|
+
| x[0-9A-Fa-f]{1,2}
|
95
|
+
| .
|
96
|
+
/mx
|
97
|
+
|
98
|
+
CHARACTER = /
|
99
|
+
\?
|
100
|
+
(?:
|
101
|
+
[^\s\\]
|
102
|
+
| \\ #{ESCAPE}
|
103
|
+
)
|
104
|
+
/mx
|
105
|
+
|
106
|
+
# NOTE: This is not completely correct, but
|
107
|
+
# nobody needs heredoc delimiters ending with \n.
|
108
|
+
HEREDOC_OPEN = /
|
109
|
+
<< (-)? # $1 = float
|
110
|
+
(?:
|
111
|
+
( [A-Za-z_0-9]+ ) # $2 = delim
|
112
|
+
|
|
113
|
+
( ["'`] ) # $3 = quote, type
|
114
|
+
( [^\n]*? ) \3 # $4 = delim
|
115
|
+
)
|
116
|
+
/mx
|
117
|
+
|
118
|
+
RUBYDOC = /
|
119
|
+
=begin (?!\S)
|
120
|
+
.*?
|
121
|
+
(?: \Z | ^=end (?!\S) [^\n]* )
|
122
|
+
/mx
|
123
|
+
|
124
|
+
DATA = /
|
125
|
+
__END__$
|
126
|
+
.*?
|
127
|
+
(?: \Z | (?=^\#CODE) )
|
128
|
+
/mx
|
129
|
+
|
130
|
+
RUBYDOC_OR_DATA = / #{RUBYDOC} | #{DATA} /xo
|
131
|
+
|
132
|
+
RDOC_DATA_START = / ^=begin (?!\S) | ^__END__$ /x
|
133
|
+
|
134
|
+
# FIXME: \s and = are only a workaround, they are still allowed
|
135
|
+
# as delimiters.
|
136
|
+
FANCY_START_SAVE = / % ( [qQwWxsr] | (?![a-zA-Z0-9\s=]) ) ([^a-zA-Z0-9]) /mx
|
137
|
+
FANCY_START_CORRECT = / % ( [qQwWxsr] | (?![a-zA-Z0-9]) ) ([^a-zA-Z0-9]) /mx
|
138
|
+
|
139
|
+
FancyStringType = {
|
140
|
+
'q' => [:string, false],
|
141
|
+
'Q' => [:string, true],
|
142
|
+
'r' => [:regexp, true],
|
143
|
+
's' => [:symbol, false],
|
144
|
+
'x' => [:shell, true]
|
145
|
+
}
|
146
|
+
FancyStringType['w'] = FancyStringType['q']
|
147
|
+
FancyStringType['W'] = FancyStringType[''] = FancyStringType['Q']
|
148
|
+
|
149
|
+
class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
|
150
|
+
:paren, :paren_depth, :pattern, :next_state
|
151
|
+
|
152
|
+
CLOSING_PAREN = Hash[ *%w[
|
153
|
+
( )
|
154
|
+
[ ]
|
155
|
+
< >
|
156
|
+
{ }
|
157
|
+
] ]
|
158
|
+
|
159
|
+
CLOSING_PAREN.values.each { |o| o.freeze } # debug, if I try to change it with <<
|
160
|
+
OPENING_PAREN = CLOSING_PAREN.invert
|
161
|
+
|
162
|
+
STRING_PATTERN = Hash.new { |h, k|
|
163
|
+
delim, interpreted = *k
|
164
|
+
delim_pattern = Regexp.escape(delim.dup)
|
165
|
+
if closing_paren = CLOSING_PAREN[delim]
|
166
|
+
delim_pattern << Regexp.escape(closing_paren)
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
special_escapes =
|
171
|
+
case interpreted
|
172
|
+
when :regexp_symbols
|
173
|
+
'| ' + REGEXP_SYMBOLS.source
|
174
|
+
when :words
|
175
|
+
'| \s'
|
176
|
+
end
|
177
|
+
|
178
|
+
h[k] =
|
179
|
+
if interpreted and not delim == '#'
|
180
|
+
/ (?= [#{delim_pattern}\\] | \# [{$@] #{special_escapes} ) /mx
|
181
|
+
else
|
182
|
+
/ (?= [#{delim_pattern}\\] #{special_escapes} ) /mx
|
183
|
+
end
|
184
|
+
}
|
185
|
+
|
186
|
+
HEREDOC_PATTERN = Hash.new { |h, k|
|
187
|
+
delim, interpreted, indented = *k
|
188
|
+
delim_pattern = Regexp.escape(delim.dup)
|
189
|
+
delim_pattern = / \n #{ '(?>[\ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
|
190
|
+
h[k] =
|
191
|
+
if interpreted
|
192
|
+
/ (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc
|
193
|
+
else
|
194
|
+
/ (?= #{delim_pattern}() | \\ ) /mx
|
195
|
+
end
|
196
|
+
}
|
197
|
+
|
198
|
+
def initialize kind, interpreted, delim, heredoc = false
|
199
|
+
if heredoc
|
200
|
+
pattern = HEREDOC_PATTERN[ [delim, interpreted, heredoc == :indented] ]
|
201
|
+
delim = nil
|
202
|
+
else
|
203
|
+
pattern = STRING_PATTERN[ [delim, interpreted] ]
|
204
|
+
if paren = CLOSING_PAREN[delim]
|
205
|
+
delim, paren = paren, delim
|
206
|
+
paren_depth = 1
|
207
|
+
end
|
208
|
+
end
|
209
|
+
super kind, interpreted, delim, heredoc, paren, paren_depth, pattern, :initial
|
210
|
+
end
|
211
|
+
end unless defined? StringState
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
end
|
data/lib/coderay/scanners/xml.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
module CodeRay
|
2
|
-
module Scanners
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
load :html
|
5
|
+
|
6
|
+
# XML Scanner
|
7
|
+
#
|
8
|
+
# $Id$
|
9
|
+
#
|
10
|
+
# Currently this is the same scanner as Scanners::HTML.
|
11
|
+
class XML < HTML
|
12
|
+
|
13
|
+
register_for :xml
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|