rdoc 3.12.2 → 4.0.0.preview2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -141,6 +141,7 @@ class RDoc::Parser
141
141
  return if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/
142
142
 
143
143
  parser
144
+ rescue Errno::EACCES
144
145
  end
145
146
 
146
147
  ##
@@ -201,7 +202,8 @@ class RDoc::Parser
201
202
 
202
203
  return unless markup
203
204
 
204
- return RDoc::Parser::Ruby if markup == 'tomdoc'
205
+ # TODO Ruby should be returned only when the filename is correct
206
+ return RDoc::Parser::Ruby if %w[tomdoc markdown].include? markup
205
207
 
206
208
  markup = Regexp.escape markup
207
209
 
@@ -219,6 +221,7 @@ class RDoc::Parser
219
221
  def initialize top_level, file_name, content, options, stats
220
222
  @top_level = top_level
221
223
  @top_level.parser = self.class
224
+ @store = @top_level.store
222
225
 
223
226
  @file_name = file_name
224
227
  @content = content
@@ -236,7 +239,8 @@ end
236
239
 
237
240
  # simple must come first in order to show up last in the parsers list
238
241
  require 'rdoc/parser/simple'
242
+ require 'rdoc/parser/c'
243
+ require 'rdoc/parser/markdown'
239
244
  require 'rdoc/parser/rd'
240
245
  require 'rdoc/parser/ruby'
241
- require 'rdoc/parser/c'
242
246
 
@@ -1,3 +1,5 @@
1
+ require 'tsort'
2
+
1
3
  ##
2
4
  # RDoc::Parser::C attempts to parse C extension files. It looks for
3
5
  # the standard patterns that you find in extensions: <tt>rb_define_class,
@@ -54,6 +56,13 @@
54
56
  # [Document-const: +name+]
55
57
  # Documentation for the named +rb_define_const+.
56
58
  #
59
+ # Constant values can be supplied on the first line of the comment like so:
60
+ #
61
+ # /* 300: The highest possible score in bowling */
62
+ # rb_define_const(cFoo, "PERFECT", INT2FIX(300));
63
+ #
64
+ # The value can contain internal colons so long as they are escaped with a \
65
+ #
57
66
  # [Document-global: +name+]
58
67
  # Documentation for the named +rb_define_global_const+
59
68
  #
@@ -118,27 +127,27 @@ class RDoc::Parser::C < RDoc::Parser
118
127
 
119
128
  attr_accessor :content
120
129
 
130
+ ##
131
+ # Dependencies from a missing enclosing class to the classes in
132
+ # missing_dependencies that depend upon it.
133
+
134
+ attr_reader :enclosure_dependencies
121
135
 
122
136
  ##
123
- # Maps C variable names to names of ruby classes (andsingleton classes)
137
+ # Maps C variable names to names of ruby classes (and singleton classes)
124
138
 
125
139
  attr_reader :known_classes
126
140
 
127
141
  ##
128
- # Maps C variable names to names of ruby singleton classes
142
+ # Classes found while parsing the C file that were not yet registered due to
143
+ # a missing enclosing class. These are processed by do_missing
129
144
 
130
- attr_reader :singleton_classes
145
+ attr_reader :missing_dependencies
131
146
 
132
147
  ##
133
- # Resets cross-file state. Call when parsing different projects that need
134
- # separate documentation.
135
-
136
- def self.reset
137
- @@enclosure_classes = {}
138
- @@known_bodies = {}
139
- end
148
+ # Maps C variable names to names of ruby singleton classes
140
149
 
141
- reset
150
+ attr_reader :singleton_classes
142
151
 
143
152
  ##
144
153
  # Prepare to parse a C file
@@ -151,6 +160,38 @@ class RDoc::Parser::C < RDoc::Parser
151
160
  @classes = {}
152
161
  @singleton_classes = {}
153
162
  @file_dir = File.dirname(@file_name)
163
+
164
+ # missing variable => [handle_class_module arguments]
165
+ @missing_dependencies = {}
166
+
167
+ # missing enclosure variable => [dependent handle_class_module arguments]
168
+ @enclosure_dependencies = Hash.new { |h, k| h[k] = [] }
169
+ @enclosure_dependencies.instance_variable_set :@missing_dependencies,
170
+ @missing_dependencies
171
+
172
+ @enclosure_dependencies.extend TSort
173
+
174
+ def @enclosure_dependencies.tsort_each_node &block
175
+ each_key(&block)
176
+ rescue TSort::Cyclic => e
177
+ cycle_vars = e.message.scan(/"(.*?)"/).flatten
178
+
179
+ cycle = cycle_vars.sort.map do |var_name|
180
+ delete var_name
181
+
182
+ var_name, type, mod_name, = @missing_dependencies[var_name]
183
+
184
+ "#{type} #{mod_name} (#{var_name})"
185
+ end.join ', '
186
+
187
+ warn "Unable to create #{cycle} due to a cyclic class or module creation"
188
+
189
+ retry
190
+ end
191
+
192
+ def @enclosure_dependencies.tsort_each_child node, &block
193
+ fetch(node, []).each(&block)
194
+ end
154
195
  end
155
196
 
156
197
  ##
@@ -165,7 +206,7 @@ class RDoc::Parser::C < RDoc::Parser
165
206
  class_name = @known_classes[var_name]
166
207
 
167
208
  unless class_name then
168
- @options.warn "Enclosing class/module %p for alias %s %s not known" % [
209
+ @options.warn "Enclosing class or module %p for alias %s %s is not known" % [
169
210
  var_name, new_name, old_name]
170
211
  next
171
212
  end
@@ -212,73 +253,26 @@ class RDoc::Parser::C < RDoc::Parser
212
253
  end
213
254
 
214
255
  ##
215
- # Scans #content for rb_define_module, rb_define_class, boot_defclass,
216
- # rb_define_module_under, rb_define_class_under and rb_singleton_class
217
-
218
- def do_classes
219
- @content.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
220
- |var_name, class_name|
221
- handle_class_module(var_name, "module", class_name, nil, nil)
222
- end
223
-
224
- # The '.' lets us handle SWIG-generated files
225
- @content.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
226
- \(
227
- \s*"(\w+)",
228
- \s*(\w+)\s*
229
- \)/mx) do |var_name, class_name, parent|
230
- handle_class_module(var_name, "class", class_name, parent, nil)
231
- end
232
-
233
- @content.scan(/([\w\.]+)\s* = \s*rb_struct_define_without_accessor\s*
234
- \(
235
- \s*"(\w+)", # Class name
236
- \s*(\w+), # Parent class
237
- \s*\w+, # Allocation function
238
- (\s*"\w+",)* # Attributes
239
- \s*NULL
240
- \)/mx) do |var_name, class_name, parent|
241
- handle_class_module(var_name, "class", class_name, parent, nil)
242
- end
256
+ # Scans #content for boot_defclass
243
257
 
258
+ def do_boot_defclass
244
259
  @content.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\s*\)/) do
245
260
  |var_name, class_name, parent|
246
261
  parent = nil if parent == "0"
247
- handle_class_module(var_name, "class", class_name, parent, nil)
262
+ handle_class_module(var_name, :class, class_name, parent, nil)
248
263
  end
264
+ end
249
265
 
250
- @content.scan(/(\w+)\s* = \s*rb_define_module_under\s*
251
- \(
252
- \s*(\w+),
253
- \s*"(\w+)"
254
- \s*\)/mx) do |var_name, in_module, class_name|
255
- handle_class_module(var_name, "module", class_name, nil, in_module)
256
- end
257
-
258
- @content.scan(/([\w\.]+)\s* = # var_name
259
- \s*rb_define_class_under\s*
260
- \(
261
- \s* (\w+), # under
262
- \s* "(\w+)", # class_name
263
- \s*
264
- (?:
265
- ([\w\*\s\(\)\.\->]+) | # parent_name
266
- rb_path2class\("([\w:]+)"\) # path
267
- )
268
- \s*
269
- \)
270
- /mx) do |var_name, under, class_name, parent_name, path|
271
- parent = path || parent_name
272
-
273
- handle_class_module var_name, 'class', class_name, parent, under
274
- end
266
+ ##
267
+ # Scans #content for rb_define_class, boot_defclass, rb_define_class_under
268
+ # and rb_singleton_class
275
269
 
276
- @content.scan(/([\w\.]+)\s* = \s*rb_singleton_class\s*
277
- \(
278
- \s*(\w+)
279
- \s*\)/mx) do |sclass_var, class_var|
280
- handle_singleton sclass_var, class_var
281
- end
270
+ def do_classes
271
+ do_boot_defclass
272
+ do_define_class
273
+ do_define_class_under
274
+ do_singleton_class
275
+ do_struct_define_without_accessor
282
276
  end
283
277
 
284
278
  ##
@@ -309,8 +303,82 @@ class RDoc::Parser::C < RDoc::Parser
309
303
  \)
310
304
  \s*;%xm) do |consts|
311
305
  const = consts.first
306
+
312
307
  handle_constants 'const', 'mCurses', const, "UINT2NUM(#{const})"
313
308
  end
309
+
310
+ @content.scan(%r%
311
+ \Wrb_file_const
312
+ \s*\(
313
+ \s*
314
+ "([^"]+)",
315
+ \s*
316
+ (.*?)
317
+ \s*
318
+ \)
319
+ \s*;%xm) do |name, value|
320
+ handle_constants 'const', 'rb_mFConst', name, value
321
+ end
322
+ end
323
+
324
+ ##
325
+ # Scans #content for rb_define_class
326
+
327
+ def do_define_class
328
+ # The '.' lets us handle SWIG-generated files
329
+ @content.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
330
+ \(
331
+ \s*"(\w+)",
332
+ \s*(\w+)\s*
333
+ \)/mx) do |var_name, class_name, parent|
334
+ handle_class_module(var_name, :class, class_name, parent, nil)
335
+ end
336
+ end
337
+
338
+ ##
339
+ # Scans #content for rb_define_class_under
340
+
341
+ def do_define_class_under
342
+ @content.scan(/([\w\.]+)\s* = # var_name
343
+ \s*rb_define_class_under\s*
344
+ \(
345
+ \s* (\w+), # under
346
+ \s* "(\w+)", # class_name
347
+ \s*
348
+ (?:
349
+ ([\w\*\s\(\)\.\->]+) | # parent_name
350
+ rb_path2class\("([\w:]+)"\) # path
351
+ )
352
+ \s*
353
+ \)
354
+ /mx) do |var_name, under, class_name, parent_name, path|
355
+ parent = path || parent_name
356
+
357
+ handle_class_module var_name, :class, class_name, parent, under
358
+ end
359
+ end
360
+
361
+ ##
362
+ # Scans #content for rb_define_module
363
+
364
+ def do_define_module
365
+ @content.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
366
+ |var_name, class_name|
367
+ handle_class_module(var_name, :module, class_name, nil, nil)
368
+ end
369
+ end
370
+
371
+ ##
372
+ # Scans #content for rb_define_module_under
373
+
374
+ def do_define_module_under
375
+ @content.scan(/(\w+)\s* = \s*rb_define_module_under\s*
376
+ \(
377
+ \s*(\w+),
378
+ \s*"(\w+)"
379
+ \s*\)/mx) do |var_name, in_module, class_name|
380
+ handle_class_module(var_name, :module, class_name, nil, in_module)
381
+ end
314
382
  end
315
383
 
316
384
  ##
@@ -378,6 +446,54 @@ class RDoc::Parser::C < RDoc::Parser
378
446
  end
379
447
  end
380
448
 
449
+ def do_missing
450
+ return if @missing_dependencies.empty?
451
+
452
+ @enclosure_dependencies.tsort.each do |in_module|
453
+ arguments = @missing_dependencies.delete in_module
454
+
455
+ next unless arguments # dependency on existing class
456
+
457
+ handle_class_module(*arguments)
458
+ end
459
+ end
460
+
461
+ ##
462
+ # Scans #content for rb_define_module and rb_define_module_under
463
+
464
+ def do_modules
465
+ do_define_module
466
+ do_define_module_under
467
+ end
468
+
469
+ ##
470
+ # Scans #content for rb_singleton_class
471
+
472
+ def do_singleton_class
473
+ @content.scan(/([\w\.]+)\s* = \s*rb_singleton_class\s*
474
+ \(
475
+ \s*(\w+)
476
+ \s*\)/mx) do |sclass_var, class_var|
477
+ handle_singleton sclass_var, class_var
478
+ end
479
+ end
480
+
481
+ ##
482
+ # Scans #content for struct_define_without_accessor
483
+
484
+ def do_struct_define_without_accessor
485
+ @content.scan(/([\w\.]+)\s* = \s*rb_struct_define_without_accessor\s*
486
+ \(
487
+ \s*"(\w+)", # Class name
488
+ \s*(\w+), # Parent class
489
+ \s*\w+, # Allocation function
490
+ (\s*"\w+",)* # Attributes
491
+ \s*NULL
492
+ \)/mx) do |var_name, class_name, parent|
493
+ handle_class_module(var_name, :class, class_name, parent, nil)
494
+ end
495
+ end
496
+
381
497
  ##
382
498
  # Finds the comment for an alias on +class_name+ from +new_name+ to
383
499
  # +old_name+
@@ -440,7 +556,7 @@ class RDoc::Parser::C < RDoc::Parser
440
556
  \s*(\([^)]*\))([^;]|$))%xm then
441
557
  comment = RDoc::Comment.new $1, @top_level
442
558
  body = $2
443
- offset = $~.offset(2).first
559
+ offset, = $~.offset(2)
444
560
 
445
561
  comment.remove_private if comment
446
562
 
@@ -557,7 +673,7 @@ class RDoc::Parser::C < RDoc::Parser
557
673
  # */
558
674
  # VALUE cFoo = rb_define_class("Foo", rb_cObject);
559
675
 
560
- def find_class_comment(class_name, class_mod)
676
+ def find_class_comment class_name, class_mod
561
677
  comment = nil
562
678
 
563
679
  if @content =~ %r%
@@ -569,10 +685,10 @@ class RDoc::Parser::C < RDoc::Parser
569
685
  elsif @content =~ %r%Document-(?:class|module):\s+#{class_name}\s*?
570
686
  (?:<\s+[:,\w]+)?\n((?>.*?\*/))%xm then
571
687
  comment = "/*\n#{$1}"
572
- elsif @content =~ %r%((?>/\*.*?\*/\s+))
688
+ elsif @content =~ %r%.*((?>/\*.*?\*/\s+))
573
689
  ([\w\.\s]+\s* = \s+)?rb_define_(class|module).*?"(#{class_name})"%xm then
574
690
  comment = $1
575
- elsif @content =~ %r%((?>/\*.*?\*/\s+))
691
+ elsif @content =~ %r%.*((?>/\*.*?\*/\s+))
576
692
  ([\w\.\s]+\s* = \s+)?rb_define_(class|module)_under.*?"(#{class_name.split('::').last})"%xm then
577
693
  comment = $1
578
694
  else
@@ -681,24 +797,26 @@ class RDoc::Parser::C < RDoc::Parser
681
797
  parent_name = @known_classes[parent] || parent
682
798
 
683
799
  if in_module then
684
- enclosure = @classes[in_module] || @@enclosure_classes[in_module]
800
+ enclosure = @classes[in_module] || @store.c_enclosure_classes[in_module]
685
801
 
686
802
  if enclosure.nil? and enclosure = @known_classes[in_module] then
687
- enc_type = /^rb_m/ =~ in_module ? "module" : "class"
803
+ enc_type = /^rb_m/ =~ in_module ? :module : :class
688
804
  handle_class_module in_module, enc_type, enclosure, nil, nil
689
805
  enclosure = @classes[in_module]
690
806
  end
691
807
 
692
808
  unless enclosure then
693
- @options.warn "Enclosing class/module '#{in_module}' for " \
694
- "#{type} #{class_name} not known"
809
+ @enclosure_dependencies[in_module] << var_name
810
+ @missing_dependencies[var_name] =
811
+ [var_name, type, class_name, parent, in_module]
812
+
695
813
  return
696
814
  end
697
815
  else
698
816
  enclosure = @top_level
699
817
  end
700
818
 
701
- if type == "class" then
819
+ if type == :class then
702
820
  full_name = if RDoc::ClassModule === enclosure then
703
821
  enclosure.full_name + "::#{class_name}"
704
822
  else
@@ -726,7 +844,7 @@ class RDoc::Parser::C < RDoc::Parser
726
844
  end
727
845
 
728
846
  @classes[var_name] = cm
729
- @@enclosure_classes[var_name] = cm
847
+ @store.c_enclosure_classes[var_name] = cm
730
848
  @known_classes[var_name] = cm.full_name
731
849
  end
732
850
 
@@ -748,7 +866,7 @@ class RDoc::Parser::C < RDoc::Parser
748
866
  class_obj = find_class var_name, class_name
749
867
 
750
868
  unless class_obj then
751
- @options.warn "Enclosing class/module #{const_name.inspect} not known"
869
+ @options.warn 'Enclosing class or module %p is not known' % [const_name]
752
870
  return
753
871
  end
754
872
 
@@ -759,13 +877,9 @@ class RDoc::Parser::C < RDoc::Parser
759
877
  # "/* definition: comment */" form. The literal ':' and '\' characters
760
878
  # can be escaped with a backslash.
761
879
  if type.downcase == 'const' then
762
- elements = comment.text.split ':'
763
-
764
- if elements.nil? or elements.empty? then
765
- con = RDoc::Constant.new const_name, definition, comment
766
- else
767
- new_definition = elements[0..-2].join(':')
880
+ no_match, new_definition, new_comment = comment.text.split(/(\A.*):/)
768
881
 
882
+ if no_match and no_match.empty? then
769
883
  if new_definition.empty? then # Default to literal C definition
770
884
  new_definition = definition
771
885
  else
@@ -775,15 +889,13 @@ class RDoc::Parser::C < RDoc::Parser
775
889
 
776
890
  new_definition.sub!(/\A(\s+)/, '')
777
891
 
778
- new_comment = if $1.nil? then
779
- elements.last.lstrip
780
- else
781
- "#{$1}#{elements.last.lstrip}"
782
- end
892
+ new_comment = "#{$1}#{new_comment.lstrip}"
783
893
 
784
894
  new_comment = RDoc::Comment.new new_comment, @top_level
785
895
 
786
896
  con = RDoc::Constant.new const_name, new_definition, new_comment
897
+ else
898
+ con = RDoc::Constant.new const_name, definition, comment
787
899
  end
788
900
  else
789
901
  con = RDoc::Constant.new const_name, definition, comment
@@ -833,10 +945,9 @@ class RDoc::Parser::C < RDoc::Parser
833
945
  file_name = File.join @file_dir, source_file
834
946
 
835
947
  if File.exist? file_name then
836
- file_content = (@@known_bodies[file_name] ||= File.read(file_name))
948
+ file_content = File.read file_name
837
949
  else
838
- @options.warn "unknown source #{source_file} for " \
839
- "#{meth_name} in #{@file_name}"
950
+ @options.warn "unknown source #{source_file} for #{meth_name} in #{@file_name}"
840
951
  end
841
952
  else
842
953
  file_content = @content
@@ -1011,7 +1122,11 @@ class RDoc::Parser::C < RDoc::Parser
1011
1122
 
1012
1123
  def scan
1013
1124
  remove_commented_out_lines
1125
+
1126
+ do_modules
1014
1127
  do_classes
1128
+ do_missing
1129
+
1015
1130
  do_constants
1016
1131
  do_methods
1017
1132
  do_includes