rdoc 6.1.0 → 6.3.0

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -0
  3. data/README.rdoc +0 -1
  4. data/Rakefile +12 -4
  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 +35 -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 +1 -1
  39. data/lib/rdoc/markdown.rb +16287 -0
  40. data/lib/rdoc/markdown/literals.rb +417 -0
  41. data/lib/rdoc/markup.rb +0 -2
  42. data/lib/rdoc/markup/formatter.rb +1 -1
  43. data/lib/rdoc/markup/parser.rb +58 -42
  44. data/lib/rdoc/markup/pre_process.rb +1 -1
  45. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  46. data/lib/rdoc/markup/to_html.rb +19 -6
  47. data/lib/rdoc/markup/to_html_crossref.rb +18 -6
  48. data/lib/rdoc/options.rb +23 -5
  49. data/lib/rdoc/parser.rb +7 -7
  50. data/lib/rdoc/parser/c.rb +139 -183
  51. data/lib/rdoc/parser/ripper_state_lex.rb +2 -1
  52. data/lib/rdoc/parser/ruby.rb +18 -8
  53. data/lib/rdoc/rd/block_parser.rb +1056 -0
  54. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  55. data/lib/rdoc/rdoc.rb +26 -20
  56. data/lib/rdoc/ri/driver.rb +9 -5
  57. data/lib/rdoc/ri/paths.rb +3 -17
  58. data/lib/rdoc/ri/task.rb +1 -1
  59. data/lib/rdoc/rubygems_hook.rb +2 -2
  60. data/lib/rdoc/servlet.rb +16 -8
  61. data/lib/rdoc/store.rb +6 -14
  62. data/lib/rdoc/task.rb +1 -1
  63. data/lib/rdoc/text.rb +8 -2
  64. data/lib/rdoc/token_stream.rb +8 -3
  65. data/lib/rdoc/tom_doc.rb +6 -7
  66. data/lib/rdoc/version.rb +1 -1
  67. data/man/ri.1 +247 -0
  68. data/rdoc.gemspec +194 -10
  69. metadata +10 -86
  70. data/.document +0 -5
  71. data/.gitignore +0 -14
  72. data/.travis.yml +0 -21
  73. data/appveyor.yml +0 -36
  74. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  75. data/lib/rdoc/markup/formatter_test_case.rb +0 -764
  76. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
@@ -178,7 +178,7 @@ class RDoc::Markup::PreProcess
178
178
 
179
179
  blankline
180
180
  when 'include' then
181
- filename = param.split.first
181
+ filename = param.split(' ', 2).first
182
182
  include_file filename, prefix, encoding
183
183
  when 'main' then
184
184
  @options.main_page = param if @options.respond_to? :main_page
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Hold details of a regexp handling sequence
4
+
5
+ class RDoc::Markup::RegexpHandling
6
+
7
+ ##
8
+ # Regexp handling type
9
+
10
+ attr_reader :type
11
+
12
+ ##
13
+ # Regexp handling text
14
+
15
+ attr_accessor :text
16
+
17
+ ##
18
+ # Creates a new regexp handling sequence of +type+ with +text+
19
+
20
+ def initialize(type, text)
21
+ @type, @text = type, text
22
+ end
23
+
24
+ ##
25
+ # Regexp handlings are equal when the have the same text and type
26
+
27
+ def ==(o)
28
+ self.text == o.text && self.type == o.type
29
+ end
30
+
31
+ def inspect # :nodoc:
32
+ "#<RDoc::Markup::RegexpHandling:0x%x @type=%p, @text=%p>" % [
33
+ object_id, @type, text.dump]
34
+ end
35
+
36
+ def to_s # :nodoc:
37
+ "RegexpHandling: type=#{type} text=#{text.dump}"
38
+ end
39
+
40
+ end
41
+
@@ -52,12 +52,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
52
52
  @th = nil
53
53
  @hard_break = "<br>\n"
54
54
 
55
- # external links
56
- @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
57
- :HYPERLINK)
58
-
59
- add_regexp_handling_RDOCLINK
60
- add_regexp_handling_TIDYLINK
55
+ init_regexp_handlings
61
56
 
62
57
  init_tags
63
58
  end
@@ -66,6 +61,24 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
66
61
  #
67
62
  # These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.
68
63
 
64
+ ##
65
+ # Adds regexp handlings.
66
+
67
+ def init_regexp_handlings
68
+ # external links
69
+ @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
70
+ :HYPERLINK)
71
+ init_link_notation_regexp_handlings
72
+ end
73
+
74
+ ##
75
+ # Adds regexp handlings about link notations.
76
+
77
+ def init_link_notation_regexp_handlings
78
+ add_regexp_handling_RDOCLINK
79
+ add_regexp_handling_TIDYLINK
80
+ end
81
+
69
82
  def handle_RDOCLINK url # :nodoc:
70
83
  case url
71
84
  when /^rdoc-ref:/
@@ -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>"
@@ -344,7 +344,10 @@ class RDoc::Options
344
344
 
345
345
  def init_ivars # :nodoc:
346
346
  @dry_run = false
347
- @exclude = []
347
+ @exclude = %w[
348
+ ~\z \.orig\z \.rej\z \.bak\z
349
+ \.gemspec\z
350
+ ]
348
351
  @files = nil
349
352
  @force_output = false
350
353
  @force_update = true
@@ -552,7 +555,13 @@ class RDoc::Options
552
555
 
553
556
  @files << @page_dir.to_s
554
557
 
555
- page_dir = @page_dir.expand_path.relative_path_from @root
558
+ page_dir = nil
559
+ begin
560
+ page_dir = @page_dir.expand_path.relative_path_from @root
561
+ rescue ArgumentError
562
+ # On Windows, sometimes crosses different drive letters.
563
+ page_dir = @page_dir.expand_path
564
+ end
556
565
 
557
566
  @page_dir = page_dir
558
567
  end
@@ -746,7 +755,7 @@ Usage: #{opt.program_name} [options] [names...]
746
755
 
747
756
  opt.on("--[no-]force-update", "-U",
748
757
  "Forces rdoc to scan all sources even if",
749
- "newer than the flag file.") do |value|
758
+ "no files are newer than the flag file.") do |value|
750
759
  @force_update = value
751
760
  end
752
761
 
@@ -1151,8 +1160,17 @@ Usage: #{opt.program_name} [options] [names...]
1151
1160
 
1152
1161
  path.reject do |item|
1153
1162
  path = Pathname.new(item).expand_path
1154
- relative = path.relative_path_from(dot).to_s
1155
- relative.start_with? '..'
1163
+ is_reject = nil
1164
+ relative = nil
1165
+ begin
1166
+ relative = path.relative_path_from(dot).to_s
1167
+ rescue ArgumentError
1168
+ # On Windows, sometimes crosses different drive letters.
1169
+ is_reject = true
1170
+ else
1171
+ is_reject = relative.start_with? '..'
1172
+ end
1173
+ is_reject
1156
1174
  end
1157
1175
  end
1158
1176
 
@@ -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'
@@ -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
-