coderay 0.7.1.147 → 0.7.2.165

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/bin/coderay +54 -56
  2. data/demo/suite.rb +54 -54
  3. data/lib/coderay.rb +187 -187
  4. data/lib/coderay/duo.rb +29 -29
  5. data/lib/coderay/encoder.rb +173 -173
  6. data/lib/coderay/encoders/_map.rb +8 -8
  7. data/lib/coderay/encoders/count.rb +21 -21
  8. data/lib/coderay/encoders/debug.rb +46 -46
  9. data/lib/coderay/encoders/div.rb +20 -20
  10. data/lib/coderay/encoders/html.rb +249 -245
  11. data/lib/coderay/encoders/html/classes.rb +73 -73
  12. data/lib/coderay/encoders/html/css.rb +65 -65
  13. data/lib/coderay/encoders/html/numerization.rb +122 -122
  14. data/lib/coderay/encoders/html/output.rb +195 -195
  15. data/lib/coderay/encoders/null.rb +26 -26
  16. data/lib/coderay/encoders/page.rb +21 -21
  17. data/lib/coderay/encoders/span.rb +20 -20
  18. data/lib/coderay/encoders/statistic.rb +81 -81
  19. data/lib/coderay/encoders/text.rb +33 -33
  20. data/lib/coderay/encoders/tokens.rb +44 -44
  21. data/lib/coderay/encoders/xml.rb +71 -71
  22. data/lib/coderay/encoders/yaml.rb +22 -22
  23. data/lib/coderay/helpers/filetype.rb +152 -153
  24. data/lib/coderay/helpers/gzip_simple.rb +67 -68
  25. data/lib/coderay/helpers/plugin.rb +297 -297
  26. data/lib/coderay/helpers/word_list.rb +46 -47
  27. data/lib/coderay/scanner.rb +238 -238
  28. data/lib/coderay/scanners/_map.rb +15 -14
  29. data/lib/coderay/scanners/c.rb +163 -155
  30. data/lib/coderay/scanners/delphi.rb +131 -129
  31. data/lib/coderay/scanners/html.rb +174 -167
  32. data/lib/coderay/scanners/nitro_xhtml.rb +130 -0
  33. data/lib/coderay/scanners/plaintext.rb +15 -15
  34. data/lib/coderay/scanners/rhtml.rb +73 -65
  35. data/lib/coderay/scanners/ruby.rb +404 -397
  36. data/lib/coderay/scanners/ruby/patterns.rb +216 -216
  37. data/lib/coderay/scanners/xml.rb +18 -18
  38. data/lib/coderay/style.rb +20 -20
  39. data/lib/coderay/styles/_map.rb +3 -3
  40. data/lib/coderay/styles/cycnus.rb +18 -18
  41. data/lib/coderay/styles/murphy.rb +18 -18
  42. data/lib/coderay/tokens.rb +322 -322
  43. metadata +86 -86
  44. data/lib/coderay/scanners/nitro_html.rb +0 -125
  45. data/lib/coderay/scanners/yaml.rb +0 -85
@@ -1,216 +1,216 @@
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
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
@@ -1,18 +1,18 @@
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
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