rdoc 8.0.0 → 8.1.0

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -3
  3. data/RI.md +75 -75
  4. data/exe/rdoc +2 -2
  5. data/lib/rdoc/code_object/alias.rb +71 -69
  6. data/lib/rdoc/code_object/any_method.rb +305 -303
  7. data/lib/rdoc/code_object/attr.rb +150 -148
  8. data/lib/rdoc/code_object/class_module.rb +798 -792
  9. data/lib/rdoc/code_object/constant.rb +175 -173
  10. data/lib/rdoc/code_object/context/section.rb +142 -138
  11. data/lib/rdoc/code_object/context.rb +926 -958
  12. data/lib/rdoc/code_object/extend.rb +7 -5
  13. data/lib/rdoc/code_object/include.rb +7 -5
  14. data/lib/rdoc/code_object/method_attr.rb +326 -319
  15. data/lib/rdoc/code_object/mixin.rb +97 -95
  16. data/lib/rdoc/code_object/normal_class.rb +77 -78
  17. data/lib/rdoc/code_object/normal_module.rb +61 -59
  18. data/lib/rdoc/code_object/require.rb +23 -39
  19. data/lib/rdoc/code_object/single_class.rb +21 -19
  20. data/lib/rdoc/code_object/top_level.rb +212 -219
  21. data/lib/rdoc/code_object.rb +305 -303
  22. data/lib/rdoc/comment.rb +275 -273
  23. data/lib/rdoc/cross_reference.rb +192 -190
  24. data/lib/rdoc/encoding.rb +105 -103
  25. data/lib/rdoc/erb_partial.rb +13 -11
  26. data/lib/rdoc/erbio.rb +29 -27
  27. data/lib/rdoc/generator/aliki.rb +161 -153
  28. data/lib/rdoc/generator/darkfish.rb +645 -635
  29. data/lib/rdoc/generator/json_index.rb +233 -229
  30. data/lib/rdoc/generator/markup.rb +164 -146
  31. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  32. data/lib/rdoc/generator/pot/po.rb +52 -51
  33. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  34. data/lib/rdoc/generator/pot.rb +85 -81
  35. data/lib/rdoc/generator/ri.rb +23 -19
  36. data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
  37. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
  39. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  40. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  41. data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
  42. data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  44. data/lib/rdoc/generator.rb +48 -46
  45. data/lib/rdoc/i18n/locale.rb +99 -95
  46. data/lib/rdoc/i18n/text.rb +109 -105
  47. data/lib/rdoc/i18n.rb +7 -5
  48. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  49. data/lib/rdoc/markdown.kpeg +15 -11
  50. data/lib/rdoc/markdown.rb +40 -47
  51. data/lib/rdoc/markup/block_quote.rb +12 -8
  52. data/lib/rdoc/markup/document.rb +127 -123
  53. data/lib/rdoc/markup/formatter.rb +219 -215
  54. data/lib/rdoc/markup/include.rb +33 -29
  55. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  56. data/lib/rdoc/markup/inline_parser.rb +281 -277
  57. data/lib/rdoc/markup/list.rb +80 -88
  58. data/lib/rdoc/markup/list_item.rb +73 -85
  59. data/lib/rdoc/markup/paragraph.rb +23 -19
  60. data/lib/rdoc/markup/parser.rb +501 -497
  61. data/lib/rdoc/markup/pre_process.rb +283 -279
  62. data/lib/rdoc/markup/raw.rb +2 -2
  63. data/lib/rdoc/markup/rule.rb +16 -12
  64. data/lib/rdoc/markup/to_ansi.rb +143 -139
  65. data/lib/rdoc/markup/to_bs.rb +72 -68
  66. data/lib/rdoc/markup/to_html.rb +594 -565
  67. data/lib/rdoc/markup/to_html_crossref.rb +234 -230
  68. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  69. data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
  70. data/lib/rdoc/markup/to_label.rb +63 -59
  71. data/lib/rdoc/markup/to_markdown.rb +212 -208
  72. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  73. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  74. data/lib/rdoc/markup/to_test.rb +60 -56
  75. data/lib/rdoc/markup/to_tt_only.rb +84 -80
  76. data/lib/rdoc/markup/verbatim.rb +62 -58
  77. data/lib/rdoc/markup.rb +198 -196
  78. data/lib/rdoc/options.rb +1063 -1061
  79. data/lib/rdoc/parser/c.rb +1039 -1037
  80. data/lib/rdoc/parser/changelog.rb +319 -315
  81. data/lib/rdoc/parser/markdown.rb +17 -13
  82. data/lib/rdoc/parser/rbs.rb +239 -235
  83. data/lib/rdoc/parser/rd.rb +17 -13
  84. data/lib/rdoc/parser/ruby.rb +1245 -1124
  85. data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
  86. data/lib/rdoc/parser/simple.rb +31 -27
  87. data/lib/rdoc/parser/text.rb +12 -8
  88. data/lib/rdoc/parser.rb +228 -220
  89. data/lib/rdoc/rbs_helper.rb +1 -1
  90. data/lib/rdoc/rd/inline.rb +57 -53
  91. data/lib/rdoc/rd.rb +90 -88
  92. data/lib/rdoc/rdoc.rb +500 -491
  93. data/lib/rdoc/ri/driver.rb +1140 -1135
  94. data/lib/rdoc/ri/formatter.rb +7 -3
  95. data/lib/rdoc/ri/paths.rb +140 -136
  96. data/lib/rdoc/ri/servlet.rb +354 -350
  97. data/lib/rdoc/ri/store.rb +4 -2
  98. data/lib/rdoc/ri/task.rb +55 -51
  99. data/lib/rdoc/ri.rb +14 -12
  100. data/lib/rdoc/rubygems_hook.rb +183 -181
  101. data/lib/rdoc/server.rb +349 -347
  102. data/lib/rdoc/stats/normal.rb +46 -42
  103. data/lib/rdoc/stats/quiet.rb +39 -35
  104. data/lib/rdoc/stats/verbose.rb +35 -31
  105. data/lib/rdoc/stats.rb +365 -363
  106. data/lib/rdoc/store.rb +888 -902
  107. data/lib/rdoc/task.rb +260 -256
  108. data/lib/rdoc/text.rb +135 -133
  109. data/lib/rdoc/token_stream.rb +101 -93
  110. data/lib/rdoc/tom_doc.rb +203 -201
  111. data/lib/rdoc/version.rb +1 -1
  112. metadata +4 -5
  113. data/lib/rdoc/markdown/literals.kpeg +0 -21
  114. data/lib/rdoc/markdown/literals.rb +0 -454
@@ -1,22 +1,26 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Parse a Markdown format file. The parsed RDoc::Markup::Document is attached
4
- # as a file comment.
2
+ module RDoc
3
+ class Parser
4
+ ##
5
+ # Parse a Markdown format file. The parsed RDoc::Markup::Document is attached
6
+ # as a file comment.
5
7
 
6
- class RDoc::Parser::Markdown < RDoc::Parser
8
+ class Markdown < Parser
7
9
 
8
- include RDoc::Parser::Text
10
+ include Parser::Text
9
11
 
10
- parse_files_matching(/\.(md|markdown)(?:\.[^.]+)?$/)
12
+ parse_files_matching(/\.(md|markdown)(?:\.[^.]+)?$/)
11
13
 
12
- ##
13
- # Creates an Markdown-format TopLevel for the given file.
14
+ ##
15
+ # Creates an Markdown-format TopLevel for the given file.
14
16
 
15
- def scan
16
- comment = RDoc::Comment.new @content, @top_level
17
- comment.format = 'markdown'
17
+ def scan
18
+ comment = Comment.new @content, @top_level
19
+ comment.format = 'markdown'
18
20
 
19
- @top_level.comment = comment
20
- end
21
+ @top_level.comment = comment
22
+ end
21
23
 
24
+ end
25
+ end
22
26
  end
@@ -2,274 +2,278 @@
2
2
 
3
3
  require 'rbs'
4
4
 
5
- ##
6
- # Parse RBS signature files as first-class RDoc input.
7
-
8
- class RDoc::Parser::RBS < RDoc::Parser
9
- RBS_FILE_EXTENSION = /\.rbs$/
10
-
11
- parse_files_matching RBS_FILE_EXTENSION
12
-
13
- def scan
14
- _, _, decls = ::RBS::Parser.parse_signature(@content)
15
- decls.each do |decl|
16
- parse_decl decl, @top_level
17
- end
18
- @top_level
19
- end
20
-
21
- private
22
-
23
- def record_object_location(object, location)
24
- object.line = location.start_line if location
25
-
26
- if RDoc::ClassModule === object
27
- @top_level.add_to_classes_or_modules object unless
28
- @top_level.classes_or_modules.include? object
29
- end
5
+ module RDoc
6
+ class Parser
7
+ ##
8
+ # Parse RBS signature files as first-class RDoc input.
9
+
10
+ class RBS < Parser
11
+ RBS_FILE_EXTENSION = /\.rbs$/
12
+
13
+ parse_files_matching RBS_FILE_EXTENSION
14
+
15
+ def scan
16
+ _, _, decls = ::RBS::Parser.parse_signature(@content)
17
+ decls.each do |decl|
18
+ parse_decl decl, @top_level
19
+ end
20
+ @top_level
21
+ end
30
22
 
31
- object.record_location @top_level
32
- object
33
- end
23
+ private
34
24
 
35
- def rdoc_comment_for(decl)
36
- rbs_comment = decl.comment if decl.respond_to?(:comment)
37
- return unless rbs_comment
25
+ def record_object_location(object, location)
26
+ object.line = location.start_line if location
38
27
 
39
- # TODO: Run RBS comments through RDoc's directive preprocessor so
40
- # directives like :nodoc: affect the documented object.
41
- comment = RDoc::Comment.new rbs_comment.string, @top_level
42
- comment.format = 'markdown'
43
- comment
44
- end
28
+ if ClassModule === object
29
+ @top_level.add_to_classes_or_modules object unless
30
+ @top_level.classes_or_modules.include? object
31
+ end
45
32
 
46
- def local_module_name(type_name, context)
47
- name = type_name.to_s
48
- return name if name.start_with?('::')
33
+ object.record_location @top_level
34
+ object
35
+ end
49
36
 
50
- namespace_names = context == @top_level ? [] : context.full_name.split('::')
37
+ def rdoc_comment_for(decl)
38
+ rbs_comment = decl.comment if decl.respond_to?(:comment)
39
+ return unless rbs_comment
51
40
 
52
- namespace_names.length.downto(1) do |length|
53
- qualified_name = namespace_names.take(length).join('::')
54
- if module_name = @top_level.find_module_named("#{qualified_name}::#{name}")
55
- return module_name.full_name
41
+ # TODO: Run RBS comments through RDoc's directive preprocessor so
42
+ # directives like :nodoc: affect the documented object.
43
+ comment = Comment.new rbs_comment.string, @top_level
44
+ comment.format = 'markdown'
45
+ comment
56
46
  end
57
- end
58
47
 
59
- name
60
- end
48
+ def local_module_name(type_name, context)
49
+ name = type_name.to_s
50
+ return name if name.start_with?('::')
61
51
 
62
- def merge_documentation(object, comment, type_signature_lines)
63
- if comment
64
- object.comment = if object.comment.empty?
65
- comment
66
- else
67
- merge_comments object, comment
68
- end
69
- end
52
+ namespace_names = context == @top_level ? [] : context.full_name.split('::')
70
53
 
71
- # TODO: Track RBS-owned documentation overlays so incremental reparsing can
72
- # replace stale comments and signatures from the previous RBS parse.
73
- object.type_signature_lines ||= type_signature_lines
74
- end
75
-
76
- def merge_comments(object, comment)
77
- document = RDoc::Markup::Document.new
78
- document.concat object.parse(object.comment).parts
79
- document << RDoc::Markup::Rule.new(1)
80
- document.concat comment.parse.parts
81
-
82
- # Keep this text separator in sync with the Rule node above.
83
- merged_comment = RDoc::Comment.new "#{object.comment}\n---\n#{comment}", comment.location
84
- merged_comment.format = 'markdown'
85
- merged_comment.document = document
86
- merged_comment
87
- end
54
+ namespace_names.length.downto(1) do |length|
55
+ qualified_name = namespace_names.take(length).join('::')
56
+ if module_name = @top_level.find_module_named("#{qualified_name}::#{name}")
57
+ return module_name.full_name
58
+ end
59
+ end
88
60
 
89
- def attr_rw_matches?(existing_rw, new_rw)
90
- existing_rw.each_char.any? { |rw| new_rw.include? rw }
91
- end
61
+ name
62
+ end
92
63
 
93
- def merge_attribute_methods(context, name, rw, singleton, comment, type_signature_lines)
94
- method_names = []
95
- method_names << name if rw.include?('R')
96
- method_names << "#{name}=" if rw.include?('W')
64
+ def merge_documentation(object, comment, type_signature_lines)
65
+ if comment
66
+ object.comment = if object.comment.empty?
67
+ comment
68
+ else
69
+ merge_comments object, comment
70
+ end
71
+ end
72
+
73
+ # TODO: Track RBS-owned documentation overlays so incremental reparsing can
74
+ # replace stale comments and signatures from the previous RBS parse.
75
+ object.type_signature_lines ||= type_signature_lines
76
+ end
97
77
 
98
- methods = method_names.map { |method_name| context.find_method(method_name, singleton) }
99
- methods.compact.each do |method|
100
- merge_documentation method, comment, type_signature_lines
101
- end
78
+ def merge_comments(object, comment)
79
+ document = Markup::Document.new
80
+ document.concat object.parse(object.comment).parts
81
+ document << Markup::Rule.new(1)
82
+ document.concat comment.parse.parts
83
+
84
+ # Keep this text separator in sync with the Rule node above.
85
+ merged_comment = Comment.new "#{object.comment}\n---\n#{comment}", comment.location
86
+ merged_comment.format = 'markdown'
87
+ merged_comment.document = document
88
+ merged_comment
89
+ end
102
90
 
103
- methods.any?
104
- end
91
+ def attr_rw_matches?(existing_rw, new_rw)
92
+ existing_rw.each_char.any? { |rw| new_rw.include? rw }
93
+ end
105
94
 
106
- def rdoc_method_name(decl)
107
- rbs_constructor_decl?(decl) ? 'new' : decl.name.to_s
108
- end
95
+ def merge_attribute_methods(context, name, rw, singleton, comment, type_signature_lines)
96
+ method_names = []
97
+ method_names << name if rw.include?('R')
98
+ method_names << "#{name}=" if rw.include?('W')
109
99
 
110
- def rdoc_method_singleton?(decl)
111
- # TODO: RBS `self?` methods are :singleton_instance and should add both a
112
- # singleton method and a private instance method.
113
- rbs_constructor_decl?(decl) || decl.singleton?
114
- end
100
+ methods = method_names.map { |method_name| context.find_method(method_name, singleton) }
101
+ methods.compact.each do |method|
102
+ merge_documentation method, comment, type_signature_lines
103
+ end
115
104
 
116
- def rdoc_method_visibility(decl)
117
- rbs_constructor_decl?(decl) ? :public : decl.visibility
118
- end
105
+ methods.any?
106
+ end
119
107
 
120
- def rbs_constructor_decl?(decl)
121
- decl.kind == :instance && decl.name == :initialize
122
- end
108
+ def rdoc_method_name(decl)
109
+ rbs_constructor_decl?(decl) ? 'new' : decl.name.to_s
110
+ end
123
111
 
124
- def parse_attr_decl(decl, context)
125
- rw = case decl
126
- when ::RBS::AST::Members::AttrReader
127
- 'R'
128
- when ::RBS::AST::Members::AttrWriter
129
- 'W'
130
- when ::RBS::AST::Members::AttrAccessor
131
- 'RW'
132
- end
133
-
134
- comment = rdoc_comment_for decl
135
- type_signature_lines = [decl.type.to_s]
136
- name = decl.name.to_s
137
- singleton = decl.kind == :singleton
138
- if attribute = context.find_attribute(name, singleton)
139
- merge_documentation attribute, comment, type_signature_lines if
140
- attr_rw_matches? attribute.rw, rw
141
- return
142
- end
112
+ def rdoc_method_singleton?(decl)
113
+ # TODO: RBS `self?` methods are :singleton_instance and should add both a
114
+ # singleton method and a private instance method.
115
+ rbs_constructor_decl?(decl) || decl.singleton?
116
+ end
143
117
 
144
- if merge_attribute_methods(context, name, rw, singleton, comment, type_signature_lines)
145
- return
146
- end
118
+ def rdoc_method_visibility(decl)
119
+ rbs_constructor_decl?(decl) ? :public : decl.visibility
120
+ end
147
121
 
148
- attribute = RDoc::Attr.new(
149
- name,
150
- rw,
151
- comment,
152
- singleton: singleton
153
- )
154
- record_object_location attribute, decl.location
155
- attribute.type_signature_lines = type_signature_lines
156
- context.add_attribute attribute
157
- attribute.visibility = decl.visibility if decl.visibility
158
- end
122
+ def rbs_constructor_decl?(decl)
123
+ decl.kind == :instance && decl.name == :initialize
124
+ end
159
125
 
160
- def parse_class_decl(decl, context)
161
- owner, name = context.find_or_create_constant_owner_for_path decl.name
162
- superclass = decl.super_class&.name&.to_s || '::Object'
163
- klass = owner.add_class RDoc::NormalClass, name, superclass
164
- record_object_location klass, decl.location
165
- comment = rdoc_comment_for decl
166
- klass.add_comment comment, @top_level if comment
126
+ def parse_attr_decl(decl, context)
127
+ rw = case decl
128
+ when ::RBS::AST::Members::AttrReader
129
+ 'R'
130
+ when ::RBS::AST::Members::AttrWriter
131
+ 'W'
132
+ when ::RBS::AST::Members::AttrAccessor
133
+ 'RW'
134
+ end
135
+
136
+ comment = rdoc_comment_for decl
137
+ type_signature_lines = [decl.type.to_s]
138
+ name = decl.name.to_s
139
+ singleton = decl.kind == :singleton
140
+ if attribute = context.find_attribute(name, singleton)
141
+ merge_documentation attribute, comment, type_signature_lines if
142
+ attr_rw_matches? attribute.rw, rw
143
+ return
144
+ end
145
+
146
+ if merge_attribute_methods(context, name, rw, singleton, comment, type_signature_lines)
147
+ return
148
+ end
149
+
150
+ attribute = Attr.new(
151
+ name,
152
+ rw,
153
+ comment,
154
+ singleton: singleton
155
+ )
156
+ record_object_location attribute, decl.location
157
+ attribute.type_signature_lines = type_signature_lines
158
+ attribute.visibility = decl.visibility if decl.visibility
159
+ context.add_attribute attribute
160
+ end
167
161
 
168
- decl.members.each { |member| parse_decl member, klass }
169
- end
162
+ def parse_class_decl(decl, context)
163
+ owner, name = context.find_or_create_constant_owner_for_path decl.name
164
+ superclass = decl.super_class&.name&.to_s || '::Object'
165
+ klass = owner.add_class NormalClass, name, superclass
166
+ record_object_location klass, decl.location
167
+ comment = rdoc_comment_for decl
168
+ klass.add_comment comment, @top_level if comment
170
169
 
171
- def parse_constant_decl(decl, context)
172
- constant = RDoc::Constant.new decl.name.to_s, decl.type.to_s,
173
- rdoc_comment_for(decl)
174
- record_object_location constant, decl.location
175
- context.add_constant constant
176
- end
170
+ decl.members.each { |member| parse_decl member, klass }
171
+ end
177
172
 
178
- def parse_decl(decl, context)
179
- case decl
180
- when ::RBS::AST::Declarations::Class
181
- parse_class_decl decl, context
182
- when ::RBS::AST::Declarations::Module, ::RBS::AST::Declarations::Interface
183
- parse_module_decl decl, context
184
- when ::RBS::AST::Declarations::ClassAlias,
185
- ::RBS::AST::Declarations::ModuleAlias
186
- # TODO: Add RBS class and module aliases to the RDoc store.
187
- nil
188
- else
189
- parse_member_decl decl, context
190
- end
191
- end
173
+ def parse_constant_decl(decl, context)
174
+ constant = Constant.new decl.name.to_s, decl.type.to_s,
175
+ rdoc_comment_for(decl)
176
+ record_object_location constant, decl.location
177
+ context.add_constant constant
178
+ end
192
179
 
193
- def parse_extend_decl(decl, context)
194
- extend_decl = RDoc::Extend.new local_module_name(decl.name, context),
195
- rdoc_comment_for(decl)
196
- record_object_location extend_decl, decl.location
197
- context.add_extend extend_decl
198
- end
180
+ def parse_decl(decl, context)
181
+ case decl
182
+ when ::RBS::AST::Declarations::Class
183
+ parse_class_decl decl, context
184
+ when ::RBS::AST::Declarations::Module, ::RBS::AST::Declarations::Interface
185
+ parse_module_decl decl, context
186
+ when ::RBS::AST::Declarations::ClassAlias,
187
+ ::RBS::AST::Declarations::ModuleAlias
188
+ # TODO: Add RBS class and module aliases to the RDoc store.
189
+ nil
190
+ else
191
+ parse_member_decl decl, context
192
+ end
193
+ end
199
194
 
200
- def parse_include_decl(decl, context)
201
- include_decl = RDoc::Include.new local_module_name(decl.name, context),
202
- rdoc_comment_for(decl)
203
- record_object_location include_decl, decl.location
204
- context.add_include include_decl
205
- end
195
+ def parse_extend_decl(decl, context)
196
+ extend_decl = Extend.new local_module_name(decl.name, context),
197
+ rdoc_comment_for(decl)
198
+ record_object_location extend_decl, decl.location
199
+ context.add_extend extend_decl
200
+ end
206
201
 
207
- def parse_member_decl(decl, context)
208
- case decl
209
- when ::RBS::AST::Declarations::Constant
210
- parse_constant_decl decl, context
211
- when ::RBS::AST::Members::MethodDefinition
212
- parse_method_decl decl, context
213
- when ::RBS::AST::Members::Alias
214
- parse_method_alias_decl decl, context
215
- when ::RBS::AST::Members::AttrReader,
216
- ::RBS::AST::Members::AttrWriter,
217
- ::RBS::AST::Members::AttrAccessor
218
- parse_attr_decl decl, context
219
- when ::RBS::AST::Members::Include
220
- parse_include_decl decl, context
221
- when ::RBS::AST::Members::Extend
222
- parse_extend_decl decl, context
223
- when ::RBS::AST::Members::Private,
224
- ::RBS::AST::Members::Public
225
- # TODO: Track standalone RBS visibility members.
226
- nil
227
- end
228
- end
202
+ def parse_include_decl(decl, context)
203
+ include_decl = Include.new local_module_name(decl.name, context),
204
+ rdoc_comment_for(decl)
205
+ record_object_location include_decl, decl.location
206
+ context.add_include include_decl
207
+ end
229
208
 
230
- def parse_method_alias_decl(decl, context)
231
- alias_def = RDoc::Alias.new(
232
- decl.old_name.to_s,
233
- decl.new_name.to_s,
234
- rdoc_comment_for(decl),
235
- singleton: decl.kind == :singleton
236
- )
237
- record_object_location alias_def, decl.location
238
- context.add_alias alias_def
239
- end
209
+ def parse_member_decl(decl, context)
210
+ case decl
211
+ when ::RBS::AST::Declarations::Constant
212
+ parse_constant_decl decl, context
213
+ when ::RBS::AST::Members::MethodDefinition
214
+ parse_method_decl decl, context
215
+ when ::RBS::AST::Members::Alias
216
+ parse_method_alias_decl decl, context
217
+ when ::RBS::AST::Members::AttrReader,
218
+ ::RBS::AST::Members::AttrWriter,
219
+ ::RBS::AST::Members::AttrAccessor
220
+ parse_attr_decl decl, context
221
+ when ::RBS::AST::Members::Include
222
+ parse_include_decl decl, context
223
+ when ::RBS::AST::Members::Extend
224
+ parse_extend_decl decl, context
225
+ when ::RBS::AST::Members::Private,
226
+ ::RBS::AST::Members::Public
227
+ # TODO: Track standalone RBS visibility members.
228
+ nil
229
+ end
230
+ end
240
231
 
241
- def parse_method_decl(decl, context)
242
- comment = rdoc_comment_for decl
243
- type_signature_lines = decl.overloads.map { |overload| overload.method_type.to_s }
244
- method_name = rdoc_method_name(decl)
245
- singleton = rdoc_method_singleton?(decl)
246
- visibility = rdoc_method_visibility(decl)
232
+ def parse_method_alias_decl(decl, context)
233
+ alias_def = Alias.new(
234
+ decl.old_name.to_s,
235
+ decl.new_name.to_s,
236
+ rdoc_comment_for(decl),
237
+ singleton: decl.kind == :singleton
238
+ )
239
+ record_object_location alias_def, decl.location
240
+ context.add_alias alias_def
241
+ end
247
242
 
248
- if method = context.find_method(method_name, singleton)
249
- merge_documentation method, comment, type_signature_lines
250
- return
251
- end
243
+ def parse_method_decl(decl, context)
244
+ comment = rdoc_comment_for decl
245
+ type_signature_lines = decl.overloads.map { |overload| overload.method_type.to_s }
246
+ method_name = rdoc_method_name(decl)
247
+ singleton = rdoc_method_singleton?(decl)
248
+ visibility = rdoc_method_visibility(decl)
249
+
250
+ if method = context.find_method(method_name, singleton)
251
+ merge_documentation method, comment, type_signature_lines
252
+ return
253
+ end
254
+
255
+ method = AnyMethod.new method_name, singleton: singleton
256
+ record_object_location method, decl.location
257
+ method.type_signature_lines = type_signature_lines
258
+
259
+ if loc = decl.location
260
+ method.start_collecting_tokens :ruby
261
+ method.add_token line_no: loc.start_line, char_no: 1, text: loc.source
262
+ end
263
+
264
+ method.comment = comment if comment
265
+ method.visibility = visibility if visibility
266
+ context.add_method method
267
+ end
252
268
 
253
- method = RDoc::AnyMethod.new method_name, singleton: singleton
254
- record_object_location method, decl.location
255
- method.type_signature_lines = type_signature_lines
269
+ def parse_module_decl(decl, context)
270
+ mod = context.add_module NormalModule, decl.name.to_s
271
+ record_object_location mod, decl.location
272
+ comment = rdoc_comment_for decl
273
+ mod.add_comment comment, @top_level if comment
256
274
 
257
- if loc = decl.location
258
- method.start_collecting_tokens :ruby
259
- method.add_token line_no: loc.start_line, char_no: 1, text: loc.source
275
+ decl.members.each { |member| parse_decl member, mod }
276
+ end
260
277
  end
261
-
262
- method.comment = comment if comment
263
- context.add_method method
264
- method.visibility = visibility if visibility
265
- end
266
-
267
- def parse_module_decl(decl, context)
268
- mod = context.add_module RDoc::NormalModule, decl.name.to_s
269
- record_object_location mod, decl.location
270
- comment = rdoc_comment_for decl
271
- mod.add_comment comment, @top_level if comment
272
-
273
- decl.members.each { |member| parse_decl member, mod }
274
278
  end
275
279
  end
@@ -1,22 +1,26 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Parse a RD format file. The parsed RDoc::Markup::Document is attached as a
4
- # file comment.
2
+ module RDoc
3
+ class Parser
4
+ ##
5
+ # Parse a RD format file. The parsed RDoc::Markup::Document is attached as a
6
+ # file comment.
5
7
 
6
- class RDoc::Parser::RD < RDoc::Parser
8
+ class RD < Parser
7
9
 
8
- include RDoc::Parser::Text
10
+ include Parser::Text
9
11
 
10
- parse_files_matching(/\.rd(?:\.[^.]+)?$/)
12
+ parse_files_matching(/\.rd(?:\.[^.]+)?$/)
11
13
 
12
- ##
13
- # Creates an rd-format TopLevel for the given file.
14
+ ##
15
+ # Creates an rd-format TopLevel for the given file.
14
16
 
15
- def scan
16
- comment = RDoc::Comment.new @content, @top_level
17
- comment.format = 'rd'
17
+ def scan
18
+ comment = Comment.new @content, @top_level
19
+ comment.format = 'rd'
18
20
 
19
- @top_level.comment = comment
20
- end
21
+ @top_level.comment = comment
22
+ end
21
23
 
24
+ end
25
+ end
22
26
  end