rdoc 2.4.3 → 2.5

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 (139) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +3 -1
  3. data/History.txt +68 -0
  4. data/LICENSE.txt +57 -0
  5. data/Manifest.txt +37 -19
  6. data/README.txt +2 -12
  7. data/Rakefile +12 -12
  8. data/bin/rdoc +4 -4
  9. data/lib/rdoc.rb +32 -9
  10. data/lib/rdoc/alias.rb +2 -2
  11. data/lib/rdoc/any_method.rb +108 -16
  12. data/lib/rdoc/attr.rb +87 -1
  13. data/lib/rdoc/class_module.rb +131 -5
  14. data/lib/rdoc/code_object.rb +28 -5
  15. data/lib/rdoc/constant.rb +22 -0
  16. data/lib/rdoc/context.rb +80 -37
  17. data/lib/rdoc/gauntlet.rb +48 -0
  18. data/lib/rdoc/generator/darkfish.rb +25 -23
  19. data/lib/rdoc/generator/markup.rb +6 -29
  20. data/lib/rdoc/generator/ri.rb +39 -189
  21. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +17 -1
  22. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +10 -0
  23. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  24. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  25. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  26. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  27. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  28. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  29. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  30. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  31. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  32. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  33. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  34. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  35. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  36. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  37. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  38. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  39. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +2 -2
  41. data/lib/rdoc/generator/template/darkfish/rdoc.css +38 -33
  42. data/lib/rdoc/include.rb +22 -0
  43. data/lib/rdoc/markup.rb +10 -262
  44. data/lib/rdoc/markup/attribute_manager.rb +57 -50
  45. data/lib/rdoc/markup/blank_line.rb +19 -0
  46. data/lib/rdoc/markup/document.rb +72 -0
  47. data/lib/rdoc/markup/formatter.rb +118 -0
  48. data/lib/rdoc/markup/formatter_test_case.rb +341 -0
  49. data/lib/rdoc/markup/heading.rb +17 -0
  50. data/lib/rdoc/markup/inline.rb +6 -5
  51. data/lib/rdoc/markup/list.rb +78 -0
  52. data/lib/rdoc/markup/list_item.rb +83 -0
  53. data/lib/rdoc/markup/paragraph.rb +66 -0
  54. data/lib/rdoc/markup/parser.rb +528 -0
  55. data/lib/rdoc/markup/rule.rb +17 -0
  56. data/lib/rdoc/markup/to_ansi.rb +72 -0
  57. data/lib/rdoc/markup/to_bs.rb +74 -0
  58. data/lib/rdoc/markup/to_html.rb +106 -172
  59. data/lib/rdoc/markup/to_html_crossref.rb +10 -4
  60. data/lib/rdoc/markup/to_rdoc.rb +243 -0
  61. data/lib/rdoc/markup/to_test.rb +27 -16
  62. data/lib/rdoc/markup/verbatim.rb +42 -0
  63. data/lib/rdoc/normal_class.rb +38 -1
  64. data/lib/rdoc/normal_module.rb +38 -8
  65. data/lib/rdoc/options.rb +39 -151
  66. data/lib/rdoc/parser.rb +36 -18
  67. data/lib/rdoc/parser/c.rb +102 -109
  68. data/lib/rdoc/parser/ruby.rb +359 -1662
  69. data/lib/rdoc/parser/ruby_tools.rb +157 -0
  70. data/lib/rdoc/parser/simple.rb +0 -2
  71. data/lib/rdoc/rdoc.rb +142 -82
  72. data/lib/rdoc/ri.rb +10 -0
  73. data/lib/rdoc/ri/driver.rb +674 -444
  74. data/lib/rdoc/ri/formatter.rb +2 -651
  75. data/lib/rdoc/ri/paths.rb +70 -45
  76. data/lib/rdoc/ri/store.rb +248 -0
  77. data/lib/rdoc/ruby_lex.rb +1284 -0
  78. data/lib/rdoc/ruby_token.rb +416 -0
  79. data/lib/rdoc/single_class.rb +5 -0
  80. data/lib/rdoc/stats.rb +152 -83
  81. data/lib/rdoc/task.rb +27 -49
  82. data/lib/rdoc/text.rb +130 -0
  83. data/lib/rdoc/tokenstream.rb +28 -9
  84. data/lib/rdoc/top_level.rb +49 -43
  85. data/test/hidden.zip.txt +1 -0
  86. data/test/test_attribute_manager.rb +9 -16
  87. data/test/test_rdoc_any_method.rb +23 -0
  88. data/test/test_rdoc_attr.rb +40 -0
  89. data/test/test_rdoc_class_module.rb +100 -0
  90. data/test/test_rdoc_code_object.rb +18 -2
  91. data/test/test_rdoc_context.rb +41 -0
  92. data/test/test_rdoc_generator_ri.rb +56 -0
  93. data/test/test_rdoc_markup.rb +21 -610
  94. data/test/test_rdoc_markup_attribute_manager.rb +14 -17
  95. data/test/test_rdoc_markup_document.rb +51 -0
  96. data/test/test_rdoc_markup_paragraph.rb +27 -0
  97. data/test/test_rdoc_markup_parser.rb +1327 -0
  98. data/test/test_rdoc_markup_to_ansi.rb +426 -0
  99. data/test/test_rdoc_markup_to_bs.rb +443 -0
  100. data/test/test_rdoc_markup_to_html.rb +183 -18
  101. data/test/test_rdoc_markup_to_html_crossref.rb +1 -3
  102. data/test/test_rdoc_markup_to_rdoc.rb +426 -0
  103. data/test/test_rdoc_normal_class.rb +17 -0
  104. data/test/test_rdoc_normal_module.rb +6 -6
  105. data/test/test_rdoc_options.rb +41 -0
  106. data/test/test_rdoc_parser.rb +66 -13
  107. data/test/test_rdoc_parser_c.rb +93 -38
  108. data/test/test_rdoc_parser_perl.rb +2 -3
  109. data/test/test_rdoc_parser_ruby.rb +291 -28
  110. data/test/test_rdoc_parser_simple.rb +48 -0
  111. data/test/test_rdoc_rdoc.rb +66 -0
  112. data/test/test_rdoc_ri_driver.rb +752 -38
  113. data/test/test_rdoc_ri_paths.rb +39 -0
  114. data/test/test_rdoc_ri_store.rb +309 -0
  115. data/test/test_rdoc_text.rb +157 -0
  116. data/test/test_rdoc_top_level.rb +35 -9
  117. data/test/xref_data.rb +9 -1
  118. data/test/xref_test_case.rb +8 -3
  119. metadata +110 -38
  120. metadata.gz.sig +0 -0
  121. data/lib/rdoc/cache.rb +0 -41
  122. data/lib/rdoc/diagram.rb +0 -340
  123. data/lib/rdoc/dot.rb +0 -249
  124. data/lib/rdoc/markup/fragments.rb +0 -377
  125. data/lib/rdoc/markup/lines.rb +0 -156
  126. data/lib/rdoc/markup/to_flow.rb +0 -211
  127. data/lib/rdoc/markup/to_latex.rb +0 -328
  128. data/lib/rdoc/markup/to_texinfo.rb +0 -73
  129. data/lib/rdoc/ri/cache.rb +0 -187
  130. data/lib/rdoc/ri/descriptions.rb +0 -156
  131. data/lib/rdoc/ri/display.rb +0 -340
  132. data/lib/rdoc/ri/reader.rb +0 -106
  133. data/lib/rdoc/ri/util.rb +0 -79
  134. data/lib/rdoc/ri/writer.rb +0 -68
  135. data/test/test_rdoc_ri_attribute_formatter.rb +0 -44
  136. data/test/test_rdoc_ri_default_display.rb +0 -302
  137. data/test/test_rdoc_ri_formatter.rb +0 -320
  138. data/test/test_rdoc_ri_html_formatter.rb +0 -141
  139. data/test/test_rdoc_ri_overstrike_formatter.rb +0 -71
@@ -12,21 +12,11 @@ class RDoc::Options
12
12
 
13
13
  attr_reader :charset
14
14
 
15
- ##
16
- # Should diagrams be drawn?
17
-
18
- attr_accessor :diagram
19
-
20
15
  ##
21
16
  # Files matching this pattern will be excluded
22
17
 
23
18
  attr_accessor :exclude
24
19
 
25
- ##
26
- # Should we draw fileboxes in diagrams?
27
-
28
- attr_reader :fileboxes
29
-
30
20
  ##
31
21
  # The list of files to be processed
32
22
 
@@ -47,27 +37,12 @@ class RDoc::Options
47
37
 
48
38
  attr_accessor :formatter
49
39
 
50
- ##
51
- # Image format for diagrams
52
-
53
- attr_reader :image_format
54
-
55
- ##
56
- # Include line numbers in the source listings?
57
-
58
- attr_reader :include_line_numbers
59
-
60
40
  ##
61
41
  # Name of the file, class or module to display in the initial index page (if
62
42
  # not specified the first file we encounter is used)
63
43
 
64
44
  attr_accessor :main_page
65
45
 
66
- ##
67
- # Merge into classes of the same name when generating ri
68
-
69
- attr_reader :merge
70
-
71
46
  ##
72
47
  # The name of the output directory
73
48
 
@@ -103,11 +78,6 @@ class RDoc::Options
103
78
 
104
79
  attr_reader :template
105
80
 
106
- ##
107
- # Number of threads to parse with
108
-
109
- attr_accessor :threads
110
-
111
81
  ##
112
82
  # Documentation title
113
83
 
@@ -125,10 +95,9 @@ class RDoc::Options
125
95
 
126
96
  def initialize # :nodoc:
127
97
  require 'rdoc/rdoc'
128
- @op_dir = 'doc'
98
+ @op_dir = nil
129
99
  @show_all = false
130
100
  @main_page = nil
131
- @merge = false
132
101
  @exclude = []
133
102
  @generators = RDoc::RDoc::GENERATORS
134
103
  @generator = RDoc::Generator::Darkfish
@@ -136,17 +105,8 @@ class RDoc::Options
136
105
  @rdoc_include = []
137
106
  @title = nil
138
107
  @template = nil
139
- @threads = if RUBY_PLATFORM == 'java' then
140
- Java::java::lang::Runtime.getRuntime.availableProcessors * 2
141
- else
142
- 2
143
- end
144
- @diagram = false
145
- @fileboxes = false
146
108
  @show_hash = false
147
- @image_format = 'png'
148
109
  @tab_width = 8
149
- @include_line_numbers = false
150
110
  @force_update = true
151
111
  @verbosity = 1
152
112
  @pipe = false
@@ -160,6 +120,8 @@ class RDoc::Options
160
120
  # Parse command line options.
161
121
 
162
122
  def parse(argv)
123
+ ignore_invalid = true
124
+
163
125
  opts = OptionParser.new do |opt|
164
126
  opt.program_name = File.basename $0
165
127
  opt.version = RDoc::VERSION
@@ -178,10 +140,22 @@ Usage: #{opt.program_name} [options] [names...]
178
140
  the options you give.
179
141
 
180
142
  - Darkfish creates frameless HTML output by Michael Granger.
181
-
182
143
  - ri creates ri data files
144
+
145
+ RDoc understands the following file formats:
146
+
183
147
  EOF
184
148
 
149
+ parsers = Hash.new { |h,parser| h[parser] = [] }
150
+
151
+ RDoc::Parser.parsers.each do |regexp, parser|
152
+ parsers[parser.name.sub('RDoc::Parser::', '')] << regexp.source
153
+ end
154
+
155
+ parsers.sort.each do |parser, regexp|
156
+ opt.banner << " - #{parser}: #{regexp.join ', '}\n"
157
+ end
158
+
185
159
  opt.separator nil
186
160
  opt.separator "Parsing Options:"
187
161
  opt.separator nil
@@ -212,7 +186,7 @@ Usage: #{opt.program_name} [options] [names...]
212
186
  raise OptionParser::InvalidArgument, "Invalid parameter to '-E'"
213
187
  end
214
188
 
215
- unless RDoc::ParserFactory.alias_extension old, new then
189
+ unless RDoc::Parser.alias_extension old, new then
216
190
  raise OptionParser::InvalidArgument, "Unknown extension .#{old} to -E"
217
191
  end
218
192
  end
@@ -232,13 +206,6 @@ Usage: #{opt.program_name} [options] [names...]
232
206
  @pipe = true
233
207
  end
234
208
 
235
- opt.separator nil
236
-
237
- opt.on("--threads=THREADS", Integer,
238
- "Number of threads to parse with.") do |threads|
239
- @threads = threads
240
- end
241
-
242
209
  opt.separator nil
243
210
  opt.separator "Generator Options:"
244
211
  opt.separator nil
@@ -269,13 +236,6 @@ Usage: #{opt.program_name} [options] [names...]
269
236
 
270
237
  opt.separator nil
271
238
 
272
- opt.on("--line-numbers", "-N",
273
- "Include line numbers in the source code.") do |value|
274
- @include_line_numbers = value
275
- end
276
-
277
- opt.separator nil
278
-
279
239
  opt.on("--main=NAME", "-m",
280
240
  "NAME will be the initial page displayed.") do |value|
281
241
  @main_page = value
@@ -331,41 +291,9 @@ Usage: #{opt.program_name} [options] [names...]
331
291
  @webcvs = value
332
292
  end
333
293
 
334
- opt.separator nil
335
- opt.separator "Diagram Options:"
336
294
  opt.separator nil
337
295
 
338
- image_formats = %w[gif png jpg jpeg]
339
- opt.on("--image-format=FORMAT", "-I", image_formats,
340
- "Sets output image format for diagrams. Can",
341
- "be #{image_formats.join ', '}. If this option",
342
- "is omitted, png is used. Requires",
343
- "diagrams.") do |value|
344
- @image_format = value
345
- end
346
-
347
- opt.separator nil
348
-
349
- opt.on("--diagram", "-d",
350
- "Generate diagrams showing modules and",
351
- "classes. You need dot V1.8.6 or later to",
352
- "use the --diagram option correctly. Dot is",
353
- "available from http://graphviz.org") do |value|
354
- check_diagram
355
- @diagram = true
356
- end
357
-
358
- opt.separator nil
359
-
360
- opt.on("--fileboxes", "-F",
361
- "Classes are put in boxes which represents",
362
- "files, where these classes reside. Classes",
363
- "shared between more than one file are",
364
- "shown with list of files that are sharing",
365
- "them. Silently discarded if --diagram is",
366
- "not given.") do |value|
367
- @fileboxes = value
368
- end
296
+ opt.on("-d", "--diagram", "Prevents -d from tripping --debug")
369
297
 
370
298
  opt.separator nil
371
299
  opt.separator "ri Generator Options:"
@@ -378,7 +306,7 @@ Usage: #{opt.program_name} [options] [names...]
378
306
  "subsequent --op parameter, so no special",
379
307
  "privileges are needed.") do |value|
380
308
  @generator_name = "ri"
381
- @op_dir = RDoc::RI::Paths::HOMEDIR
309
+ @op_dir ||= RDoc::RI::Paths::HOMEDIR
382
310
  setup_generator
383
311
  end
384
312
 
@@ -394,24 +322,20 @@ Usage: #{opt.program_name} [options] [names...]
394
322
  setup_generator
395
323
  end
396
324
 
397
- opt.separator nil
398
-
399
- opt.on("--merge", "-M",
400
- "When creating ri output, merge previously",
401
- "processed classes into previously",
402
- "documented classes of the same name.") do |value|
403
- @merge = value
404
- end
405
-
406
325
  opt.separator nil
407
326
  opt.separator "Generic Options:"
408
327
  opt.separator nil
409
328
 
410
- opt.on("--debug", "-D",
329
+ opt.on("-D", "--[no-]debug",
411
330
  "Displays lots on internal stuff.") do |value|
412
331
  $DEBUG_RDOC = value
413
332
  end
414
333
 
334
+ opt.on("--[no-]ignore-invalid",
335
+ "Ignore invalid options and continue.") do |value|
336
+ ignore_invalid = value
337
+ end
338
+
415
339
  opt.on("--quiet", "-q",
416
340
  "Don't show progress as we parse.") do |value|
417
341
  @verbosity = 0
@@ -422,25 +346,26 @@ Usage: #{opt.program_name} [options] [names...]
422
346
  @verbosity = 2
423
347
  end
424
348
 
425
- opt.separator nil
426
- opt.separator 'Deprecated options - these warn when set'
427
- opt.separator nil
428
-
429
- opt.on("--inline-source", "-S") do |value|
430
- warn "--inline-source will be removed from RDoc on or after August 2009"
431
- end
432
-
433
- opt.on("--promiscuous", "-p") do |value|
434
- warn "--promiscuous will be removed from RDoc on or after August 2009"
435
- end
436
-
437
349
  opt.separator nil
438
350
  end
439
351
 
440
352
  argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
441
353
 
442
- opts.parse! argv
354
+ begin
355
+ opts.parse! argv
356
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
357
+ if ignore_invalid and not quiet then
358
+ $stderr.puts e
359
+ $stderr.puts '(invalid options are ignored)'
360
+ else
361
+ $stderr.puts opts
362
+ $stderr.puts
363
+ $stderr.puts e
364
+ exit 1
365
+ end
366
+ end
443
367
 
368
+ @op_dir ||= 'doc'
444
369
  @files = argv.dup
445
370
 
446
371
  @rdoc_include << "." if @rdoc_include.empty?
@@ -457,12 +382,6 @@ Usage: #{opt.program_name} [options] [names...]
457
382
  # formatter
458
383
 
459
384
  @template ||= @generator_name
460
-
461
- rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
462
- puts opts
463
- puts
464
- puts e
465
- exit 1
466
385
  end
467
386
 
468
387
  ##
@@ -497,37 +416,6 @@ Usage: #{opt.program_name} [options] [names...]
497
416
  end
498
417
  end
499
418
 
500
- # Check that the right version of 'dot' is available. Unfortunately this
501
- # doesn't work correctly under Windows NT, so we'll bypass the test under
502
- # Windows.
503
-
504
- def check_diagram
505
- return if RUBY_PLATFORM =~ /mswin|cygwin|mingw|bccwin/
506
-
507
- ok = false
508
- ver = nil
509
-
510
- IO.popen "dot -V 2>&1" do |io|
511
- ver = io.read
512
- if ver =~ /dot.+version(?:\s+gviz)?\s+(\d+)\.(\d+)/ then
513
- ok = ($1.to_i > 1) || ($1.to_i == 1 && $2.to_i >= 8)
514
- end
515
- end
516
-
517
- unless ok then
518
- if ver =~ /^dot.+version/ then
519
- $stderr.puts "Warning: You may need dot V1.8.6 or later to use\n",
520
- "the --diagram option correctly. You have:\n\n ",
521
- ver,
522
- "\nDiagrams might have strange background colors.\n\n"
523
- else
524
- $stderr.puts "You need the 'dot' program to produce diagrams.",
525
- "(see http://www.research.att.com/sw/tools/graphviz/)\n\n"
526
- exit
527
- end
528
- end
529
- end
530
-
531
419
  ##
532
420
  # Check that the files on the command line exist
533
421
 
@@ -63,19 +63,37 @@ class RDoc::Parser
63
63
  end
64
64
 
65
65
  ##
66
- # Shamelessly stolen from the ptools gem (since RDoc cannot depend on
67
- # the gem).
66
+ # Determines if the file is a "binary" file which basically means it has
67
+ # content that an RDoc parser shouldn't try to consume.
68
68
 
69
69
  def self.binary?(file)
70
- s = (File.read(file, File.stat(file).blksize) || "").split(//)
70
+ s = File.read(file, File.stat(file).blksize) || ""
71
71
 
72
- if s.size > 0 then
73
- ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
74
- else
72
+ if s[0, 2] == Marshal.dump('')[0, 2] then
73
+ true
74
+ elsif file =~ /erb\.rb$/ then
75
75
  false
76
+ elsif s.scan(/<%|%>/).length >= 4 then
77
+ true
78
+ else
79
+ # From ptools under the Artistic License 2.0, (c) Daniel Berger.
80
+ s = s.split(//)
81
+
82
+ ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
76
83
  end
77
84
  end
78
- private_class_method :binary?
85
+
86
+ ##
87
+ # Checks if +file+ is a zip file in disguise. Signatures from
88
+ # http://www.garykessler.net/library/file_sigs.html
89
+
90
+ def self.zip? file
91
+ zip_signature = File.read file, 4
92
+
93
+ zip_signature == "PK\x03\x04" or
94
+ zip_signature == "PK\x05\x06" or
95
+ zip_signature == "PK\x07\x08"
96
+ end
79
97
 
80
98
  ##
81
99
  # Return a parser that can handle a particular extension
@@ -83,16 +101,13 @@ class RDoc::Parser
83
101
  def self.can_parse(file_name)
84
102
  parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }.last
85
103
 
86
- #
87
- # The default parser should *NOT* parse binary files.
88
- #
89
- if parser == RDoc::Parser::Simple && file_name !~ /\.(txt|rdoc)$/ then
90
- if binary? file_name then
91
- return nil
92
- end
93
- end
104
+ # HACK Selenium hides a jar file using a .txt extension
105
+ return if parser == RDoc::Parser::Simple and zip? file_name
106
+
107
+ # The default parser must not parse binary files
108
+ return if parser == RDoc::Parser::Simple and file_name !~ /\.(txt|rdoc)$/
94
109
 
95
- return parser
110
+ parser
96
111
  end
97
112
 
98
113
  ##
@@ -100,6 +115,8 @@ class RDoc::Parser
100
115
  # for ones that we don't know
101
116
 
102
117
  def self.for(top_level, file_name, body, options, stats)
118
+ return if binary? file_name
119
+
103
120
  # If no extension, look for shebang
104
121
  if file_name !~ /\.\w+$/ && body =~ %r{\A#!(.+)} then
105
122
  shebang = $1
@@ -111,14 +128,15 @@ class RDoc::Parser
111
128
 
112
129
  parser = can_parse file_name
113
130
 
114
- # This method must return a parser.
115
- parser ||= RDoc::Parser::Simple
131
+ return unless parser
116
132
 
117
133
  parser.new top_level, file_name, body, options, stats
118
134
  end
119
135
 
120
136
  ##
121
137
  # Record which file types this parser can understand.
138
+ #
139
+ # It is ok to call this multiple times.
122
140
 
123
141
  def self.parse_files_matching(regexp)
124
142
  RDoc::Parser.parsers.unshift [regexp, self]
@@ -14,32 +14,32 @@ require 'rdoc/known_classes'
14
14
  # method, that is to say the method whose name is given in the
15
15
  # <tt>rb_define_method</tt> call. For example, you might write:
16
16
  #
17
- # /*
18
- # * Returns a new array that is a one-dimensional flattening of this
19
- # * array (recursively). That is, for every element that is an array,
20
- # * extract its elements into the new array.
21
- # *
22
- # * s = [ 1, 2, 3 ] #=> [1, 2, 3]
23
- # * t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
24
- # * a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
25
- # * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
26
- # */
27
- # static VALUE
28
- # rb_ary_flatten(ary)
29
- # VALUE ary;
30
- # {
31
- # ary = rb_obj_dup(ary);
32
- # rb_ary_flatten_bang(ary);
33
- # return ary;
34
- # }
17
+ # /*
18
+ # * Returns a new array that is a one-dimensional flattening of this
19
+ # * array (recursively). That is, for every element that is an array,
20
+ # * extract its elements into the new array.
21
+ # *
22
+ # * s = [ 1, 2, 3 ] #=> [1, 2, 3]
23
+ # * t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
24
+ # * a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
25
+ # * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
26
+ # */
27
+ # static VALUE
28
+ # rb_ary_flatten(ary)
29
+ # VALUE ary;
30
+ # {
31
+ # ary = rb_obj_dup(ary);
32
+ # rb_ary_flatten_bang(ary);
33
+ # return ary;
34
+ # }
35
35
  #
36
- # ...
36
+ # ...
37
37
  #
38
- # void
39
- # Init_Array()
40
- # {
41
- # ...
42
- # rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
38
+ # void
39
+ # Init_Array()
40
+ # {
41
+ # ...
42
+ # rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
43
43
  #
44
44
  # Here RDoc will determine from the rb_define_method line that there's a
45
45
  # method called "flatten" in class Array, and will look for the implementation
@@ -47,9 +47,6 @@ require 'rdoc/known_classes'
47
47
  # method in the HTML output. This method must be in the same source file
48
48
  # as the rb_define_method.
49
49
  #
50
- # C classes can be diagrammed (see /tc/dl/ruby/ruby/error.c), and RDoc
51
- # integrates C and Ruby source into one tree
52
- #
53
50
  # The comment blocks may include special directives:
54
51
  #
55
52
  # [Document-class: <i>name</i>]
@@ -68,7 +65,7 @@ require 'rdoc/known_classes'
68
65
  # Ruby function is in the same source file as the rb_define_method call.
69
66
  # If this isn't the case, add the comment:
70
67
  #
71
- # rb_define_method(....); // in: filename
68
+ # rb_define_method(....); // in: filename
72
69
  #
73
70
  # As an example, we might have an extension that defines multiple classes
74
71
  # in its Init_xxx method. We could document them using
@@ -96,6 +93,8 @@ class RDoc::Parser::C < RDoc::Parser
96
93
 
97
94
  parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)
98
95
 
96
+ include RDoc::Text
97
+
99
98
  ##
100
99
  # C file the parser is parsing
101
100
 
@@ -177,19 +176,17 @@ class RDoc::Parser::C < RDoc::Parser
177
176
 
178
177
  def do_constants
179
178
  @content.scan(%r{\Wrb_define_
180
- (
181
- variable |
182
- readonly_variable |
183
- const |
184
- global_const |
185
- )
179
+ ( variable |
180
+ readonly_variable |
181
+ const |
182
+ global_const | )
186
183
  \s*\(
187
184
  (?:\s*(\w+),)?
188
185
  \s*"(\w+)",
189
186
  \s*(.*?)\s*\)\s*;
190
187
  }xm) do |type, var_name, const_name, definition|
191
188
  var_name = "rb_cObject" if !var_name or var_name == "rb_mKernel"
192
- handle_constants(type, var_name, const_name, definition)
189
+ handle_constants type, var_name, const_name, definition
193
190
  end
194
191
  end
195
192
 
@@ -309,8 +306,10 @@ class RDoc::Parser::C < RDoc::Parser
309
306
 
310
307
  # meth_obj.params = params
311
308
  meth_obj.start_collecting_tokens
312
- meth_obj.add_token RDoc::RubyToken::Token.new(1,1).set_text(body_text)
313
- meth_obj.comment = mangle_comment comment
309
+ tk = RDoc::RubyToken::Token.new nil, 1, 1
310
+ tk.set_text body_text
311
+ meth_obj.add_token tk
312
+ meth_obj.comment = strip_stars comment
314
313
  when %r{((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+#{meth_name}\s+(\w+))}m
315
314
  comment = $1
316
315
  body_text = $2
@@ -318,8 +317,10 @@ class RDoc::Parser::C < RDoc::Parser
318
317
  find_modifiers comment, meth_obj
319
318
 
320
319
  meth_obj.start_collecting_tokens
321
- meth_obj.add_token RDoc::RubyToken::Token.new(1,1).set_text(body_text)
322
- meth_obj.comment = mangle_comment(comment) + meth_obj.comment.to_s
320
+ tk = RDoc::RubyToken::Token.new nil, 1, 1
321
+ tk.set_text body_text
322
+ meth_obj.add_token tk
323
+ meth_obj.comment = strip_stars(comment) + meth_obj.comment.to_s
323
324
  when %r{^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
324
325
  unless find_body(class_name, $1, meth_obj, body, true)
325
326
  warn "No definition for #{meth_name}" unless @options.quiet
@@ -331,7 +332,7 @@ class RDoc::Parser::C < RDoc::Parser
331
332
 
332
333
  if comment
333
334
  find_modifiers(comment, meth_obj)
334
- meth_obj.comment = mangle_comment(comment)
335
+ meth_obj.comment = strip_stars comment
335
336
  else
336
337
  warn "No definition for #{meth_name}" unless @options.quiet
337
338
  return false
@@ -380,11 +381,14 @@ class RDoc::Parser::C < RDoc::Parser
380
381
  # */
381
382
  # VALUE cFoo = rb_define_class("Foo", rb_cObject);
382
383
 
383
- def find_class_comment(class_name, class_meth)
384
+ def find_class_comment(class_name, class_mod)
384
385
  comment = nil
385
386
 
386
- if @content =~ %r{((?>/\*.*?\*/\s+))
387
- (static\s+)?void\s+Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)\)}xmi then
387
+ if @content =~ %r{
388
+ ((?>/\*.*?\*/\s+))
389
+ (static\s+)?
390
+ void\s+
391
+ Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)?\)}xmi then # )
388
392
  comment = $1
389
393
  elsif @content =~ %r{Document-(?:class|module):\s+#{class_name}\s*?(?:<\s+[:,\w]+)?\n((?>.*?\*/))}m then
390
394
  comment = $1
@@ -393,7 +397,7 @@ class RDoc::Parser::C < RDoc::Parser
393
397
  comment = $1
394
398
  end
395
399
 
396
- class_meth.comment = mangle_comment comment if comment
400
+ class_mod.comment = strip_stars comment if comment
397
401
  end
398
402
 
399
403
  ##
@@ -444,53 +448,45 @@ class RDoc::Parser::C < RDoc::Parser
444
448
 
445
449
  def handle_attr(var_name, attr_name, reader, writer)
446
450
  rw = ''
447
- if reader
448
- #@stats.num_methods += 1
449
- rw << 'R'
450
- end
451
- if writer
452
- #@stats.num_methods += 1
453
- rw << 'W'
454
- end
451
+ rw << 'R' if reader
452
+ rw << 'W' if writer
455
453
 
456
454
  class_name = @known_classes[var_name]
457
455
 
458
456
  return unless class_name
459
457
 
460
- class_obj = find_class(var_name, class_name)
458
+ class_obj = find_class(var_name, class_name)
461
459
 
462
460
  if class_obj
463
461
  comment = find_attr_comment(attr_name)
464
- unless comment.empty?
465
- comment = mangle_comment(comment)
466
- end
462
+ comment = strip_stars comment
467
463
  att = RDoc::Attr.new '', attr_name, rw, comment
464
+ @stats.add_method att
468
465
  class_obj.add_attribute(att)
469
466
  end
470
467
  end
471
468
 
472
- def handle_class_module(var_name, class_mod, class_name, parent, in_module)
469
+ def handle_class_module(var_name, type, class_name, parent, in_module)
473
470
  parent_name = @known_classes[parent] || parent
474
471
 
475
- if in_module
472
+ if in_module then
476
473
  enclosure = @classes[in_module] || @@enclosure_classes[in_module]
477
- unless enclosure
478
- if enclosure = @known_classes[in_module]
479
- handle_class_module(in_module, (/^rb_m/ =~ in_module ? "module" : "class"),
480
- enclosure, nil, nil)
481
- enclosure = @classes[in_module]
482
- end
474
+
475
+ if enclosure.nil? and enclosure = @known_classes[in_module] then
476
+ type = /^rb_m/ =~ in_module ? "module" : "class"
477
+ handle_class_module in_module, type, enclosure, nil, nil
478
+ enclosure = @classes[in_module]
483
479
  end
484
- unless enclosure
485
- warn("Enclosing class/module '#{in_module}' for " +
486
- "#{class_mod} #{class_name} not known")
480
+
481
+ unless enclosure then
482
+ warn("Enclosing class/module '#{in_module}' for #{type} #{class_name} not known")
487
483
  return
488
484
  end
489
485
  else
490
486
  enclosure = @top_level
491
487
  end
492
488
 
493
- if class_mod == "class" then
489
+ if type == "class" then
494
490
  full_name = if RDoc::ClassModule === enclosure then
495
491
  enclosure.full_name + "::#{class_name}"
496
492
  else
@@ -500,7 +496,9 @@ class RDoc::Parser::C < RDoc::Parser
500
496
  if @content =~ %r{Document-class:\s+#{full_name}\s*<\s+([:,\w]+)} then
501
497
  parent_name = $1
502
498
  end
499
+
503
500
  cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name
501
+
504
502
  @stats.add_class cm
505
503
  else
506
504
  cm = enclosure.add_module RDoc::NormalModule, class_name
@@ -528,46 +526,55 @@ class RDoc::Parser::C < RDoc::Parser
528
526
  # Values may include quotes and escaped colons (\:).
529
527
 
530
528
  def handle_constants(type, var_name, const_name, definition)
531
- #@stats.num_constants += 1
532
529
  class_name = @known_classes[var_name]
533
530
 
534
531
  return unless class_name
535
532
 
536
- class_obj = find_class(var_name, class_name)
533
+ class_obj = find_class var_name, class_name
537
534
 
538
- unless class_obj
539
- warn("Enclosing class/module '#{const_name}' for not known")
535
+ unless class_obj then
536
+ warn "Enclosing class/module #{const_name.inspect} not known"
540
537
  return
541
538
  end
542
539
 
543
- comment = find_const_comment(type, const_name)
540
+ comment = find_const_comment type, const_name
541
+ comment = strip_stars comment
542
+ comment = normalize_comment comment
544
543
 
545
544
  # In the case of rb_define_const, the definition and comment are in
546
545
  # "/* definition: comment */" form. The literal ':' and '\' characters
547
546
  # can be escaped with a backslash.
548
547
  if type.downcase == 'const' then
549
- elements = mangle_comment(comment).split(':')
550
- if elements.nil? or elements.empty? then
551
- con = RDoc::Constant.new(const_name, definition,
552
- mangle_comment(comment))
553
- else
554
- new_definition = elements[0..-2].join(':')
555
- if new_definition.empty? then # Default to literal C definition
556
- new_definition = definition
557
- else
558
- new_definition.gsub!("\:", ":")
559
- new_definition.gsub!("\\", '\\')
560
- end
561
- new_definition.sub!(/\A(\s+)/, '')
562
- new_comment = $1.nil? ? elements.last : "#{$1}#{elements.last.lstrip}"
563
- con = RDoc::Constant.new(const_name, new_definition,
564
- mangle_comment(new_comment))
565
- end
548
+ elements = comment.split ':'
549
+
550
+ if elements.nil? or elements.empty? then
551
+ con = RDoc::Constant.new const_name, definition, comment
552
+ else
553
+ new_definition = elements[0..-2].join(':')
554
+
555
+ if new_definition.empty? then # Default to literal C definition
556
+ new_definition = definition
557
+ else
558
+ new_definition.gsub!("\:", ":")
559
+ new_definition.gsub!("\\", '\\')
560
+ end
561
+
562
+ new_definition.sub!(/\A(\s+)/, '')
563
+
564
+ new_comment = if $1.nil? then
565
+ elements.last.lstrip
566
+ else
567
+ "#{$1}#{elements.last.lstrip}"
568
+ end
569
+
570
+ con = RDoc::Constant.new const_name, new_definition, new_comment
571
+ end
566
572
  else
567
- con = RDoc::Constant.new const_name, definition, mangle_comment(comment)
573
+ con = RDoc::Constant.new const_name, definition, comment
568
574
  end
569
575
 
570
- class_obj.add_constant(con)
576
+ @stats.add_constant con
577
+ class_obj.add_constant con
571
578
  end
572
579
 
573
580
  ##
@@ -604,9 +611,11 @@ class RDoc::Parser::C < RDoc::Parser
604
611
  meth_obj.params = "(" + (1..p_count).map{|i| "p#{i}"}.join(", ") + ")"
605
612
  end
606
613
 
607
- if source_file then
614
+ if source_file and File.exist? source_file then
608
615
  file_name = File.join(@file_dir, source_file)
609
616
  body = (@@known_bodies[source_file] ||= File.read(file_name))
617
+ elsif source_file then
618
+ warn "unknown source file #{source_file}"
610
619
  else
611
620
  body = @content
612
621
  end
@@ -631,16 +640,6 @@ class RDoc::Parser::C < RDoc::Parser
631
640
  end
632
641
  end
633
642
 
634
- ##
635
- # Remove the /*'s and leading asterisks from C comments
636
-
637
- def mangle_comment(comment)
638
- comment.sub!(%r{/\*+}) { " " * $&.length }
639
- comment.sub!(%r{\*+/}) { " " * $&.length }
640
- comment.gsub!(/^[ \t]*\*/m) { " " * $&.length }
641
- comment
642
- end
643
-
644
643
  ##
645
644
  # Removes lines that are commented out that might otherwise get picked up
646
645
  # when scanning for classes and methods
@@ -668,11 +667,5 @@ class RDoc::Parser::C < RDoc::Parser
668
667
  @top_level
669
668
  end
670
669
 
671
- def warn(msg)
672
- $stderr.puts
673
- $stderr.puts msg
674
- $stderr.flush
675
- end
676
-
677
670
  end
678
671