rdoc 5.1.0 → 6.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.rdoc +5 -6
  3. data/ExampleMarkdown.md +2 -0
  4. data/ExampleRDoc.rdoc +2 -0
  5. data/History.rdoc +68 -66
  6. data/LEGAL.rdoc +1 -1
  7. data/LICENSE.rdoc +2 -0
  8. data/README.rdoc +18 -6
  9. data/RI.md +842 -0
  10. data/TODO.rdoc +8 -7
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -12
  13. data/lib/rdoc/{anon_class.rb → code_object/anon_class.rb} +1 -2
  14. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +83 -26
  15. data/lib/rdoc/{attr.rb → code_object/attr.rb} +5 -9
  16. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +112 -24
  17. data/lib/rdoc/{constant.rb → code_object/constant.rb} +4 -5
  18. data/lib/rdoc/{context → code_object/context}/section.rb +13 -83
  19. data/lib/rdoc/{context.rb → code_object/context.rb} +69 -70
  20. data/lib/rdoc/{extend.rb → code_object/extend.rb} +1 -2
  21. data/lib/rdoc/{ghost_method.rb → code_object/ghost_method.rb} +1 -2
  22. data/lib/rdoc/{include.rb → code_object/include.rb} +1 -2
  23. data/lib/rdoc/{meta_method.rb → code_object/meta_method.rb} +1 -2
  24. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +22 -31
  25. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +1 -2
  26. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +4 -5
  27. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  28. data/lib/rdoc/{require.rb → code_object/require.rb} +2 -3
  29. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +6 -2
  30. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +22 -32
  31. data/lib/rdoc/code_object.rb +8 -41
  32. data/lib/rdoc/code_objects.rb +2 -3
  33. data/lib/rdoc/comment.rb +48 -41
  34. data/lib/rdoc/cross_reference.rb +77 -33
  35. data/lib/rdoc/encoding.rb +50 -38
  36. data/lib/rdoc/erb_partial.rb +2 -3
  37. data/lib/rdoc/erbio.rb +4 -5
  38. data/lib/rdoc/generator/darkfish.rb +178 -125
  39. data/lib/rdoc/generator/json_index.rb +9 -22
  40. data/lib/rdoc/generator/markup.rb +6 -17
  41. data/lib/rdoc/generator/pot/message_extractor.rb +4 -4
  42. data/lib/rdoc/generator/pot/po.rb +3 -3
  43. data/lib/rdoc/generator/pot/po_entry.rb +12 -12
  44. data/lib/rdoc/generator/pot.rb +4 -8
  45. data/lib/rdoc/generator/ri.rb +1 -2
  46. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  47. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -12
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +19 -10
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +26 -6
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -1
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +27 -6
  58. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  59. data/lib/rdoc/generator/template/darkfish/class.rhtml +125 -78
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +430 -339
  61. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/index.rhtml +13 -13
  64. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -92
  65. data/lib/rdoc/generator/template/darkfish/js/search.js +35 -34
  66. data/lib/rdoc/generator/template/darkfish/page.rhtml +5 -5
  67. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +10 -8
  68. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +20 -18
  69. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +32 -20
  70. data/lib/rdoc/generator/template/json_index/js/navigation.js +12 -49
  71. data/lib/rdoc/generator/template/json_index/js/searcher.js +6 -6
  72. data/lib/rdoc/generator.rb +6 -6
  73. data/lib/rdoc/i18n/locale.rb +1 -1
  74. data/lib/rdoc/i18n/text.rb +5 -5
  75. data/lib/rdoc/i18n.rb +4 -4
  76. data/lib/rdoc/known_classes.rb +6 -5
  77. data/lib/rdoc/markdown/entities.rb +1 -2
  78. data/lib/rdoc/markdown/literals.kpeg +1 -2
  79. data/lib/rdoc/markdown/literals.rb +99 -50
  80. data/lib/rdoc/markdown.kpeg +115 -58
  81. data/lib/rdoc/markdown.rb +1584 -902
  82. data/lib/rdoc/markup/attr_changer.rb +1 -2
  83. data/lib/rdoc/markup/attr_span.rb +9 -4
  84. data/lib/rdoc/markup/attribute_manager.rb +118 -57
  85. data/lib/rdoc/markup/attributes.rb +7 -8
  86. data/lib/rdoc/markup/blank_line.rb +1 -2
  87. data/lib/rdoc/markup/block_quote.rb +1 -2
  88. data/lib/rdoc/markup/document.rb +1 -2
  89. data/lib/rdoc/markup/formatter.rb +44 -37
  90. data/lib/rdoc/markup/hard_break.rb +1 -2
  91. data/lib/rdoc/markup/heading.rb +11 -6
  92. data/lib/rdoc/markup/include.rb +1 -2
  93. data/lib/rdoc/markup/indented_paragraph.rb +1 -2
  94. data/lib/rdoc/markup/list.rb +1 -2
  95. data/lib/rdoc/markup/list_item.rb +1 -2
  96. data/lib/rdoc/markup/paragraph.rb +1 -2
  97. data/lib/rdoc/markup/parser.rb +90 -48
  98. data/lib/rdoc/markup/pre_process.rb +38 -11
  99. data/lib/rdoc/markup/raw.rb +1 -2
  100. data/lib/rdoc/markup/regexp_handling.rb +40 -0
  101. data/lib/rdoc/markup/rule.rb +1 -2
  102. data/lib/rdoc/markup/table.rb +56 -0
  103. data/lib/rdoc/markup/to_ansi.rb +1 -2
  104. data/lib/rdoc/markup/to_bs.rb +30 -5
  105. data/lib/rdoc/markup/to_html.rb +95 -40
  106. data/lib/rdoc/markup/to_html_crossref.rb +108 -43
  107. data/lib/rdoc/markup/to_html_snippet.rb +13 -11
  108. data/lib/rdoc/markup/to_joined_paragraph.rb +6 -32
  109. data/lib/rdoc/markup/to_label.rb +11 -12
  110. data/lib/rdoc/markup/to_markdown.rb +13 -14
  111. data/lib/rdoc/markup/to_rdoc.rb +49 -31
  112. data/lib/rdoc/markup/to_table_of_contents.rb +2 -2
  113. data/lib/rdoc/markup/to_test.rb +1 -2
  114. data/lib/rdoc/markup/to_tt_only.rb +3 -4
  115. data/lib/rdoc/markup/verbatim.rb +1 -2
  116. data/lib/rdoc/markup.rb +64 -694
  117. data/lib/rdoc/options.rb +226 -44
  118. data/lib/rdoc/parser/c.rb +231 -246
  119. data/lib/rdoc/parser/changelog.rb +169 -23
  120. data/lib/rdoc/parser/markdown.rb +1 -3
  121. data/lib/rdoc/parser/prism_ruby.rb +1092 -0
  122. data/lib/rdoc/parser/rd.rb +1 -2
  123. data/lib/rdoc/parser/ripper_state_lex.rb +302 -0
  124. data/lib/rdoc/parser/ruby.rb +695 -478
  125. data/lib/rdoc/parser/ruby_tools.rb +33 -36
  126. data/lib/rdoc/parser/simple.rb +4 -4
  127. data/lib/rdoc/parser/text.rb +1 -2
  128. data/lib/rdoc/parser.rb +37 -42
  129. data/lib/rdoc/rd/block_parser.rb +708 -57
  130. data/lib/rdoc/rd/block_parser.ry +15 -11
  131. data/lib/rdoc/rd/inline.rb +5 -6
  132. data/lib/rdoc/rd/inline_parser.rb +787 -140
  133. data/lib/rdoc/rd/inline_parser.ry +1 -1
  134. data/lib/rdoc/rd.rb +4 -5
  135. data/lib/rdoc/rdoc.rb +72 -87
  136. data/lib/rdoc/ri/driver.rb +236 -152
  137. data/lib/rdoc/ri/formatter.rb +1 -1
  138. data/lib/rdoc/ri/paths.rb +4 -18
  139. data/lib/rdoc/ri/store.rb +1 -2
  140. data/lib/rdoc/ri/task.rb +2 -2
  141. data/lib/rdoc/ri.rb +5 -6
  142. data/lib/rdoc/rubygems_hook.rb +98 -20
  143. data/lib/rdoc/servlet.rb +30 -20
  144. data/lib/rdoc/stats/normal.rb +24 -18
  145. data/lib/rdoc/stats/quiet.rb +1 -2
  146. data/lib/rdoc/stats/verbose.rb +1 -3
  147. data/lib/rdoc/stats.rb +6 -7
  148. data/lib/rdoc/store.rb +84 -55
  149. data/lib/rdoc/task.rb +35 -10
  150. data/lib/rdoc/text.rb +40 -27
  151. data/lib/rdoc/token_stream.rb +56 -34
  152. data/lib/rdoc/tom_doc.rb +18 -19
  153. data/lib/rdoc/version.rb +10 -0
  154. data/lib/rdoc.rb +80 -56
  155. data/lib/rubygems_plugin.rb +23 -0
  156. data/man/ri.1 +247 -0
  157. metadata +45 -99
  158. data/.document +0 -5
  159. data/.gitignore +0 -13
  160. data/.travis.yml +0 -24
  161. data/Gemfile +0 -3
  162. data/RI.rdoc +0 -57
  163. data/Rakefile +0 -133
  164. data/bin/console +0 -7
  165. data/bin/setup +0 -6
  166. data/lib/gauntlet_rdoc.rb +0 -82
  167. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  168. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  169. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  170. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  171. data/lib/rdoc/generator/template/json_index/.document +0 -1
  172. data/lib/rdoc/markup/formatter_test_case.rb +0 -764
  173. data/lib/rdoc/markup/inline.rb +0 -2
  174. data/lib/rdoc/markup/special.rb +0 -41
  175. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
  176. data/lib/rdoc/ruby_lex.rb +0 -1367
  177. data/lib/rdoc/ruby_token.rb +0 -461
  178. data/lib/rdoc/test_case.rb +0 -204
  179. data/rdoc.gemspec +0 -57
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # A singleton class
4
4
 
@@ -22,5 +22,9 @@ class RDoc::SingleClass < RDoc::ClassModule
22
22
  "class << #{full_name}"
23
23
  end
24
24
 
25
+ def pretty_print q # :nodoc:
26
+ q.group 2, "[class << #{full_name}", "]" do
27
+ next
28
+ end
29
+ end
25
30
  end
26
-
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # A TopLevel context is a representation of the contents of a single file
4
4
 
@@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context
6
6
 
7
7
  MARSHAL_VERSION = 0 # :nodoc:
8
8
 
9
- ##
10
- # This TopLevel's File::Stat struct
11
-
12
- attr_accessor :file_stat
13
-
14
9
  ##
15
10
  # Relative name of this file
16
11
 
@@ -28,12 +23,10 @@ class RDoc::TopLevel < RDoc::Context
28
23
 
29
24
  attr_reader :classes_or_modules
30
25
 
31
- attr_accessor :diagram # :nodoc:
32
-
33
26
  ##
34
27
  # The parser class that processed this file
35
28
 
36
- attr_accessor :parser
29
+ attr_reader :parser
37
30
 
38
31
  ##
39
32
  # Creates a new TopLevel for the file at +absolute_name+. If documentation
@@ -45,13 +38,20 @@ class RDoc::TopLevel < RDoc::Context
45
38
  @name = nil
46
39
  @absolute_name = absolute_name
47
40
  @relative_name = relative_name
48
- @file_stat = File.stat(absolute_name) rescue nil # HACK for testing
49
- @diagram = nil
50
41
  @parser = nil
51
42
 
52
43
  @classes_or_modules = []
53
44
  end
54
45
 
46
+ ##
47
+ # Sets the parser for this toplevel context, also the store.
48
+
49
+ def parser=(val)
50
+ @parser = val
51
+ @store.update_parser_of_file(absolute_name, val) if @store
52
+ @parser
53
+ end
54
+
55
55
  ##
56
56
  # An RDoc::TopLevel is equal to another with the same relative_name
57
57
 
@@ -164,28 +164,19 @@ class RDoc::TopLevel < RDoc::Context
164
164
  ##
165
165
  # URL for this with a +prefix+
166
166
 
167
- def http_url(prefix)
168
- path = [prefix, @relative_name.tr('.', '_')]
169
-
170
- File.join(*path.compact) + '.html'
167
+ def http_url
168
+ @relative_name.tr('.', '_') + '.html'
171
169
  end
172
170
 
173
171
  def inspect # :nodoc:
174
172
  "#<%s:0x%x %p modules: %p classes: %p>" % [
175
173
  self.class, object_id,
176
174
  base_name,
177
- @modules.map { |n,m| m },
178
- @classes.map { |n,c| c }
175
+ @modules.map { |n, m| m },
176
+ @classes.map { |n, c| c }
179
177
  ]
180
178
  end
181
179
 
182
- ##
183
- # Time this file was last modified, if known
184
-
185
- def last_modified
186
- @file_stat ? file_stat.mtime : nil
187
- end
188
-
189
180
  ##
190
181
  # Dumps this TopLevel for use by ri. See also #marshal_load
191
182
 
@@ -205,9 +196,7 @@ class RDoc::TopLevel < RDoc::Context
205
196
  initialize array[1]
206
197
 
207
198
  @parser = array[2]
208
- @comment = array[3]
209
-
210
- @file_stat = nil
199
+ @comment = RDoc::Comment.from_document array[3]
211
200
  end
212
201
 
213
202
  ##
@@ -237,7 +226,9 @@ class RDoc::TopLevel < RDoc::Context
237
226
  # Path to this file for use with HTML generator output.
238
227
 
239
228
  def path
240
- http_url @store.rdoc.generator.file_dir
229
+ prefix = options.file_path_prefix
230
+ return http_url unless prefix
231
+ File.join(prefix, http_url)
241
232
  end
242
233
 
243
234
  def pretty_print q # :nodoc:
@@ -245,8 +236,8 @@ class RDoc::TopLevel < RDoc::Context
245
236
  q.text "base name: #{base_name.inspect}"
246
237
  q.breakable
247
238
 
248
- items = @modules.map { |n,m| m }
249
- items.concat @modules.map { |n,c| c }
239
+ items = @modules.map { |n, m| m }
240
+ items.concat @modules.map { |n, c| c }
250
241
  q.seplist items do |mod| q.pp mod end
251
242
  end
252
243
  end
@@ -272,7 +263,7 @@ class RDoc::TopLevel < RDoc::Context
272
263
  # Is this TopLevel from a text file instead of a source code file?
273
264
 
274
265
  def text?
275
- @parser and @parser.ancestors.include? RDoc::Parser::Text
266
+ @parser and @parser.include? RDoc::Parser::Text
276
267
  end
277
268
 
278
269
  def to_s # :nodoc:
@@ -280,4 +271,3 @@ class RDoc::TopLevel < RDoc::Context
280
271
  end
281
272
 
282
273
  end
283
-
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # Base class for the RDoc code tree.
4
4
  #
@@ -21,9 +21,10 @@
21
21
  # * RDoc::MetaMethod
22
22
  # * RDoc::Alias
23
23
  # * RDoc::Constant
24
+ # * RDoc::Require
24
25
  # * RDoc::Mixin
25
- # * RDoc::Require
26
26
  # * RDoc::Include
27
+ # * RDoc::Extend
27
28
 
28
29
  class RDoc::CodeObject
29
30
 
@@ -69,13 +70,6 @@ class RDoc::CodeObject
69
70
 
70
71
  attr_reader :metadata
71
72
 
72
- ##
73
- # Offset in #file where this CodeObject was defined
74
- #--
75
- # TODO character or byte?
76
-
77
- attr_accessor :offset
78
-
79
73
  ##
80
74
  # Sets the parent CodeObject
81
75
 
@@ -97,11 +91,9 @@ class RDoc::CodeObject
97
91
  attr_reader :store
98
92
 
99
93
  ##
100
- # We are the model of the code, but we know that at some point we will be
101
- # worked on by viewers. By implementing the Viewable protocol, viewers can
102
- # associated themselves with these objects.
94
+ # When mixed-in to a class, this points to the Context in which it was originally defined.
103
95
 
104
- attr_accessor :viewer
96
+ attr_accessor :mixin_from
105
97
 
106
98
  ##
107
99
  # Creates a new CodeObject that will document itself and its children
@@ -118,6 +110,7 @@ class RDoc::CodeObject
118
110
  @full_name = nil
119
111
  @store = nil
120
112
  @track_visibility = true
113
+ @mixin_from = nil
121
114
 
122
115
  initialize_visibility
123
116
  end
@@ -142,7 +135,6 @@ class RDoc::CodeObject
142
135
  def comment=(comment)
143
136
  @comment = case comment
144
137
  when NilClass then ''
145
- when RDoc::Markup::Document then comment
146
138
  when RDoc::Comment then comment.normalize
147
139
  else
148
140
  if comment and not comment.empty? then
@@ -151,7 +143,7 @@ class RDoc::CodeObject
151
143
  # HACK correct fix is to have #initialize create @comment
152
144
  # with the correct encoding
153
145
  if String === @comment and @comment.empty? then
154
- @comment.force_encoding comment.encoding
146
+ @comment = RDoc::Encoding.change_encoding @comment, comment.encoding
155
147
  end
156
148
  @comment
157
149
  end
@@ -218,20 +210,6 @@ class RDoc::CodeObject
218
210
  @document_children = @document_self
219
211
  end
220
212
 
221
- ##
222
- # Yields each parent of this CodeObject. See also
223
- # RDoc::ClassModule#each_ancestor
224
-
225
- def each_parent
226
- code_object = self
227
-
228
- while code_object = code_object.parent do
229
- yield code_object
230
- end
231
-
232
- self
233
- end
234
-
235
213
  ##
236
214
  # File name where this CodeObject was found.
237
215
  #
@@ -302,11 +280,7 @@ class RDoc::CodeObject
302
280
  # This is used by Text#snippet
303
281
 
304
282
  def options
305
- if @store and @store.rdoc then
306
- @store.rdoc.options
307
- else
308
- RDoc::Options.new
309
- end
283
+ @store&.options || RDoc::Options.new
310
284
  end
311
285
 
312
286
  ##
@@ -332,13 +306,6 @@ class RDoc::CodeObject
332
306
  end
333
307
  end
334
308
 
335
- ##
336
- # File name of our parent
337
-
338
- def parent_file_name
339
- @parent ? @parent.base_name : '(unknown)'
340
- end
341
-
342
309
  ##
343
310
  # Name of our parent
344
311
 
@@ -1,6 +1,5 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  # This file was used to load all the RDoc::CodeObject subclasses at once. Now
3
3
  # autoload handles this.
4
4
 
5
- require 'rdoc'
6
-
5
+ require_relative '../rdoc'
data/lib/rdoc/comment.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # A comment holds the text comment for a RDoc::CodeObject and provides a
4
4
  # unified way of cleaning it up and parsing it into an RDoc::Markup::Document.
@@ -6,8 +6,8 @@
6
6
  # Each comment may have a different markup format set by #format=. By default
7
7
  # 'rdoc' is used. The :markup: directive tells RDoc which format to use.
8
8
  #
9
- # See RDoc::Markup@Other+directives for instructions on adding an alternate
10
- # format.
9
+ # See RDoc::MarkupReference@Directive+for+Specifying+RDoc+Source+Format.
10
+
11
11
 
12
12
  class RDoc::Comment
13
13
 
@@ -23,6 +23,11 @@ class RDoc::Comment
23
23
 
24
24
  attr_accessor :location
25
25
 
26
+ ##
27
+ # Line where this Comment was written
28
+
29
+ attr_accessor :line
30
+
26
31
  ##
27
32
  # For duck-typing when merging classes at load time
28
33
 
@@ -33,6 +38,11 @@ class RDoc::Comment
33
38
 
34
39
  attr_reader :text
35
40
 
41
+ ##
42
+ # Alias for text
43
+
44
+ alias to_s text
45
+
36
46
  ##
37
47
  # Overrides the content returned by #parse. Use when there is no #text
38
48
  # source for this comment
@@ -43,9 +53,10 @@ class RDoc::Comment
43
53
  # Creates a new comment with +text+ that is found in the RDoc::TopLevel
44
54
  # +location+.
45
55
 
46
- def initialize text = nil, location = nil
56
+ def initialize text = nil, location = nil, language = nil
47
57
  @location = location
48
- @text = text
58
+ @text = text.nil? ? nil : text.dup
59
+ @language = language
49
60
 
50
61
  @document = nil
51
62
  @format = 'rdoc'
@@ -81,60 +92,46 @@ class RDoc::Comment
81
92
  # # ARGF.to_a(limit) -> array
82
93
  # # ARGF.to_a(sep, limit) -> array
83
94
 
84
- def extract_call_seq method
95
+ def extract_call_seq
85
96
  # we must handle situations like the above followed by an unindented first
86
97
  # comment. The difficulty is to make sure not to match lines starting
87
98
  # with ARGF at the same indent, but that are after the first description
88
99
  # paragraph.
89
- if @text =~ /^\s*:?call-seq:(.*?(?:\S).*?)^\s*$/m then
100
+ if /^(?<S> ((?!\n)\s)*+ (?# whitespaces except newline))
101
+ :?call-seq:
102
+ (?<B> \g<S>(?<N>\n|\z) (?# trailing spaces))?
103
+ (?<seq>
104
+ (\g<S>(?!\w)\S.*\g<N>)*
105
+ (?>
106
+ (?<H> \g<S>\w+ (?# ' # ARGF' in the example above))
107
+ .*\g<N>)?
108
+ (\g<S>\S.*\g<N> (?# other non-blank line))*+
109
+ (\g<B>+(\k<H>.*\g<N> (?# ARGF.to_a lines))++)*+
110
+ )
111
+ (?m:^\s*$|\z)
112
+ /x =~ @text
113
+ seq = $~[:seq]
114
+
90
115
  all_start, all_stop = $~.offset(0)
91
- seq_start, seq_stop = $~.offset(1)
92
-
93
- # we get the following lines that start with the leading word at the
94
- # same indent, even if they have blank lines before
95
- if $1 =~ /(^\s*\n)+^(\s*\w+)/m then
96
- leading = $2 # ' * ARGF' in the example above
97
- re = %r%
98
- \A(
99
- (^\s*\n)+
100
- (^#{Regexp.escape leading}.*?\n)+
101
- )+
102
- ^\s*$
103
- %xm
104
-
105
- if @text[seq_stop..-1] =~ re then
106
- all_stop = seq_stop + $~.offset(0).last
107
- seq_stop = seq_stop + $~.offset(1).last
108
- end
109
- end
110
-
111
- seq = @text[seq_start..seq_stop]
112
- seq.gsub!(/^\s*(\S|\n)/m, '\1')
113
116
  @text.slice! all_start...all_stop
114
117
 
115
- method.call_seq = seq.chomp
116
-
117
- elsif @text.sub!(/^\s*:?call-seq:(.*?)(^\s*$|\z)/m, '') then
118
- seq = $1
119
118
  seq.gsub!(/^\s*/, '')
120
- method.call_seq = seq
121
119
  end
122
-
123
- method
124
120
  end
125
121
 
126
122
  ##
127
123
  # A comment is empty if its text String is empty.
128
124
 
129
125
  def empty?
130
- @text.empty?
126
+ @text.empty? && (@document.nil? || @document.empty?)
131
127
  end
132
128
 
133
129
  ##
134
130
  # HACK dubious
135
131
 
136
- def force_encoding encoding
137
- @text.force_encoding encoding
132
+ def encode! encoding
133
+ @text = String.new @text, encoding: encoding
134
+ self
138
135
  end
139
136
 
140
137
  ##
@@ -200,7 +197,7 @@ class RDoc::Comment
200
197
  def remove_private
201
198
  # Workaround for gsub encoding for Ruby 1.9.2 and earlier
202
199
  empty = ''
203
- empty.force_encoding @text.encoding
200
+ empty = RDoc::Encoding.change_encoding empty, @text.encoding
204
201
 
205
202
  @text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
206
203
  @text = @text.sub(%r%^\s*[#*]?--.*%m, '')
@@ -216,7 +213,7 @@ class RDoc::Comment
216
213
  @text.nil? and @document
217
214
 
218
215
  @document = nil
219
- @text = text
216
+ @text = text.nil? ? nil : text.dup
220
217
  end
221
218
 
222
219
  ##
@@ -226,4 +223,14 @@ class RDoc::Comment
226
223
  @format == 'tomdoc'
227
224
  end
228
225
 
226
+ ##
227
+ # Create a new parsed comment from a document
228
+
229
+ def self.from_document(document) # :nodoc:
230
+ comment = RDoc::Comment.new('')
231
+ comment.document = document
232
+ comment.location = RDoc::TopLevel.new(document.file) if document.file
233
+ comment
234
+ end
235
+
229
236
  end
@@ -1,4 +1,7 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'markup/attribute_manager' # for PROTECT_ATTR
4
+
2
5
  ##
3
6
  # RDoc::CrossReference is a reusable way to create cross references for names.
4
7
 
@@ -14,32 +17,39 @@ class RDoc::CrossReference
14
17
 
15
18
  CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
16
19
 
20
+ ##
21
+ # Regular expression to match a single method argument.
22
+
23
+ METHOD_ARG_REGEXP_STR = '[\w.+*/=<>-]+'
24
+
25
+ ##
26
+ # Regular expression to match method arguments.
27
+
28
+ METHOD_ARGS_REGEXP_STR = /(?:\((?:#{METHOD_ARG_REGEXP_STR}(?:,\s*#{METHOD_ARG_REGEXP_STR})*)?\))?/.source
29
+
17
30
  ##
18
31
  # Regular expression to match method references.
19
32
  #
20
33
  # See CLASS_REGEXP_STR
21
34
 
22
- METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===|\[\]=?|<<|>>)(?:\([\w.+*/=<>-]*\))?'
35
+ METHOD_REGEXP_STR = /(
36
+ (?!\d)[\w#{RDoc::Markup::AttributeManager::PROTECT_ATTR}]+[!?=]?|
37
+ %|=(?:==?|~)|![=~]|\[\]=?|<(?:<|=>?)?|>[>=]?|[-+!]@?|\*\*?|[\/%\`|&^~]
38
+ )#{METHOD_ARGS_REGEXP_STR}/.source.delete("\n ").freeze
23
39
 
24
40
  ##
25
41
  # Regular expressions matching text that should potentially have
26
- # cross-reference links generated are passed to add_special. Note that
27
- # these expressions are meant to pick up text for which cross-references
42
+ # cross-reference links generated are passed to add_regexp_handling. Note
43
+ # that these expressions are meant to pick up text for which cross-references
28
44
  # have been suppressed, since the suppression characters are removed by the
29
45
  # code that is triggered.
30
46
 
31
- CROSSREF_REGEXP = /(?:^|\s)
47
+ CROSSREF_REGEXP = /(?:^|[\s()])
32
48
  (
33
49
  (?:
34
50
  # A::B::C.meth
35
51
  #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
36
52
 
37
- # Stand-alone method (preceded by a #)
38
- | \\?\##{METHOD_REGEXP_STR}
39
-
40
- # Stand-alone method (preceded by ::)
41
- | ::#{METHOD_REGEXP_STR}
42
-
43
53
  # A::B::C
44
54
  # The stuff after CLASS_REGEXP_STR is a
45
55
  # nasty hack. CLASS_REGEXP_STR unfortunately matches
@@ -56,6 +66,12 @@ class RDoc::CrossReference
56
66
  # marker.
57
67
  | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
58
68
 
69
+ # Stand-alone method (preceded by a #)
70
+ | \\?\##{METHOD_REGEXP_STR}
71
+
72
+ # Stand-alone method (preceded by ::)
73
+ | ::#{METHOD_REGEXP_STR}
74
+
59
75
  # Things that look like filenames
60
76
  # The key thing is that there must be at least
61
77
  # one special character (period, slash, or
@@ -76,18 +92,18 @@ class RDoc::CrossReference
76
92
  # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
77
93
 
78
94
  ALL_CROSSREF_REGEXP = /
79
- (?:^|\s)
95
+ (?:^|[\s()])
80
96
  (
81
97
  (?:
82
98
  # A::B::C.meth
83
99
  #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
84
100
 
85
- # Stand-alone method
86
- | \\?#{METHOD_REGEXP_STR}
87
-
88
101
  # A::B::C
89
102
  | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
90
103
 
104
+ # Stand-alone method
105
+ | \\?#{METHOD_REGEXP_STR}
106
+
91
107
  # Things that look like filenames
92
108
  | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
93
109
 
@@ -116,46 +132,75 @@ class RDoc::CrossReference
116
132
  end
117
133
 
118
134
  ##
119
- # Returns a reference to +name+.
120
- #
121
- # If the reference is found and +name+ is not documented +text+ will be
122
- # returned. If +name+ is escaped +name+ is returned. If +name+ is not
123
- # found +text+ is returned.
135
+ # Returns a method reference to +name+.
124
136
 
125
- def resolve name, text
126
- return @seen[name] if @seen.include? name
137
+ def resolve_method name
138
+ ref = nil
127
139
 
128
140
  if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
129
141
  type = $2
130
- type = '' if type == '.' # will find either #method or ::method
131
- method = "#{type}#{$3}"
142
+ if '.' == type # will find either #method or ::method
143
+ method = $3
144
+ else
145
+ method = "#{type}#{$3}"
146
+ end
132
147
  container = @context.find_symbol_module($1)
133
148
  elsif /^([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
134
149
  type = $1
135
- type = '' if type == '.'
136
- method = "#{type}#{$2}"
150
+ if '.' == type
151
+ method = $2
152
+ else
153
+ method = "#{type}#{$2}"
154
+ end
137
155
  container = @context
138
156
  else
157
+ type = nil
139
158
  container = nil
140
159
  end
141
160
 
142
161
  if container then
143
- ref = container.find_local_symbol method
144
-
145
- unless ref || RDoc::TopLevel === container then
146
- ref = container.find_ancestor_local_symbol method
162
+ unless RDoc::TopLevel === container then
163
+ if '.' == type then
164
+ if 'new' == method then # AnyClassName.new will be class method
165
+ ref = container.find_local_symbol method
166
+ ref = container.find_ancestor_local_symbol method unless ref
167
+ else
168
+ ref = container.find_local_symbol "::#{method}"
169
+ ref = container.find_ancestor_local_symbol "::#{method}" unless ref
170
+ ref = container.find_local_symbol "##{method}" unless ref
171
+ ref = container.find_ancestor_local_symbol "##{method}" unless ref
172
+ end
173
+ else
174
+ ref = container.find_local_symbol method
175
+ ref = container.find_ancestor_local_symbol method unless ref
176
+ end
147
177
  end
148
178
  end
149
179
 
180
+ ref
181
+ end
182
+
183
+ ##
184
+ # Returns a reference to +name+.
185
+ #
186
+ # If the reference is found and +name+ is not documented +text+ will be
187
+ # returned. If +name+ is escaped +name+ is returned. If +name+ is not
188
+ # found +text+ is returned.
189
+
190
+ def resolve name, text
191
+ return @seen[name] if @seen.include? name
192
+
150
193
  ref = case name
151
194
  when /^\\(#{CLASS_REGEXP_STR})$/o then
152
195
  @context.find_symbol $1
153
196
  else
154
197
  @context.find_symbol name
155
- end unless ref
198
+ end
199
+
200
+ ref = resolve_method name unless ref
156
201
 
157
202
  # Try a page name
158
- ref = @store.page name if not ref and name =~ /^\w+$/
203
+ ref = @store.page name if not ref and name =~ /^[\w.]+$/
159
204
 
160
205
  ref = nil if RDoc::Alias === ref # external alias, can't link to it
161
206
 
@@ -181,4 +226,3 @@ class RDoc::CrossReference
181
226
  end
182
227
 
183
228
  end
184
-