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,167 +1,174 @@
1
- module CodeRay
2
- module Scanners
3
-
4
- # HTML Scanner
5
- #
6
- # $Id$
7
- class HTML < Scanner
8
-
9
- include Streamable
10
- register_for :html
11
-
12
- ATTR_NAME = /[\w.:-]+/
13
- ATTR_VALUE_UNQUOTED = ATTR_NAME
14
- TAG_END = /\/?>/
15
- HEX = /[0-9a-fA-F]/
16
- ENTITY = /
17
- &
18
- (?:
19
- \w+
20
- |
21
- \#
22
- (?:
23
- \d+
24
- |
25
- x#{HEX}+
26
- )
27
- )
28
- ;
29
- /ox
30
-
31
- PLAIN_STRING_CONTENT = {
32
- "'" => /[^&'>\n]+/,
33
- '"' => /[^&">\n]+/,
34
- }
35
-
36
- private
37
- def setup
38
- @state = :initial
39
- @plain_string_content = nil
40
- end
41
-
42
- def scan_tokens tokens, options
43
-
44
- state = @state
45
- plain_string_content = @plain_string_content
46
-
47
- until eos?
48
-
49
- kind = :error
50
- match = nil
51
-
52
- if scan(/\s+/m)
53
- kind = :space
54
-
55
- else
56
-
57
- case state
58
-
59
- when :initial
60
- if scan(/<!--.*?-->/m)
61
- kind = :comment
62
- elsif scan(/<!DOCTYPE.*?>/m)
63
- kind = :preprocessor
64
- elsif scan(/<\?xml.*?\?>/m)
65
- kind = :preprocessor
66
- elsif scan(/<\?.*?\?>|<%.*?%>/m)
67
- kind = :comment
68
- elsif scan(/<\/[-\w_.:]*>/m)
69
- kind = :tag
70
- elsif match = scan(/<[-\w_.:]*>?/m)
71
- kind = :tag
72
- state = :attribute unless match[-1] == ?>
73
- elsif scan(/[^<>&]+/)
74
- kind = :plain
75
- elsif scan(/#{ENTITY}/ox)
76
- kind = :entity
77
- elsif scan(/[>&]/)
78
- kind = :error
79
- else
80
- raise_inspect '[BUG] else-case reached with state %p' % [state], tokens
81
- end
82
-
83
- when :attribute
84
- if scan(/#{TAG_END}/)
85
- kind = :tag
86
- state = :initial
87
- elsif scan(/#{ATTR_NAME}/o)
88
- kind = :attribute_name
89
- state = :attribute_equal
90
- else
91
- getch
92
- end
93
-
94
- when :attribute_equal
95
- if scan(/=/)
96
- kind = :operator
97
- state = :attribute_value
98
- elsif scan(/#{ATTR_NAME}/o)
99
- kind = :attribute_name
100
- elsif scan(/#{TAG_END}/o)
101
- kind = :tag
102
- state = :initial
103
- elsif scan(/./)
104
- state = :attribute
105
- end
106
-
107
- when :attribute_value
108
- if scan(/#{ATTR_VALUE_UNQUOTED}/o)
109
- kind = :attribute_value
110
- state = :attribute
111
- elsif match = scan(/["']/)
112
- tokens << [:open, :string]
113
- state = :attribute_value_string
114
- plain_string_content = PLAIN_STRING_CONTENT[match]
115
- kind = :delimiter
116
- elsif scan(/#{TAG_END}/o)
117
- kind = :tag
118
- state = :initial
119
- else
120
- getch
121
- end
122
-
123
- when :attribute_value_string
124
- if scan(plain_string_content)
125
- kind = :content
126
- elsif scan(/['"]/)
127
- tokens << [matched, :delimiter]
128
- tokens << [:close, :string]
129
- state = :attribute
130
- next
131
- elsif scan(/#{ENTITY}/ox)
132
- kind = :entity
133
- elsif scan(/[\n>]/)
134
- tokens << [:close, :string]
135
- kind = :error
136
- state = :initial
137
- end
138
-
139
- else
140
- raise_inspect 'Unknown state: %p' % [state], tokens
141
-
142
- end
143
-
144
- end
145
-
146
- match ||= matched
147
- if $DEBUG and (not kind or kind == :error)
148
- raise_inspect 'Error token %p in line %d' %
149
- [[match, kind], line], tokens
150
- end
151
- raise_inspect 'Empty token', tokens unless match
152
-
153
- tokens << [match, kind]
154
- end
155
-
156
- if options[:keep_state]
157
- @state = state
158
- @plain_string_content = plain_string_content
159
- end
160
-
161
- tokens
162
- end
163
-
164
- end
165
-
166
- end
167
- end
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ # HTML Scanner
5
+ #
6
+ # $Id$
7
+ class HTML < Scanner
8
+
9
+ include Streamable
10
+ register_for :html
11
+
12
+ ATTR_NAME = /[\w.:-]+/
13
+ ATTR_VALUE_UNQUOTED = ATTR_NAME
14
+ TAG_END = /\/?>/
15
+ HEX = /[0-9a-fA-F]/
16
+ ENTITY = /
17
+ &
18
+ (?:
19
+ \w+
20
+ |
21
+ \#
22
+ (?:
23
+ \d+
24
+ |
25
+ x#{HEX}+
26
+ )
27
+ )
28
+ ;
29
+ /ox
30
+
31
+ PLAIN_STRING_CONTENT = {
32
+ "'" => /[^&'>\n]+/,
33
+ '"' => /[^&">\n]+/,
34
+ }
35
+
36
+ def reset
37
+ super
38
+ @state = :initial
39
+ end
40
+
41
+ private
42
+ def setup
43
+ @state = :initial
44
+ @plain_string_content = nil
45
+ end
46
+
47
+ def scan_tokens tokens, options
48
+
49
+ state = @state
50
+ plain_string_content = @plain_string_content
51
+
52
+ until eos?
53
+
54
+ kind = nil
55
+ match = nil
56
+
57
+ if scan(/\s+/m)
58
+ kind = :space
59
+
60
+ else
61
+
62
+ case state
63
+
64
+ when :initial
65
+ if scan(/<!--.*?-->/m)
66
+ kind = :comment
67
+ elsif scan(/<!DOCTYPE.*?>/m)
68
+ kind = :preprocessor
69
+ elsif scan(/<\?xml.*?\?>/m)
70
+ kind = :preprocessor
71
+ elsif scan(/<\?.*?\?>|<%.*?%>/m)
72
+ kind = :comment
73
+ elsif scan(/<\/[-\w_.:]*>/m)
74
+ kind = :tag
75
+ elsif match = scan(/<[-\w_.:]+>?/m)
76
+ kind = :tag
77
+ state = :attribute unless match[-1] == ?>
78
+ elsif scan(/[^<>&]+/)
79
+ kind = :plain
80
+ elsif scan(/#{ENTITY}/ox)
81
+ kind = :entity
82
+ elsif scan(/[<>&]/)
83
+ kind = :error
84
+ else
85
+ raise_inspect '[BUG] else-case reached with state %p' % [state], tokens
86
+ end
87
+
88
+ when :attribute
89
+ if scan(/#{TAG_END}/)
90
+ kind = :tag
91
+ state = :initial
92
+ elsif scan(/#{ATTR_NAME}/o)
93
+ kind = :attribute_name
94
+ state = :attribute_equal
95
+ else
96
+ kind = :error
97
+ getch
98
+ end
99
+
100
+ when :attribute_equal
101
+ if scan(/=/)
102
+ kind = :operator
103
+ state = :attribute_value
104
+ elsif scan(/#{ATTR_NAME}/o)
105
+ kind = :attribute_name
106
+ elsif scan(/#{TAG_END}/o)
107
+ kind = :tag
108
+ state = :initial
109
+ elsif scan(/./)
110
+ state = :attribute
111
+ end
112
+
113
+ when :attribute_value
114
+ if scan(/#{ATTR_VALUE_UNQUOTED}/o)
115
+ kind = :attribute_value
116
+ state = :attribute
117
+ elsif match = scan(/["']/)
118
+ tokens << [:open, :string]
119
+ state = :attribute_value_string
120
+ plain_string_content = PLAIN_STRING_CONTENT[match]
121
+ kind = :delimiter
122
+ elsif scan(/#{TAG_END}/o)
123
+ kind = :tag
124
+ state = :initial
125
+ else
126
+ kind = :error
127
+ getch
128
+ end
129
+
130
+ when :attribute_value_string
131
+ if scan(plain_string_content)
132
+ kind = :content
133
+ elsif scan(/['"]/)
134
+ tokens << [matched, :delimiter]
135
+ tokens << [:close, :string]
136
+ state = :attribute
137
+ next
138
+ elsif scan(/#{ENTITY}/ox)
139
+ kind = :entity
140
+ elsif scan(/[\n>]/)
141
+ tokens << [:close, :string]
142
+ kind = :error
143
+ state = :initial
144
+ end
145
+
146
+ else
147
+ raise_inspect 'Unknown state: %p' % [state], tokens
148
+
149
+ end
150
+
151
+ end
152
+
153
+ match ||= matched
154
+ if $DEBUG and not kind
155
+ raise_inspect 'Error token %p in line %d' %
156
+ [[match, kind], line], tokens, state
157
+ end
158
+ raise_inspect 'Empty token', tokens unless match
159
+
160
+ tokens << [match, kind]
161
+ end
162
+
163
+ if options[:keep_state]
164
+ @state = state
165
+ @plain_string_content = plain_string_content
166
+ end
167
+
168
+ tokens
169
+ end
170
+
171
+ end
172
+
173
+ end
174
+ end
@@ -0,0 +1,130 @@
1
+ module CodeRay
2
+ module Scanners
3
+
4
+ load :html
5
+ load :ruby
6
+
7
+ # Nitro XHTML Scanner
8
+ #
9
+ # $Id$
10
+ class NitroXHTML < Scanner
11
+
12
+ include Streamable
13
+ register_for :nitro_xhtml
14
+
15
+ NITRO_RUBY_BLOCK = /
16
+ <\?r
17
+ (?>
18
+ [^\?]*
19
+ (?> \?(?!>) [^\?]* )*
20
+ )
21
+ (?: \?> )?
22
+ |
23
+ <ruby>
24
+ (?>
25
+ [^<]*
26
+ (?> <(?!\/ruby>) [^<]* )*
27
+ )
28
+ (?: <\/ruby> )?
29
+ |
30
+ <%
31
+ (?>
32
+ [^%]*
33
+ (?> %(?!>) [^%]* )*
34
+ )
35
+ (?: %> )?
36
+ /mx
37
+
38
+ NITRO_VALUE_BLOCK = /
39
+ \#
40
+ (?:
41
+ \{
42
+ [^{}]*
43
+ (?>
44
+ \{ [^}]* \}
45
+ (?> [^{}]* )
46
+ )*
47
+ \}?
48
+ | \| [^|]* \|?
49
+ | \( [^)]* \)?
50
+ | \[ [^\]]* \]?
51
+ | \\ [^\\]* \\?
52
+ )
53
+ /x
54
+
55
+ NITRO_ENTITY = /
56
+ % (?: \#\d+ | \w+ ) ;
57
+ /
58
+
59
+ START_OF_RUBY = /
60
+ (?=[<\#%])
61
+ < (?: \?r | % | ruby> )
62
+ | \# [{(|]
63
+ | % (?: \#\d+ | \w+ ) ;
64
+ /x
65
+
66
+ CLOSING_PAREN = Hash.new do |h, p|
67
+ h[p] = p
68
+ end.update( {
69
+ '(' => ')',
70
+ '[' => ']',
71
+ '{' => '}',
72
+ } )
73
+
74
+ private
75
+
76
+ def setup
77
+ @ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
78
+ @html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true
79
+ end
80
+
81
+ def reset_instance
82
+ super
83
+ @html_scanner.reset
84
+ end
85
+
86
+ def scan_tokens tokens, options
87
+
88
+ until eos?
89
+
90
+ if (match = scan_until(/(?=#{START_OF_RUBY})/o) || scan_until(/\z/)) and not match.empty?
91
+ @html_scanner.tokenize match
92
+
93
+ elsif match = scan(/#{NITRO_VALUE_BLOCK}/o)
94
+ start_tag = match[0,2]
95
+ delimiter = CLOSING_PAREN[start_tag[1,1]]
96
+ end_tag = match[-1,1] == delimiter ? delimiter : ''
97
+ tokens << [:open, :inline]
98
+ tokens << [start_tag, :delimiter]
99
+ code = match[start_tag.size .. -1 - end_tag.size]
100
+ @ruby_scanner.tokenize code
101
+ tokens << [end_tag, :delimiter] unless end_tag.empty?
102
+ tokens << [:close, :inline]
103
+
104
+ elsif match = scan(/#{NITRO_RUBY_BLOCK}/o)
105
+ start_tag = '<?r'
106
+ end_tag = match[-2,2] == '?>' ? '?>' : ''
107
+ tokens << [:open, :inline]
108
+ tokens << [start_tag, :delimiter]
109
+ code = match[start_tag.size .. -(end_tag.size)-1]
110
+ @ruby_scanner.tokenize code
111
+ tokens << [end_tag, :delimiter] unless end_tag.empty?
112
+ tokens << [:close, :inline]
113
+
114
+ elsif entity = scan(/#{NITRO_ENTITY}/o)
115
+ tokens << [entity, :entity]
116
+
117
+ else
118
+ raise_inspect 'else-case reached!', tokens
119
+ end
120
+
121
+ end
122
+
123
+ tokens
124
+
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+ end