rdoc 6.1.1 → 6.3.1

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -0
  3. data/README.rdoc +0 -1
  4. data/Rakefile +28 -18
  5. data/lib/rdoc.rb +21 -0
  6. data/lib/rdoc/any_method.rb +52 -7
  7. data/lib/rdoc/class_module.rb +1 -1
  8. data/lib/rdoc/comment.rb +12 -1
  9. data/lib/rdoc/context.rb +10 -2
  10. data/lib/rdoc/context/section.rb +0 -13
  11. data/lib/rdoc/cross_reference.rb +4 -4
  12. data/lib/rdoc/erb_partial.rb +1 -1
  13. data/lib/rdoc/erbio.rb +2 -2
  14. data/lib/rdoc/generator/darkfish.rb +9 -9
  15. data/lib/rdoc/generator/pot.rb +3 -3
  16. data/lib/rdoc/generator/template/darkfish/_head.rhtml +9 -7
  17. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +2 -2
  18. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +2 -2
  19. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  20. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +2 -2
  21. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  22. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  23. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +5 -5
  24. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +5 -5
  25. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +5 -5
  26. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  27. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +4 -4
  28. data/lib/rdoc/generator/template/darkfish/class.rhtml +44 -44
  29. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +55 -6
  30. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -4
  31. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +22 -99
  32. data/lib/rdoc/generator/template/darkfish/js/search.js +32 -31
  33. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +15 -16
  34. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +16 -16
  35. data/lib/rdoc/generator/template/json_index/js/navigation.js +4 -40
  36. data/lib/rdoc/generator/template/json_index/js/searcher.js +6 -6
  37. data/lib/rdoc/i18n.rb +1 -1
  38. data/lib/rdoc/markdown.kpeg +20 -2
  39. data/lib/rdoc/markdown.rb +16685 -0
  40. data/lib/rdoc/markdown/literals.rb +417 -0
  41. data/lib/rdoc/markup.rb +1 -2
  42. data/lib/rdoc/markup/attr_span.rb +8 -2
  43. data/lib/rdoc/markup/attribute_manager.rb +93 -28
  44. data/lib/rdoc/markup/formatter.rb +1 -1
  45. data/lib/rdoc/markup/parser.rb +58 -42
  46. data/lib/rdoc/markup/pre_process.rb +1 -1
  47. data/lib/rdoc/markup/to_html.rb +46 -6
  48. data/lib/rdoc/markup/to_html_crossref.rb +18 -6
  49. data/lib/rdoc/markup/to_joined_paragraph.rb +1 -0
  50. data/lib/rdoc/markup/to_rdoc.rb +28 -0
  51. data/lib/rdoc/markup/to_table_of_contents.rb +1 -0
  52. data/lib/rdoc/options.rb +56 -6
  53. data/lib/rdoc/parser.rb +7 -7
  54. data/lib/rdoc/parser/c.rb +139 -183
  55. data/lib/rdoc/parser/changelog.rb +145 -14
  56. data/lib/rdoc/parser/ripper_state_lex.rb +2 -1
  57. data/lib/rdoc/parser/ruby.rb +18 -8
  58. data/lib/rdoc/rd/block_parser.rb +1056 -0
  59. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  60. data/lib/rdoc/rdoc.rb +35 -22
  61. data/lib/rdoc/ri/driver.rb +9 -5
  62. data/lib/rdoc/ri/paths.rb +3 -17
  63. data/lib/rdoc/ri/task.rb +1 -1
  64. data/lib/rdoc/rubygems_hook.rb +2 -2
  65. data/lib/rdoc/servlet.rb +16 -8
  66. data/lib/rdoc/store.rb +6 -14
  67. data/lib/rdoc/task.rb +1 -1
  68. data/lib/rdoc/text.rb +8 -2
  69. data/lib/rdoc/token_stream.rb +8 -3
  70. data/lib/rdoc/tom_doc.rb +6 -7
  71. data/lib/rdoc/version.rb +1 -1
  72. data/man/ri.1 +247 -0
  73. data/rdoc.gemspec +195 -9
  74. metadata +9 -72
  75. data/.document +0 -5
  76. data/.gitignore +0 -14
  77. data/.travis.yml +0 -21
  78. data/appveyor.yml +0 -36
  79. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  80. data/lib/rdoc/markup/formatter_test_case.rb +0 -764
  81. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
@@ -39,10 +39,18 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
39
39
  @hyperlink_all = @options.hyperlink_all
40
40
  @show_hash = @options.show_hash
41
41
 
42
- crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
42
+ @cross_reference = RDoc::CrossReference.new @context
43
+ end
44
+
45
+ def init_link_notation_regexp_handlings
46
+ add_regexp_handling_RDOCLINK
47
+
48
+ # The crossref must be linked before tidylink because Klass.method[:sym]
49
+ # will be processed as a tidylink first and will be broken.
50
+ crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
43
51
  @markup.add_regexp_handling crossref_re, :CROSSREF
44
52
 
45
- @cross_reference = RDoc::CrossReference.new @context
53
+ add_regexp_handling_TIDYLINK
46
54
  end
47
55
 
48
56
  ##
@@ -54,7 +62,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
54
62
 
55
63
  name = name[1..-1] unless @show_hash if name[0, 1] == '#'
56
64
 
57
- if name =~ /(.*[^#:])@/
65
+ if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
58
66
  text ||= "#{CGI.unescape $'} at <code>#{$1}</code>"
59
67
  code = false
60
68
  else
@@ -130,7 +138,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
130
138
  # Creates an HTML link to +name+ with the given +text+.
131
139
 
132
140
  def link name, text, code = true
133
- if name =~ /(.*[^#:])@/ then
141
+ if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
134
142
  name = $1
135
143
  label = $'
136
144
  end
@@ -144,7 +152,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
144
152
  path = ref.as_href @from_path
145
153
 
146
154
  if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
147
- text = "<code>#{text}</code>"
155
+ text = "<code>#{CGI.escapeHTML text}</code>"
148
156
  end
149
157
 
150
158
  if path =~ /#/ then
@@ -153,7 +161,11 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
153
161
  ref.sections.any? { |section| label == section.title } then
154
162
  path << "##{label}"
155
163
  else
156
- path << "#label-#{label}"
164
+ if ref.respond_to?(:aref)
165
+ path << "##{ref.aref}-label-#{label}"
166
+ else
167
+ path << "#label-#{label}"
168
+ end
157
169
  end if label
158
170
 
159
171
  "<a href=\"#{path}\">#{text}</a>"
@@ -41,6 +41,7 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
41
41
  alias accept_raw ignore
42
42
  alias accept_rule ignore
43
43
  alias accept_verbatim ignore
44
+ alias accept_table ignore
44
45
 
45
46
  end
46
47
 
@@ -237,6 +237,34 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
237
237
  @res << "\n"
238
238
  end
239
239
 
240
+ ##
241
+ # Adds +table+ to the output
242
+
243
+ def accept_table header, body, aligns
244
+ widths = header.zip(body) do |h, b|
245
+ [h.size, b.size].max
246
+ end
247
+ aligns = aligns.map do |a|
248
+ case a
249
+ when nil
250
+ :center
251
+ when :left
252
+ :ljust
253
+ when :right
254
+ :rjust
255
+ end
256
+ end
257
+ @res << header.zip(widths, aligns) do |h, w, a|
258
+ h.__send__(a, w)
259
+ end.join("|").rstrip << "\n"
260
+ @res << widths.map {|w| "-" * w }.join("|") << "\n"
261
+ body.each do |row|
262
+ @res << row.zip(widths, aligns) do |t, w, a|
263
+ t.__send__(a, w)
264
+ end.join("|").rstrip << "\n"
265
+ end
266
+ end
267
+
240
268
  ##
241
269
  # Applies attribute-specific markup to +text+ using RDoc::AttributeManager
242
270
 
@@ -82,6 +82,7 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
82
82
  alias accept_list_item_end ignore
83
83
  alias accept_list_end_bullet ignore
84
84
  alias accept_list_start ignore
85
+ alias accept_table ignore
85
86
  # :startdoc:
86
87
 
87
88
  end
data/lib/rdoc/options.rb CHANGED
@@ -338,13 +338,17 @@ class RDoc::Options
338
338
 
339
339
  attr_reader :visibility
340
340
 
341
- def initialize # :nodoc:
341
+ def initialize loaded_options = nil # :nodoc:
342
342
  init_ivars
343
+ override loaded_options if loaded_options
343
344
  end
344
345
 
345
346
  def init_ivars # :nodoc:
346
347
  @dry_run = false
347
- @exclude = []
348
+ @exclude = %w[
349
+ ~\z \.orig\z \.rej\z \.bak\z
350
+ \.gemspec\z
351
+ ]
348
352
  @files = nil
349
353
  @force_output = false
350
354
  @force_update = true
@@ -414,6 +418,37 @@ class RDoc::Options
414
418
  init_with map
415
419
  end
416
420
 
421
+ def override map # :nodoc:
422
+ if map.has_key?('encoding')
423
+ encoding = map['encoding']
424
+ @encoding = encoding ? Encoding.find(encoding) : encoding
425
+ end
426
+
427
+ @charset = map['charset'] if map.has_key?('charset')
428
+ @exclude = map['exclude'] if map.has_key?('exclude')
429
+ @generator_name = map['generator_name'] if map.has_key?('generator_name')
430
+ @hyperlink_all = map['hyperlink_all'] if map.has_key?('hyperlink_all')
431
+ @line_numbers = map['line_numbers'] if map.has_key?('line_numbers')
432
+ @locale_name = map['locale_name'] if map.has_key?('locale_name')
433
+ @locale_dir = map['locale_dir'] if map.has_key?('locale_dir')
434
+ @main_page = map['main_page'] if map.has_key?('main_page')
435
+ @markup = map['markup'] if map.has_key?('markup')
436
+ @op_dir = map['op_dir'] if map.has_key?('op_dir')
437
+ @show_hash = map['show_hash'] if map.has_key?('show_hash')
438
+ @tab_width = map['tab_width'] if map.has_key?('tab_width')
439
+ @template_dir = map['template_dir'] if map.has_key?('template_dir')
440
+ @title = map['title'] if map.has_key?('title')
441
+ @visibility = map['visibility'] if map.has_key?('visibility')
442
+ @webcvs = map['webcvs'] if map.has_key?('webcvs')
443
+
444
+ if map.has_key?('rdoc_include')
445
+ @rdoc_include = sanitize_path map['rdoc_include']
446
+ end
447
+ if map.has_key?('static_path')
448
+ @static_path = sanitize_path map['static_path']
449
+ end
450
+ end
451
+
417
452
  def == other # :nodoc:
418
453
  self.class === other and
419
454
  @encoding == other.encoding and
@@ -552,7 +587,13 @@ class RDoc::Options
552
587
 
553
588
  @files << @page_dir.to_s
554
589
 
555
- page_dir = @page_dir.expand_path.relative_path_from @root
590
+ page_dir = nil
591
+ begin
592
+ page_dir = @page_dir.expand_path.relative_path_from @root
593
+ rescue ArgumentError
594
+ # On Windows, sometimes crosses different drive letters.
595
+ page_dir = @page_dir.expand_path
596
+ end
556
597
 
557
598
  @page_dir = page_dir
558
599
  end
@@ -746,7 +787,7 @@ Usage: #{opt.program_name} [options] [names...]
746
787
 
747
788
  opt.on("--[no-]force-update", "-U",
748
789
  "Forces rdoc to scan all sources even if",
749
- "newer than the flag file.") do |value|
790
+ "no files are newer than the flag file.") do |value|
750
791
  @force_update = value
751
792
  end
752
793
 
@@ -1151,8 +1192,17 @@ Usage: #{opt.program_name} [options] [names...]
1151
1192
 
1152
1193
  path.reject do |item|
1153
1194
  path = Pathname.new(item).expand_path
1154
- relative = path.relative_path_from(dot).to_s
1155
- relative.start_with? '..'
1195
+ is_reject = nil
1196
+ relative = nil
1197
+ begin
1198
+ relative = path.relative_path_from(dot).to_s
1199
+ rescue ArgumentError
1200
+ # On Windows, sometimes crosses different drive letters.
1201
+ is_reject = true
1202
+ else
1203
+ is_reject = relative.start_with? '..'
1204
+ end
1205
+ is_reject
1156
1206
  end
1157
1207
  end
1158
1208
 
data/lib/rdoc/parser.rb CHANGED
@@ -78,7 +78,7 @@ class RDoc::Parser
78
78
 
79
79
  return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
80
80
 
81
- mode = 'r:utf-8' # default source encoding has been chagened to utf-8
81
+ mode = 'r:utf-8' # default source encoding has been changed to utf-8
82
82
  s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
83
83
  encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
84
84
  mode = "rb:#{encoding}" if encoding
@@ -269,9 +269,9 @@ class RDoc::Parser
269
269
  end
270
270
 
271
271
  # simple must come first in order to show up last in the parsers list
272
- require 'rdoc/parser/simple'
273
- require 'rdoc/parser/c'
274
- require 'rdoc/parser/changelog'
275
- require 'rdoc/parser/markdown'
276
- require 'rdoc/parser/rd'
277
- require 'rdoc/parser/ruby'
272
+ require_relative 'parser/simple'
273
+ require_relative 'parser/c'
274
+ require_relative 'parser/changelog'
275
+ require_relative 'parser/markdown'
276
+ require_relative 'parser/rd'
277
+ require_relative 'parser/ruby'
data/lib/rdoc/parser/c.rb CHANGED
@@ -3,15 +3,15 @@ require 'tsort'
3
3
 
4
4
  ##
5
5
  # RDoc::Parser::C attempts to parse C extension files. It looks for
6
- # the standard patterns that you find in extensions: <tt>rb_define_class,
7
- # rb_define_method</tt> and so on. It tries to find the corresponding
6
+ # the standard patterns that you find in extensions: +rb_define_class+,
7
+ # +rb_define_method+ and so on. It tries to find the corresponding
8
8
  # C source for the methods and extract comments, but if we fail
9
9
  # we don't worry too much.
10
10
  #
11
11
  # The comments associated with a Ruby method are extracted from the C
12
12
  # comment block associated with the routine that _implements_ that
13
13
  # method, that is to say the method whose name is given in the
14
- # <tt>rb_define_method</tt> call. For example, you might write:
14
+ # +rb_define_method+ call. For example, you might write:
15
15
  #
16
16
  # /*
17
17
  # * Returns a new array that is a one-dimensional flattening of this
@@ -24,8 +24,7 @@ require 'tsort'
24
24
  # * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
25
25
  # */
26
26
  # static VALUE
27
- # rb_ary_flatten(ary)
28
- # VALUE ary;
27
+ # rb_ary_flatten(VALUE ary)
29
28
  # {
30
29
  # ary = rb_obj_dup(ary);
31
30
  # rb_ary_flatten_bang(ary);
@@ -35,16 +34,16 @@ require 'tsort'
35
34
  # ...
36
35
  #
37
36
  # void
38
- # Init_Array()
37
+ # Init_Array(void)
39
38
  # {
40
39
  # ...
41
40
  # rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
42
41
  #
43
- # Here RDoc will determine from the rb_define_method line that there's a
42
+ # Here RDoc will determine from the +rb_define_method+ line that there's a
44
43
  # method called "flatten" in class Array, and will look for the implementation
45
- # in the method rb_ary_flatten. It will then use the comment from that
44
+ # in the method +rb_ary_flatten+. It will then use the comment from that
46
45
  # method in the HTML output. This method must be in the same source file
47
- # as the rb_define_method.
46
+ # as the +rb_define_method+.
48
47
  #
49
48
  # The comment blocks may include special directives:
50
49
  #
@@ -70,15 +69,15 @@ require 'tsort'
70
69
  # [Document-variable: +name+]
71
70
  # Documentation for the named +rb_define_variable+
72
71
  #
73
- # [Document-method: +method_name+]
72
+ # [Document-method\: +method_name+]
74
73
  # Documentation for the named method. Use this when the method name is
75
74
  # unambiguous.
76
75
  #
77
- # [Document-method: <tt>ClassName::method_name<tt>]
76
+ # [Document-method\: <tt>ClassName::method_name</tt>]
78
77
  # Documentation for a singleton method in the given class. Use this when
79
78
  # the method name alone is ambiguous.
80
79
  #
81
- # [Document-method: <tt>ClassName#method_name<tt>]
80
+ # [Document-method\: <tt>ClassName#method_name</tt>]
82
81
  # Documentation for a instance method in the given class. Use this when the
83
82
  # method name alone is ambiguous.
84
83
  #
@@ -210,48 +209,6 @@ class RDoc::Parser::C < RDoc::Parser
210
209
  end
211
210
  end
212
211
 
213
- ##
214
- # Removes duplicate call-seq entries for methods using the same
215
- # implementation.
216
-
217
- def deduplicate_call_seq
218
- @methods.each do |var_name, functions|
219
- class_name = @known_classes[var_name]
220
- next unless class_name
221
- class_obj = find_class var_name, class_name
222
-
223
- functions.each_value do |method_names|
224
- next if method_names.length == 1
225
-
226
- method_names.each do |method_name|
227
- deduplicate_method_name class_obj, method_name
228
- end
229
- end
230
- end
231
- end
232
-
233
- ##
234
- # If two ruby methods share a C implementation (and comment) this
235
- # deduplicates the examples in the call_seq for the method to reduce
236
- # confusion in the output.
237
-
238
- def deduplicate_method_name class_obj, method_name # :nodoc:
239
- return unless
240
- method = class_obj.method_list.find { |m| m.name == method_name }
241
- return unless call_seq = method.call_seq
242
-
243
- method_name = method_name[0, 1] if method_name =~ /\A\[/
244
-
245
- entries = call_seq.split "\n"
246
-
247
- matching = entries.select do |entry|
248
- entry =~ /^\w*\.?#{Regexp.escape method_name}/ or
249
- entry =~ /\s#{Regexp.escape method_name}\s/
250
- end
251
-
252
- method.call_seq = matching.join "\n"
253
- end
254
-
255
212
  ##
256
213
  # Scans #content for rb_define_alias
257
214
 
@@ -270,23 +227,29 @@ class RDoc::Parser::C < RDoc::Parser
270
227
  end
271
228
 
272
229
  class_obj = find_class var_name, class_name
273
-
274
- al = RDoc::Alias.new '', old_name, new_name, ''
275
- al.singleton = @singleton_classes.key? var_name
276
-
277
230
  comment = find_alias_comment var_name, new_name, old_name
278
-
279
231
  comment.normalize
280
-
281
- al.comment = comment
282
-
283
- al.record_location @top_level
284
-
285
- class_obj.add_alias al
286
- @stats.add_alias al
232
+ if comment.to_s.empty? and existing_method = class_obj.method_list.find { |m| m.name == old_name}
233
+ comment = existing_method.comment
234
+ end
235
+ add_alias(var_name, class_obj, old_name, new_name, comment)
287
236
  end
288
237
  end
289
238
 
239
+ ##
240
+ # Add alias, either from a direct alias definition, or from two
241
+ # method that reference the same function.
242
+
243
+ def add_alias(var_name, class_obj, old_name, new_name, comment)
244
+ al = RDoc::Alias.new '', old_name, new_name, ''
245
+ al.singleton = @singleton_classes.key? var_name
246
+ al.comment = comment
247
+ al.record_location @top_level
248
+ class_obj.add_alias al
249
+ @stats.add_alias al
250
+ al
251
+ end
252
+
290
253
  ##
291
254
  # Scans #content for rb_attr and rb_define_attr
292
255
 
@@ -325,12 +288,100 @@ class RDoc::Parser::C < RDoc::Parser
325
288
  # Scans #content for rb_define_class, boot_defclass, rb_define_class_under
326
289
  # and rb_singleton_class
327
290
 
328
- def do_classes
329
- do_boot_defclass
330
- do_define_class
331
- do_define_class_under
332
- do_singleton_class
333
- do_struct_define_without_accessor
291
+ def do_classes_and_modules
292
+ do_boot_defclass if @file_name == "class.c"
293
+
294
+ @content.scan(
295
+ %r(
296
+ (?<var_name>[\w\.]+)\s* =
297
+ \s*rb_(?:
298
+ define_(?:
299
+ class(?: # rb_define_class(class_name_1, parent_name_1)
300
+ \s*\(
301
+ \s*"(?<class_name_1>\w+)",
302
+ \s*(?<parent_name_1>\w+)\s*
303
+ \)
304
+ |
305
+ _under\s*\( # rb_define_class_under(class_under, class_name2, parent_name2...)
306
+ \s* (?<class_under>\w+),
307
+ \s* "(?<class_name_2>\w+)",
308
+ \s*
309
+ (?:
310
+ (?<parent_name_2>[\w\*\s\(\)\.\->]+) |
311
+ rb_path2class\("(?<path>[\w:]+)"\)
312
+ )
313
+ \s*\)
314
+ )
315
+ |
316
+ module(?: # rb_define_module(module_name_1)
317
+ \s*\(
318
+ \s*"(?<module_name_1>\w+)"\s*
319
+ \)
320
+ |
321
+ _under\s*\( # rb_define_module_under(module_under, module_name_2)
322
+ \s*(?<module_under>\w+),
323
+ \s*"(?<module_name_2>\w+)"
324
+ \s*\)
325
+ )
326
+ )
327
+ |
328
+ struct_define_without_accessor\s*\( # rb_struct_define_without_accessor(class_name_3, parent_name_3, ...)
329
+ \s*"(?<class_name_3>\w+)",
330
+ \s*(?<parent_name_3>\w+),
331
+ \s*\w+, # Allocation function
332
+ (?:\s*"\w+",)* # Attributes
333
+ \s*NULL
334
+ \)
335
+ |
336
+ singleton_class\s*\( # rb_singleton_class(target_class_name)
337
+ \s*(?<target_class_name>\w+)
338
+ \)
339
+ )
340
+ )mx
341
+ ) do
342
+ class_name = $~[:class_name_1]
343
+ type = :class
344
+ if class_name
345
+ # rb_define_class(class_name_1, parent_name_1)
346
+ parent_name = $~[:parent_name_1]
347
+ #under = nil
348
+ else
349
+ class_name = $~[:class_name_2]
350
+ if class_name
351
+ # rb_define_class_under(class_under, class_name2, parent_name2...)
352
+ parent_name = $~[:parent_name_2] || $~[:path]
353
+ under = $~[:class_under]
354
+ else
355
+ class_name = $~[:class_name_3]
356
+ if class_name
357
+ # rb_struct_define_without_accessor(class_name_3, parent_name_3, ...)
358
+ parent_name = $~[:parent_name_3]
359
+ #under = nil
360
+ else
361
+ type = :module
362
+ class_name = $~[:module_name_1]
363
+ #parent_name = nil
364
+ if class_name
365
+ # rb_define_module(module_name_1)
366
+ #under = nil
367
+ else
368
+ class_name = $~[:module_name_2]
369
+ if class_name
370
+ # rb_define_module_under(module_under, module_name_1)
371
+ under = $~[:module_under]
372
+ else
373
+ # rb_singleton_class(target_class_name)
374
+ target_class_name = $~[:target_class_name]
375
+ handle_singleton $~[:var_name], target_class_name
376
+ next
377
+ end
378
+ end
379
+ end
380
+ end
381
+ end
382
+
383
+ handle_class_module($~[:var_name], type, class_name, parent_name, under)
384
+ end
334
385
  end
335
386
 
336
387
  ##
@@ -379,65 +430,6 @@ class RDoc::Parser::C < RDoc::Parser
379
430
  end
380
431
  end
381
432
 
382
- ##
383
- # Scans #content for rb_define_class
384
-
385
- def do_define_class
386
- # The '.' lets us handle SWIG-generated files
387
- @content.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
388
- \(
389
- \s*"(\w+)",
390
- \s*(\w+)\s*
391
- \)/mx) do |var_name, class_name, parent|
392
- handle_class_module(var_name, :class, class_name, parent, nil)
393
- end
394
- end
395
-
396
- ##
397
- # Scans #content for rb_define_class_under
398
-
399
- def do_define_class_under
400
- @content.scan(/([\w\.]+)\s* = # var_name
401
- \s*rb_define_class_under\s*
402
- \(
403
- \s* (\w+), # under
404
- \s* "(\w+)", # class_name
405
- \s*
406
- (?:
407
- ([\w\*\s\(\)\.\->]+) | # parent_name
408
- rb_path2class\("([\w:]+)"\) # path
409
- )
410
- \s*
411
- \)
412
- /mx) do |var_name, under, class_name, parent_name, path|
413
- parent = path || parent_name
414
-
415
- handle_class_module var_name, :class, class_name, parent, under
416
- end
417
- end
418
-
419
- ##
420
- # Scans #content for rb_define_module
421
-
422
- def do_define_module
423
- @content.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
424
- |var_name, class_name|
425
- handle_class_module(var_name, :module, class_name, nil, nil)
426
- end
427
- end
428
-
429
- ##
430
- # Scans #content for rb_define_module_under
431
-
432
- def do_define_module_under
433
- @content.scan(/(\w+)\s* = \s*rb_define_module_under\s*
434
- \(
435
- \s*(\w+),
436
- \s*"(\w+)"
437
- \s*\)/mx) do |var_name, in_module, class_name|
438
- handle_class_module(var_name, :module, class_name, nil, in_module)
439
- end
440
- end
441
433
 
442
434
  ##
443
435
  # Scans #content for rb_include_module
@@ -447,7 +439,7 @@ class RDoc::Parser::C < RDoc::Parser
447
439
  next unless cls = @classes[c]
448
440
  m = @known_classes[m] || m
449
441
 
450
- comment = RDoc::Comment.new '', @top_level
442
+ comment = RDoc::Comment.new '', @top_level, :c
451
443
  incl = cls.add_include RDoc::Include.new(m, comment)
452
444
  incl.record_location @top_level
453
445
  end
@@ -519,42 +511,6 @@ class RDoc::Parser::C < RDoc::Parser
519
511
  end
520
512
  end
521
513
 
522
- ##
523
- # Scans #content for rb_define_module and rb_define_module_under
524
-
525
- def do_modules
526
- do_define_module
527
- do_define_module_under
528
- end
529
-
530
- ##
531
- # Scans #content for rb_singleton_class
532
-
533
- def do_singleton_class
534
- @content.scan(/([\w\.]+)\s* = \s*rb_singleton_class\s*
535
- \(
536
- \s*(\w+)
537
- \s*\)/mx) do |sclass_var, class_var|
538
- handle_singleton sclass_var, class_var
539
- end
540
- end
541
-
542
- ##
543
- # Scans #content for struct_define_without_accessor
544
-
545
- def do_struct_define_without_accessor
546
- @content.scan(/([\w\.]+)\s* = \s*rb_struct_define_without_accessor\s*
547
- \(
548
- \s*"(\w+)", # Class name
549
- \s*(\w+), # Parent class
550
- \s*\w+, # Allocation function
551
- (\s*"\w+",)* # Attributes
552
- \s*NULL
553
- \)/mx) do |var_name, class_name, parent|
554
- handle_class_module(var_name, :class, class_name, parent, nil)
555
- end
556
- end
557
-
558
514
  ##
559
515
  # Finds the comment for an alias on +class_name+ from +new_name+ to
560
516
  # +old_name+
@@ -565,7 +521,7 @@ class RDoc::Parser::C < RDoc::Parser
565
521
  \s*"#{Regexp.escape new_name}"\s*,
566
522
  \s*"#{Regexp.escape old_name}"\s*\);%xm
567
523
 
568
- RDoc::Comment.new($1 || '', @top_level)
524
+ RDoc::Comment.new($1 || '', @top_level, :c)
569
525
  end
570
526
 
571
527
  ##
@@ -604,7 +560,7 @@ class RDoc::Parser::C < RDoc::Parser
604
560
  ''
605
561
  end
606
562
 
607
- RDoc::Comment.new comment, @top_level
563
+ RDoc::Comment.new comment, @top_level, :c
608
564
  end
609
565
 
610
566
  ##
@@ -616,7 +572,7 @@ class RDoc::Parser::C < RDoc::Parser
616
572
  ((?>/\*.*?\*/\s*)?)
617
573
  ((?:(?:\w+)\s+)?
618
574
  (?:intern\s+)?VALUE\s+(\w+)
619
- \s*(?:\([^)]*\))(?:[^;]|$))
575
+ \s*(?:\([^)]*\))(?:[^\);]|$))
620
576
  | ((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+(\w+)\s+(\w+))
621
577
  | ^\s*\#\s*define\s+(\w+)\s+(\w+)
622
578
  }xm) do
@@ -644,7 +600,7 @@ class RDoc::Parser::C < RDoc::Parser
644
600
 
645
601
  case type
646
602
  when :func_def
647
- comment = RDoc::Comment.new args[0], @top_level
603
+ comment = RDoc::Comment.new args[0], @top_level, :c
648
604
  body = args[1]
649
605
  offset, = args[2]
650
606
 
@@ -674,7 +630,7 @@ class RDoc::Parser::C < RDoc::Parser
674
630
 
675
631
  body
676
632
  when :macro_def
677
- comment = RDoc::Comment.new args[0], @top_level
633
+ comment = RDoc::Comment.new args[0], @top_level, :c
678
634
  body = args[1]
679
635
  offset, = args[2]
680
636
 
@@ -781,7 +737,7 @@ class RDoc::Parser::C < RDoc::Parser
781
737
  comment = ''
782
738
  end
783
739
 
784
- comment = RDoc::Comment.new comment, @top_level
740
+ comment = RDoc::Comment.new comment, @top_level, :c
785
741
  comment.normalize
786
742
 
787
743
  look_for_directives_in class_mod, comment
@@ -826,7 +782,7 @@ class RDoc::Parser::C < RDoc::Parser
826
782
  table[const_name] ||
827
783
  ''
828
784
 
829
- RDoc::Comment.new comment, @top_level
785
+ RDoc::Comment.new comment, @top_level, :c
830
786
  end
831
787
 
832
788
  ##
@@ -857,7 +813,7 @@ class RDoc::Parser::C < RDoc::Parser
857
813
 
858
814
  return unless comment
859
815
 
860
- RDoc::Comment.new comment, @top_level
816
+ RDoc::Comment.new comment, @top_level, :c
861
817
  end
862
818
 
863
819
  ##
@@ -953,7 +909,7 @@ class RDoc::Parser::C < RDoc::Parser
953
909
  # can override the C value of the comment to give a friendly definition.
954
910
  #
955
911
  # /* 300: The perfect score in bowling */
956
- # rb_define_const(cFoo, "PERFECT", INT2FIX(300);
912
+ # rb_define_const(cFoo, "PERFECT", INT2FIX(300));
957
913
  #
958
914
  # Will override <tt>INT2FIX(300)</tt> with the value +300+ in the output
959
915
  # RDoc. Values may include quotes and escaped colons (\:).
@@ -991,7 +947,7 @@ class RDoc::Parser::C < RDoc::Parser
991
947
 
992
948
  new_comment = "#{$1}#{new_comment.lstrip}"
993
949
 
994
- new_comment = RDoc::Comment.new new_comment, @top_level
950
+ new_comment = RDoc::Comment.new new_comment, @top_level, :c
995
951
 
996
952
  con = RDoc::Constant.new const_name, new_definition, new_comment
997
953
  else
@@ -1029,6 +985,10 @@ class RDoc::Parser::C < RDoc::Parser
1029
985
 
1030
986
  class_obj = find_class var_name, class_name
1031
987
 
988
+ if existing_method = class_obj.method_list.find { |m| m.c_function == function }
989
+ add_alias(var_name, class_obj, existing_method.name, meth_name, existing_method.comment)
990
+ end
991
+
1032
992
  if class_obj then
1033
993
  if meth_name == 'initialize' then
1034
994
  meth_name = 'new'
@@ -1248,8 +1208,7 @@ class RDoc::Parser::C < RDoc::Parser
1248
1208
  def scan
1249
1209
  remove_commented_out_lines
1250
1210
 
1251
- do_modules
1252
- do_classes
1211
+ do_classes_and_modules
1253
1212
  do_missing
1254
1213
 
1255
1214
  do_constants
@@ -1258,12 +1217,9 @@ class RDoc::Parser::C < RDoc::Parser
1258
1217
  do_aliases
1259
1218
  do_attrs
1260
1219
 
1261
- deduplicate_call_seq
1262
-
1263
1220
  @store.add_c_variables self
1264
1221
 
1265
1222
  @top_level
1266
1223
  end
1267
1224
 
1268
1225
  end
1269
-