rdoc 4.2.1 → 6.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CONTRIBUTING.rdoc +8 -7
- data/Gemfile +12 -0
- data/History.rdoc +48 -4
- data/LEGAL.rdoc +2 -2
- data/README.rdoc +5 -5
- data/Rakefile +73 -155
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/{bin → exe}/rdoc +0 -0
- data/{bin → exe}/ri +0 -0
- data/lib/rdoc/alias.rb +1 -0
- data/lib/rdoc/anon_class.rb +1 -0
- data/lib/rdoc/any_method.rb +59 -14
- data/lib/rdoc/attr.rb +1 -0
- data/lib/rdoc/class_module.rb +5 -2
- data/lib/rdoc/code_object.rb +3 -11
- data/lib/rdoc/code_objects.rb +1 -0
- data/lib/rdoc/comment.rb +32 -11
- data/lib/rdoc/constant.rb +3 -2
- data/lib/rdoc/context/section.rb +7 -13
- data/lib/rdoc/context.rb +78 -23
- data/lib/rdoc/cross_reference.rb +33 -14
- data/lib/rdoc/encoding.rb +92 -55
- data/lib/rdoc/erb_partial.rb +2 -1
- data/lib/rdoc/erbio.rb +8 -3
- data/lib/rdoc/extend.rb +1 -0
- data/lib/rdoc/generator/darkfish.rb +62 -32
- data/lib/rdoc/generator/json_index.rb +8 -5
- data/lib/rdoc/generator/markup.rb +3 -12
- data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
- data/lib/rdoc/generator/pot/po.rb +84 -0
- data/lib/rdoc/generator/pot/po_entry.rb +141 -0
- data/lib/rdoc/generator/pot.rb +4 -3
- data/lib/rdoc/generator/ri.rb +1 -0
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +11 -8
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +4 -4
- data/lib/rdoc/generator/template/darkfish/class.rhtml +45 -47
- data/lib/rdoc/generator/template/darkfish/css/fonts.css +6 -6
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +55 -6
- data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -4
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +23 -100
- data/lib/rdoc/generator/template/darkfish/js/search.js +32 -31
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +15 -16
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +16 -16
- data/lib/rdoc/generator/template/json_index/js/navigation.js +4 -41
- data/lib/rdoc/generator/template/json_index/js/searcher.js +7 -6
- data/lib/rdoc/generator.rb +1 -1
- data/lib/rdoc/ghost_method.rb +1 -0
- data/lib/rdoc/i18n/locale.rb +2 -1
- data/lib/rdoc/i18n/text.rb +5 -4
- data/lib/rdoc/i18n.rb +3 -2
- data/lib/rdoc/include.rb +1 -0
- data/lib/rdoc/known_classes.rb +1 -0
- data/lib/rdoc/markdown/entities.rb +1 -0
- data/lib/rdoc/markdown/{literals_1_9.kpeg → literals.kpeg} +1 -0
- data/lib/rdoc/markdown/{literals_1_9.rb → literals.rb} +1 -4
- data/lib/rdoc/markdown.kpeg +94 -51
- data/lib/rdoc/markdown.rb +1171 -619
- data/lib/rdoc/markup/attr_changer.rb +1 -0
- data/lib/rdoc/markup/attr_span.rb +9 -2
- data/lib/rdoc/markup/attribute_manager.rb +115 -49
- data/lib/rdoc/markup/attributes.rb +7 -6
- data/lib/rdoc/markup/blank_line.rb +1 -0
- data/lib/rdoc/markup/block_quote.rb +1 -0
- data/lib/rdoc/markup/document.rb +1 -0
- data/lib/rdoc/markup/formatter.rb +25 -23
- data/lib/rdoc/markup/hard_break.rb +1 -0
- data/lib/rdoc/markup/heading.rb +4 -3
- data/lib/rdoc/markup/include.rb +1 -0
- data/lib/rdoc/markup/indented_paragraph.rb +1 -0
- data/lib/rdoc/markup/list.rb +1 -0
- data/lib/rdoc/markup/list_item.rb +1 -0
- data/lib/rdoc/markup/paragraph.rb +1 -0
- data/lib/rdoc/markup/parser.rb +78 -61
- data/lib/rdoc/markup/pre_process.rb +12 -9
- data/lib/rdoc/markup/raw.rb +1 -0
- data/lib/rdoc/markup/regexp_handling.rb +41 -0
- data/lib/rdoc/markup/rule.rb +1 -0
- data/lib/rdoc/markup/to_ansi.rb +1 -0
- data/lib/rdoc/markup/to_bs.rb +4 -5
- data/lib/rdoc/markup/to_html.rb +71 -25
- data/lib/rdoc/markup/to_html_crossref.rb +41 -25
- data/lib/rdoc/markup/to_html_snippet.rb +10 -9
- data/lib/rdoc/markup/to_joined_paragraph.rb +7 -31
- data/lib/rdoc/markup/to_label.rb +10 -9
- data/lib/rdoc/markup/to_markdown.rb +9 -8
- data/lib/rdoc/markup/to_rdoc.rb +35 -6
- data/lib/rdoc/markup/to_table_of_contents.rb +2 -0
- data/lib/rdoc/markup/to_test.rb +1 -0
- data/lib/rdoc/markup/to_tt_only.rb +3 -2
- data/lib/rdoc/markup/verbatim.rb +1 -0
- data/lib/rdoc/markup.rb +14 -16
- data/lib/rdoc/meta_method.rb +1 -0
- data/lib/rdoc/method_attr.rb +2 -1
- data/lib/rdoc/mixin.rb +1 -0
- data/lib/rdoc/normal_class.rb +3 -2
- data/lib/rdoc/normal_module.rb +1 -0
- data/lib/rdoc/options.rb +92 -58
- data/lib/rdoc/parser/c.rb +219 -223
- data/lib/rdoc/parser/changelog.rb +155 -18
- data/lib/rdoc/parser/markdown.rb +1 -0
- data/lib/rdoc/parser/rd.rb +1 -0
- data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
- data/lib/rdoc/parser/ruby.rb +635 -468
- data/lib/rdoc/parser/ruby_tools.rb +33 -33
- data/lib/rdoc/parser/simple.rb +3 -3
- data/lib/rdoc/parser/text.rb +1 -0
- data/lib/rdoc/parser.rb +17 -50
- data/lib/rdoc/rd/block_parser.rb +66 -65
- data/lib/rdoc/rd/block_parser.ry +3 -3
- data/lib/rdoc/rd/inline.rb +5 -4
- data/lib/rdoc/rd/inline_parser.rb +52 -51
- data/lib/rdoc/rd/inline_parser.ry +1 -1
- data/lib/rdoc/rd.rb +1 -0
- data/lib/rdoc/rdoc.rb +68 -63
- data/lib/rdoc/require.rb +1 -0
- data/lib/rdoc/ri/driver.rb +133 -58
- data/lib/rdoc/ri/formatter.rb +1 -0
- data/lib/rdoc/ri/paths.rb +4 -20
- data/lib/rdoc/ri/store.rb +1 -0
- data/lib/rdoc/ri/task.rb +71 -0
- data/lib/rdoc/ri.rb +1 -0
- data/lib/rdoc/rubygems_hook.rb +5 -12
- data/lib/rdoc/servlet.rb +24 -14
- data/lib/rdoc/single_class.rb +1 -0
- data/lib/rdoc/stats/normal.rb +20 -21
- data/lib/rdoc/stats/quiet.rb +1 -0
- data/lib/rdoc/stats/verbose.rb +1 -0
- data/lib/rdoc/stats.rb +1 -0
- data/lib/rdoc/store.rb +41 -41
- data/lib/rdoc/task.rb +2 -3
- data/lib/rdoc/text.rb +19 -38
- data/lib/rdoc/token_stream.rb +56 -32
- data/lib/rdoc/tom_doc.rb +17 -11
- data/lib/rdoc/top_level.rb +9 -2
- data/lib/rdoc/version.rb +8 -0
- data/lib/rdoc.rb +24 -10
- data/man/ri.1 +247 -0
- data/rdoc.gemspec +248 -0
- metadata +43 -236
- data/.autotest +0 -24
- data/.document +0 -5
- data/Manifest.txt +0 -306
- data/lib/gauntlet_rdoc.rb +0 -84
- data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
- data/lib/rdoc/markdown/literals_1_8.kpeg +0 -18
- data/lib/rdoc/markdown/literals_1_8.rb +0 -416
- data/lib/rdoc/markup/formatter_test_case.rb +0 -767
- data/lib/rdoc/markup/inline.rb +0 -1
- data/lib/rdoc/markup/special.rb +0 -40
- data/lib/rdoc/markup/text_formatter_test_case.rb +0 -114
- data/lib/rdoc/ruby_lex.rb +0 -1377
- data/lib/rdoc/ruby_token.rb +0 -460
- data/lib/rdoc/test_case.rb +0 -217
- data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +0 -21
- data/test/MarkdownTest_1.0.3/Auto links.text +0 -13
- data/test/MarkdownTest_1.0.3/Backslash escapes.text +0 -120
- data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +0 -11
- data/test/MarkdownTest_1.0.3/Code Blocks.text +0 -14
- data/test/MarkdownTest_1.0.3/Code Spans.text +0 -6
- data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +0 -8
- data/test/MarkdownTest_1.0.3/Horizontal rules.text +0 -67
- data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +0 -15
- data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +0 -69
- data/test/MarkdownTest_1.0.3/Inline HTML comments.text +0 -13
- data/test/MarkdownTest_1.0.3/Links, inline style.text +0 -12
- data/test/MarkdownTest_1.0.3/Links, reference style.text +0 -71
- data/test/MarkdownTest_1.0.3/Links, shortcut references.text +0 -20
- data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +0 -7
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +0 -306
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +0 -888
- data/test/MarkdownTest_1.0.3/Nested blockquotes.text +0 -5
- data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +0 -131
- data/test/MarkdownTest_1.0.3/Strong and em together.text +0 -7
- data/test/MarkdownTest_1.0.3/Tabs.text +0 -21
- data/test/MarkdownTest_1.0.3/Tidyness.text +0 -5
- data/test/README +0 -1
- data/test/binary.dat +0 -0
- data/test/hidden.zip.txt +0 -1
- data/test/test.ja.largedoc +0 -3
- data/test/test.ja.rdoc +0 -10
- data/test/test.ja.txt +0 -8
- data/test/test.txt +0 -1
- data/test/test_rdoc_alias.rb +0 -13
- data/test/test_rdoc_any_method.rb +0 -460
- data/test/test_rdoc_attr.rb +0 -190
- data/test/test_rdoc_class_module.rb +0 -1492
- data/test/test_rdoc_code_object.rb +0 -450
- data/test/test_rdoc_comment.rb +0 -504
- data/test/test_rdoc_constant.rb +0 -181
- data/test/test_rdoc_context.rb +0 -901
- data/test/test_rdoc_context_section.rb +0 -130
- data/test/test_rdoc_cross_reference.rb +0 -192
- data/test/test_rdoc_encoding.rb +0 -227
- data/test/test_rdoc_extend.rb +0 -94
- data/test/test_rdoc_generator_darkfish.rb +0 -229
- data/test/test_rdoc_generator_json_index.rb +0 -324
- data/test/test_rdoc_generator_markup.rb +0 -59
- data/test/test_rdoc_generator_pot.rb +0 -91
- data/test/test_rdoc_generator_pot_po.rb +0 -51
- data/test/test_rdoc_generator_pot_po_entry.rb +0 -139
- data/test/test_rdoc_generator_ri.rb +0 -78
- data/test/test_rdoc_i18n_locale.rb +0 -73
- data/test/test_rdoc_i18n_text.rb +0 -123
- data/test/test_rdoc_include.rb +0 -108
- data/test/test_rdoc_markdown.rb +0 -980
- data/test/test_rdoc_markdown_test.rb +0 -1884
- data/test/test_rdoc_markup.rb +0 -95
- data/test/test_rdoc_markup_attribute_manager.rb +0 -364
- data/test/test_rdoc_markup_attributes.rb +0 -39
- data/test/test_rdoc_markup_document.rb +0 -207
- data/test/test_rdoc_markup_formatter.rb +0 -175
- data/test/test_rdoc_markup_hard_break.rb +0 -31
- data/test/test_rdoc_markup_heading.rb +0 -29
- data/test/test_rdoc_markup_include.rb +0 -19
- data/test/test_rdoc_markup_indented_paragraph.rb +0 -53
- data/test/test_rdoc_markup_paragraph.rb +0 -32
- data/test/test_rdoc_markup_parser.rb +0 -1680
- data/test/test_rdoc_markup_pre_process.rb +0 -473
- data/test/test_rdoc_markup_raw.rb +0 -22
- data/test/test_rdoc_markup_to_ansi.rb +0 -369
- data/test/test_rdoc_markup_to_bs.rb +0 -366
- data/test/test_rdoc_markup_to_html.rb +0 -662
- data/test/test_rdoc_markup_to_html_crossref.rb +0 -225
- data/test/test_rdoc_markup_to_html_snippet.rb +0 -711
- data/test/test_rdoc_markup_to_joined_paragraph.rb +0 -32
- data/test/test_rdoc_markup_to_label.rb +0 -112
- data/test/test_rdoc_markup_to_markdown.rb +0 -389
- data/test/test_rdoc_markup_to_rdoc.rb +0 -377
- data/test/test_rdoc_markup_to_table_of_contents.rb +0 -126
- data/test/test_rdoc_markup_to_tt_only.rb +0 -246
- data/test/test_rdoc_markup_verbatim.rb +0 -29
- data/test/test_rdoc_method_attr.rb +0 -193
- data/test/test_rdoc_normal_class.rb +0 -47
- data/test/test_rdoc_normal_module.rb +0 -42
- data/test/test_rdoc_options.rb +0 -766
- data/test/test_rdoc_parser.rb +0 -327
- data/test/test_rdoc_parser_c.rb +0 -1896
- data/test/test_rdoc_parser_changelog.rb +0 -315
- data/test/test_rdoc_parser_markdown.rb +0 -61
- data/test/test_rdoc_parser_rd.rb +0 -55
- data/test/test_rdoc_parser_ruby.rb +0 -3322
- data/test/test_rdoc_parser_simple.rb +0 -115
- data/test/test_rdoc_rd.rb +0 -30
- data/test/test_rdoc_rd_block_parser.rb +0 -535
- data/test/test_rdoc_rd_inline.rb +0 -63
- data/test/test_rdoc_rd_inline_parser.rb +0 -177
- data/test/test_rdoc_rdoc.rb +0 -455
- data/test/test_rdoc_require.rb +0 -25
- data/test/test_rdoc_ri_driver.rb +0 -1436
- data/test/test_rdoc_ri_paths.rb +0 -155
- data/test/test_rdoc_ruby_lex.rb +0 -421
- data/test/test_rdoc_ruby_token.rb +0 -19
- data/test/test_rdoc_rubygems_hook.rb +0 -251
- data/test/test_rdoc_servlet.rb +0 -534
- data/test/test_rdoc_single_class.rb +0 -20
- data/test/test_rdoc_stats.rb +0 -722
- data/test/test_rdoc_store.rb +0 -993
- data/test/test_rdoc_task.rb +0 -173
- data/test/test_rdoc_text.rb +0 -557
- data/test/test_rdoc_token_stream.rb +0 -42
- data/test/test_rdoc_tom_doc.rb +0 -520
- data/test/test_rdoc_top_level.rb +0 -287
- data/test/xref_data.rb +0 -76
- data/test/xref_test_case.rb +0 -67
data/lib/rdoc/parser/ruby.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
##
|
2
3
|
# This file contains stuff stolen outright from:
|
3
4
|
#
|
@@ -7,8 +8,6 @@
|
|
7
8
|
# by Keiju ISHITSUKA (Nippon Rational Inc.)
|
8
9
|
#
|
9
10
|
|
10
|
-
$TOKEN_DEBUG ||= nil
|
11
|
-
|
12
11
|
##
|
13
12
|
# Extracts code elements from a source file returning a TopLevel object
|
14
13
|
# containing the constituent file elements.
|
@@ -23,6 +22,7 @@ $TOKEN_DEBUG ||= nil
|
|
23
22
|
# * aliases
|
24
23
|
# * private, public, protected
|
25
24
|
# * private_class_function, public_class_function
|
25
|
+
# * private_constant, public_constant
|
26
26
|
# * module_function
|
27
27
|
# * attr, attr_reader, attr_writer, attr_accessor
|
28
28
|
# * extra accessors given on the command line
|
@@ -138,11 +138,13 @@ $TOKEN_DEBUG ||= nil
|
|
138
138
|
# Note that by default, the :method: directive will be ignored if there is a
|
139
139
|
# standard rdocable item following it.
|
140
140
|
|
141
|
+
require 'ripper'
|
142
|
+
require_relative 'ripper_state_lex'
|
143
|
+
|
141
144
|
class RDoc::Parser::Ruby < RDoc::Parser
|
142
145
|
|
143
146
|
parse_files_matching(/\.rbw?$/)
|
144
147
|
|
145
|
-
include RDoc::RubyToken
|
146
148
|
include RDoc::TokenStream
|
147
149
|
include RDoc::Parser::RubyTools
|
148
150
|
|
@@ -162,20 +164,34 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
162
164
|
def initialize(top_level, file_name, content, options, stats)
|
163
165
|
super
|
164
166
|
|
167
|
+
if /\t/ =~ content then
|
168
|
+
tab_width = @options.tab_width
|
169
|
+
content = content.split(/\n/).map do |line|
|
170
|
+
1 while line.gsub!(/\t+/) {
|
171
|
+
' ' * (tab_width*$&.length - $`.length % tab_width)
|
172
|
+
} && $~
|
173
|
+
line
|
174
|
+
end.join("\n")
|
175
|
+
end
|
176
|
+
|
165
177
|
@size = 0
|
166
178
|
@token_listeners = nil
|
167
|
-
|
168
|
-
@scanner
|
179
|
+
content = RDoc::Encoding.remove_magic_comment content
|
180
|
+
@scanner = RDoc::Parser::RipperStateLex.parse(content)
|
181
|
+
@content = content
|
182
|
+
@scanner_point = 0
|
169
183
|
@prev_seek = nil
|
170
184
|
@markup = @options.markup
|
171
185
|
@track_visibility = :nodoc != @options.visibility
|
172
|
-
|
173
|
-
@encoding = nil
|
174
|
-
@encoding = @options.encoding if Object.const_defined? :Encoding
|
186
|
+
@encoding = @options.encoding
|
175
187
|
|
176
188
|
reset
|
177
189
|
end
|
178
190
|
|
191
|
+
def tk_nl?(tk)
|
192
|
+
:on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]
|
193
|
+
end
|
194
|
+
|
179
195
|
##
|
180
196
|
# Retrieves the read token stream and replaces +pattern+ with +replacement+
|
181
197
|
# using gsub. If the result is only a ";" returns an empty string.
|
@@ -195,7 +211,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
195
211
|
# methods.
|
196
212
|
|
197
213
|
def get_visibility_information tk, single # :nodoc:
|
198
|
-
vis_type = tk
|
214
|
+
vis_type = tk[:text]
|
199
215
|
singleton = single == SINGLE
|
200
216
|
|
201
217
|
vis =
|
@@ -224,31 +240,34 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
224
240
|
|
225
241
|
def collect_first_comment
|
226
242
|
skip_tkspace
|
227
|
-
comment = ''
|
228
|
-
comment.
|
243
|
+
comment = ''.dup
|
244
|
+
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
229
245
|
first_line = true
|
230
|
-
|
246
|
+
first_comment_tk_kind = nil
|
247
|
+
line_no = nil
|
231
248
|
|
232
249
|
tk = get_tk
|
233
250
|
|
234
|
-
while
|
235
|
-
|
251
|
+
while tk && (:on_comment == tk[:kind] or :on_embdoc == tk[:kind])
|
252
|
+
comment_body = retrieve_comment_body(tk)
|
253
|
+
if first_line and comment_body =~ /\A#!/ then
|
236
254
|
skip_tkspace
|
237
255
|
tk = get_tk
|
238
|
-
elsif first_line and
|
256
|
+
elsif first_line and comment_body =~ /\A#\s*-\*-/ then
|
239
257
|
first_line = false
|
240
258
|
skip_tkspace
|
241
259
|
tk = get_tk
|
242
260
|
else
|
243
|
-
break if
|
244
|
-
|
261
|
+
break if first_comment_tk_kind and not first_comment_tk_kind === tk[:kind]
|
262
|
+
first_comment_tk_kind = tk[:kind]
|
245
263
|
|
264
|
+
line_no = tk[:line_no] if first_line
|
246
265
|
first_line = false
|
247
|
-
comment <<
|
266
|
+
comment << comment_body
|
248
267
|
tk = get_tk
|
249
268
|
|
250
|
-
if
|
251
|
-
|
269
|
+
if :on_nl === tk then
|
270
|
+
skip_tkspace_without_nl
|
252
271
|
tk = get_tk
|
253
272
|
end
|
254
273
|
end
|
@@ -256,15 +275,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
256
275
|
|
257
276
|
unget_tk tk
|
258
277
|
|
259
|
-
new_comment comment
|
278
|
+
new_comment comment, line_no
|
260
279
|
end
|
261
280
|
|
262
281
|
##
|
263
282
|
# Consumes trailing whitespace from the token stream
|
264
283
|
|
265
284
|
def consume_trailing_spaces # :nodoc:
|
266
|
-
|
267
|
-
skip_tkspace false
|
285
|
+
skip_tkspace_without_nl
|
268
286
|
end
|
269
287
|
|
270
288
|
##
|
@@ -291,7 +309,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
291
309
|
container.find_module_named rhs_name
|
292
310
|
end
|
293
311
|
|
294
|
-
container.add_module_alias mod, constant
|
312
|
+
container.add_module_alias mod, rhs_name, constant, @top_level
|
295
313
|
end
|
296
314
|
|
297
315
|
##
|
@@ -304,16 +322,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
304
322
|
end
|
305
323
|
|
306
324
|
##
|
307
|
-
# Looks for a true or false token.
|
308
|
-
# found.
|
325
|
+
# Looks for a true or false token.
|
309
326
|
|
310
327
|
def get_bool
|
311
328
|
skip_tkspace
|
312
329
|
tk = get_tk
|
313
|
-
|
314
|
-
when TkTRUE
|
330
|
+
if :on_kw == tk[:kind] && 'true' == tk[:text]
|
315
331
|
true
|
316
|
-
|
332
|
+
elsif :on_kw == tk[:kind] && ('false' == tk[:text] || 'nil' == tk[:text])
|
317
333
|
false
|
318
334
|
else
|
319
335
|
unget_tk tk
|
@@ -329,27 +345,31 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
329
345
|
def get_class_or_module container, ignore_constants = false
|
330
346
|
skip_tkspace
|
331
347
|
name_t = get_tk
|
332
|
-
given_name = ''
|
348
|
+
given_name = ''.dup
|
333
349
|
|
334
350
|
# class ::A -> A is in the top level
|
335
|
-
|
336
|
-
when TkCOLON2, TkCOLON3 then # bug
|
351
|
+
if :on_op == name_t[:kind] and '::' == name_t[:text] then # bug
|
337
352
|
name_t = get_tk
|
338
353
|
container = @top_level
|
339
354
|
given_name << '::'
|
340
355
|
end
|
341
356
|
|
342
|
-
|
343
|
-
given_name << name_t
|
357
|
+
skip_tkspace_without_nl
|
358
|
+
given_name << name_t[:text]
|
344
359
|
|
345
|
-
|
360
|
+
is_self = name_t[:kind] == :on_op && name_t[:text] == '<<'
|
361
|
+
new_modules = []
|
362
|
+
while !is_self && (tk = peek_tk) and :on_op == tk[:kind] and '::' == tk[:text] do
|
346
363
|
prev_container = container
|
347
|
-
container = container.find_module_named name_t
|
364
|
+
container = container.find_module_named name_t[:text]
|
348
365
|
container ||=
|
349
366
|
if ignore_constants then
|
350
|
-
RDoc::
|
367
|
+
c = RDoc::NormalModule.new name_t[:text]
|
368
|
+
c.store = @store
|
369
|
+
new_modules << [prev_container, c]
|
370
|
+
c
|
351
371
|
else
|
352
|
-
c = prev_container.add_module RDoc::NormalModule, name_t
|
372
|
+
c = prev_container.add_module RDoc::NormalModule, name_t[:text]
|
353
373
|
c.ignore unless prev_container.document_children
|
354
374
|
@top_level.add_to_classes_or_modules c
|
355
375
|
c
|
@@ -358,35 +378,51 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
358
378
|
record_location container
|
359
379
|
|
360
380
|
get_tk
|
361
|
-
skip_tkspace
|
381
|
+
skip_tkspace
|
382
|
+
if :on_lparen == peek_tk[:kind] # ProcObjectInConstant::()
|
383
|
+
parse_method_or_yield_parameters
|
384
|
+
break
|
385
|
+
end
|
362
386
|
name_t = get_tk
|
363
|
-
|
387
|
+
unless :on_const == name_t[:kind] || :on_ident == name_t[:kind]
|
388
|
+
raise RDoc::Error, "Invalid class or module definition: #{given_name}"
|
389
|
+
end
|
390
|
+
if prev_container == container and !ignore_constants
|
391
|
+
given_name = name_t[:text]
|
392
|
+
else
|
393
|
+
given_name << '::' + name_t[:text]
|
394
|
+
end
|
364
395
|
end
|
365
396
|
|
366
|
-
|
397
|
+
skip_tkspace_without_nl
|
367
398
|
|
368
|
-
return [container, name_t, given_name]
|
399
|
+
return [container, name_t, given_name, new_modules]
|
369
400
|
end
|
370
401
|
|
371
402
|
##
|
372
403
|
# Return a superclass, which can be either a constant of an expression
|
373
404
|
|
374
405
|
def get_class_specification
|
375
|
-
|
376
|
-
|
377
|
-
|
406
|
+
tk = peek_tk
|
407
|
+
if tk.nil?
|
408
|
+
return ''
|
409
|
+
elsif :on_kw == tk[:kind] && 'self' == tk[:text]
|
410
|
+
return 'self'
|
411
|
+
elsif :on_gvar == tk[:kind]
|
412
|
+
return ''
|
378
413
|
end
|
379
414
|
|
380
415
|
res = get_constant
|
381
416
|
|
382
|
-
|
417
|
+
skip_tkspace_without_nl
|
383
418
|
|
384
419
|
get_tkread # empty out read buffer
|
385
420
|
|
386
421
|
tk = get_tk
|
422
|
+
return res unless tk
|
387
423
|
|
388
|
-
case tk
|
389
|
-
when
|
424
|
+
case tk[:kind]
|
425
|
+
when :on_nl, :on_comment, :on_embdoc, :on_semicolon then
|
390
426
|
unget_tk(tk)
|
391
427
|
return res
|
392
428
|
end
|
@@ -401,11 +437,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
401
437
|
|
402
438
|
def get_constant
|
403
439
|
res = ""
|
404
|
-
|
440
|
+
skip_tkspace_without_nl
|
405
441
|
tk = get_tk
|
406
442
|
|
407
|
-
while
|
408
|
-
res += tk
|
443
|
+
while tk && ((:on_op == tk[:kind] && '::' == tk[:text]) || :on_const == tk[:kind]) do
|
444
|
+
res += tk[:text]
|
409
445
|
tk = get_tk
|
410
446
|
end
|
411
447
|
|
@@ -414,28 +450,83 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
414
450
|
end
|
415
451
|
|
416
452
|
##
|
417
|
-
# Get
|
453
|
+
# Get an included module that may be surrounded by parens
|
418
454
|
|
419
|
-
def
|
420
|
-
|
455
|
+
def get_included_module_with_optional_parens
|
456
|
+
skip_tkspace_without_nl
|
457
|
+
get_tkread
|
458
|
+
tk = get_tk
|
459
|
+
end_token = get_end_token tk
|
460
|
+
return '' unless end_token
|
421
461
|
|
422
462
|
nest = 0
|
463
|
+
continue = false
|
464
|
+
only_constant = true
|
423
465
|
|
424
|
-
while
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
466
|
+
while tk != nil do
|
467
|
+
is_element_of_constant = false
|
468
|
+
case tk[:kind]
|
469
|
+
when :on_semicolon then
|
470
|
+
break if nest == 0
|
471
|
+
when :on_lbracket then
|
472
|
+
nest += 1
|
473
|
+
when :on_rbracket then
|
474
|
+
nest -= 1
|
475
|
+
when :on_lbrace then
|
476
|
+
nest += 1
|
477
|
+
when :on_rbrace then
|
478
|
+
nest -= 1
|
479
|
+
if nest <= 0
|
480
|
+
# we might have a.each { |i| yield i }
|
481
|
+
unget_tk(tk) if nest < 0
|
482
|
+
break
|
483
|
+
end
|
484
|
+
when :on_lparen then
|
485
|
+
nest += 1
|
486
|
+
when end_token[:kind] then
|
487
|
+
if end_token[:kind] == :on_rparen
|
488
|
+
nest -= 1
|
489
|
+
break if nest <= 0
|
490
|
+
else
|
491
|
+
break if nest <= 0
|
492
|
+
end
|
493
|
+
when :on_rparen then
|
494
|
+
nest -= 1
|
495
|
+
when :on_comment, :on_embdoc then
|
496
|
+
@read.pop
|
497
|
+
if :on_nl == end_token[:kind] and "\n" == tk[:text][-1] and
|
498
|
+
(!continue or (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0) then
|
499
|
+
break if !continue and nest <= 0
|
500
|
+
end
|
501
|
+
when :on_comma then
|
502
|
+
continue = true
|
503
|
+
when :on_ident then
|
504
|
+
continue = false if continue
|
505
|
+
when :on_kw then
|
506
|
+
case tk[:text]
|
507
|
+
when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
|
508
|
+
nest += 1
|
509
|
+
when 'if', 'unless', 'while', 'until', 'rescue'
|
510
|
+
# postfix if/unless/while/until/rescue must be EXPR_LABEL
|
511
|
+
nest += 1 unless (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0
|
512
|
+
when 'end'
|
513
|
+
nest -= 1
|
514
|
+
break if nest == 0
|
515
|
+
end
|
516
|
+
when :on_const then
|
517
|
+
is_element_of_constant = true
|
518
|
+
when :on_op then
|
519
|
+
is_element_of_constant = true if '::' == tk[:text]
|
520
|
+
end
|
521
|
+
only_constant = false unless is_element_of_constant
|
434
522
|
tk = get_tk
|
435
|
-
nest -= 1 if TkRPAREN === tk
|
436
523
|
end
|
437
524
|
|
438
|
-
|
525
|
+
if only_constant
|
526
|
+
get_tkread_clean(/\s+/, ' ')
|
527
|
+
else
|
528
|
+
''
|
529
|
+
end
|
439
530
|
end
|
440
531
|
|
441
532
|
##
|
@@ -447,13 +538,19 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
447
538
|
# won't catch all cases (such as "a = yield + 1"
|
448
539
|
|
449
540
|
def get_end_token tk # :nodoc:
|
450
|
-
case tk
|
451
|
-
when
|
452
|
-
|
453
|
-
|
541
|
+
case tk[:kind]
|
542
|
+
when :on_lparen
|
543
|
+
token = RDoc::Parser::RipperStateLex::Token.new
|
544
|
+
token[:kind] = :on_rparen
|
545
|
+
token[:text] = ')'
|
546
|
+
token
|
547
|
+
when :on_rparen
|
454
548
|
nil
|
455
549
|
else
|
456
|
-
|
550
|
+
token = RDoc::Parser::RipperStateLex::Token.new
|
551
|
+
token[:kind] = :on_nl
|
552
|
+
token[:text] = "\n"
|
553
|
+
token
|
457
554
|
end
|
458
555
|
end
|
459
556
|
|
@@ -462,11 +559,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
462
559
|
|
463
560
|
def get_method_container container, name_t # :nodoc:
|
464
561
|
prev_container = container
|
465
|
-
container = container.find_module_named(name_t
|
562
|
+
container = container.find_module_named(name_t[:text])
|
466
563
|
|
467
564
|
unless container then
|
468
565
|
constant = prev_container.constants.find do |const|
|
469
|
-
const.name == name_t
|
566
|
+
const.name == name_t[:text]
|
470
567
|
end
|
471
568
|
|
472
569
|
if constant then
|
@@ -477,21 +574,21 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
477
574
|
|
478
575
|
unless container then
|
479
576
|
# TODO seems broken, should starting at Object in @store
|
480
|
-
obj = name_t.
|
577
|
+
obj = name_t[:text].split("::").inject(Object) do |state, item|
|
481
578
|
state.const_get(item)
|
482
579
|
end rescue nil
|
483
580
|
|
484
581
|
type = obj.class == Class ? RDoc::NormalClass : RDoc::NormalModule
|
485
582
|
|
486
583
|
unless [Class, Module].include?(obj.class) then
|
487
|
-
warn("Couldn't find #{name_t
|
584
|
+
warn("Couldn't find #{name_t[:text]}. Assuming it's a module")
|
488
585
|
end
|
489
586
|
|
490
587
|
if type == RDoc::NormalClass then
|
491
588
|
sclass = obj.superclass ? obj.superclass.name : nil
|
492
|
-
container = prev_container.add_class type, name_t
|
589
|
+
container = prev_container.add_class type, name_t[:text], sclass
|
493
590
|
else
|
494
|
-
container = prev_container.add_module type, name_t
|
591
|
+
container = prev_container.add_module type, name_t[:text]
|
495
592
|
end
|
496
593
|
|
497
594
|
record_location container
|
@@ -505,32 +602,26 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
505
602
|
|
506
603
|
def get_symbol_or_name
|
507
604
|
tk = get_tk
|
508
|
-
case tk
|
509
|
-
when
|
510
|
-
text = tk
|
605
|
+
case tk[:kind]
|
606
|
+
when :on_symbol then
|
607
|
+
text = tk[:text].sub(/^:/, '')
|
511
608
|
|
512
|
-
|
609
|
+
next_tk = peek_tk
|
610
|
+
if next_tk && :on_op == next_tk[:kind] && '=' == next_tk[:text] then
|
513
611
|
get_tk
|
514
612
|
text << '='
|
515
613
|
end
|
516
614
|
|
517
615
|
text
|
518
|
-
when
|
519
|
-
tk
|
520
|
-
when
|
521
|
-
|
522
|
-
TkSTAR,
|
523
|
-
TkSTRING then
|
524
|
-
tk.text
|
616
|
+
when :on_ident, :on_const, :on_gvar, :on_cvar, :on_ivar, :on_op, :on_kw then
|
617
|
+
tk[:text]
|
618
|
+
when :on_tstring, :on_dstring then
|
619
|
+
tk[:text][1..-2]
|
525
620
|
else
|
526
621
|
raise RDoc::Error, "Name or symbol expected (got #{tk})"
|
527
622
|
end
|
528
623
|
end
|
529
624
|
|
530
|
-
def stop_at_EXPR_END # :nodoc:
|
531
|
-
@scanner.lex_state == :EXPR_END || !@scanner.continue
|
532
|
-
end
|
533
|
-
|
534
625
|
##
|
535
626
|
# Marks containers between +container+ and +ancestor+ as ignored
|
536
627
|
|
@@ -549,29 +640,31 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
549
640
|
#
|
550
641
|
# This routine modifies its +comment+ parameter.
|
551
642
|
|
552
|
-
def look_for_directives_in
|
553
|
-
@preprocess.handle comment,
|
643
|
+
def look_for_directives_in container, comment
|
644
|
+
@preprocess.handle comment, container do |directive, param|
|
554
645
|
case directive
|
555
646
|
when 'method', 'singleton-method',
|
556
647
|
'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
|
557
648
|
false # handled elsewhere
|
558
649
|
when 'section' then
|
559
|
-
|
650
|
+
break unless container.kind_of?(RDoc::Context)
|
651
|
+
container.set_current_section param, comment.dup
|
560
652
|
comment.text = ''
|
561
653
|
break
|
562
654
|
end
|
563
655
|
end
|
564
656
|
|
565
|
-
|
657
|
+
comment.remove_private
|
566
658
|
end
|
567
659
|
|
568
660
|
##
|
569
661
|
# Adds useful info about the parser to +message+
|
570
662
|
|
571
663
|
def make_message message
|
572
|
-
prefix = "#{@file_name}:"
|
664
|
+
prefix = "#{@file_name}:".dup
|
573
665
|
|
574
|
-
|
666
|
+
tk = peek_tk
|
667
|
+
prefix << "#{tk[:line_no]}:#{tk[:char_no]}:" if tk
|
575
668
|
|
576
669
|
"#{prefix} #{message}"
|
577
670
|
end
|
@@ -579,8 +672,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
579
672
|
##
|
580
673
|
# Creates a comment with the correct format
|
581
674
|
|
582
|
-
def new_comment comment
|
583
|
-
c = RDoc::Comment.new comment, @top_level
|
675
|
+
def new_comment comment, line_no = nil
|
676
|
+
c = RDoc::Comment.new comment, @top_level, :ruby
|
677
|
+
c.line = line_no
|
584
678
|
c.format = @markup
|
585
679
|
c
|
586
680
|
end
|
@@ -590,24 +684,22 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
590
684
|
# +comment+.
|
591
685
|
|
592
686
|
def parse_attr(context, single, tk, comment)
|
593
|
-
|
594
|
-
line_no = tk.line_no
|
687
|
+
line_no = tk[:line_no]
|
595
688
|
|
596
689
|
args = parse_symbol_arg 1
|
597
690
|
if args.size > 0 then
|
598
691
|
name = args[0]
|
599
692
|
rw = "R"
|
600
|
-
|
693
|
+
skip_tkspace_without_nl
|
601
694
|
tk = get_tk
|
602
695
|
|
603
|
-
if
|
696
|
+
if :on_comma == tk[:kind] then
|
604
697
|
rw = "RW" if get_bool
|
605
698
|
else
|
606
699
|
unget_tk tk
|
607
700
|
end
|
608
701
|
|
609
702
|
att = create_attr context, single, name, rw, comment
|
610
|
-
att.offset = offset
|
611
703
|
att.line = line_no
|
612
704
|
|
613
705
|
read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
|
@@ -621,8 +713,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
621
713
|
# comment for each to +comment+.
|
622
714
|
|
623
715
|
def parse_attr_accessor(context, single, tk, comment)
|
624
|
-
|
625
|
-
line_no = tk.line_no
|
716
|
+
line_no = tk[:line_no]
|
626
717
|
|
627
718
|
args = parse_symbol_arg
|
628
719
|
rw = "?"
|
@@ -633,7 +724,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
633
724
|
# and add found items appropriately but here we do not. I'm not sure why.
|
634
725
|
return if @track_visibility and not tmp.document_self
|
635
726
|
|
636
|
-
case tk
|
727
|
+
case tk[:text]
|
637
728
|
when "attr_reader" then rw = "R"
|
638
729
|
when "attr_writer" then rw = "W"
|
639
730
|
when "attr_accessor" then rw = "RW"
|
@@ -643,7 +734,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
643
734
|
|
644
735
|
for name in args
|
645
736
|
att = create_attr context, single, name, rw, comment
|
646
|
-
att.offset = offset
|
647
737
|
att.line = line_no
|
648
738
|
end
|
649
739
|
end
|
@@ -652,22 +742,19 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
652
742
|
# Parses an +alias+ in +context+ with +comment+
|
653
743
|
|
654
744
|
def parse_alias(context, single, tk, comment)
|
655
|
-
|
656
|
-
line_no = tk.line_no
|
745
|
+
line_no = tk[:line_no]
|
657
746
|
|
658
747
|
skip_tkspace
|
659
748
|
|
660
|
-
if
|
749
|
+
if :on_lparen === peek_tk[:kind] then
|
661
750
|
get_tk
|
662
751
|
skip_tkspace
|
663
752
|
end
|
664
753
|
|
665
754
|
new_name = get_symbol_or_name
|
666
755
|
|
667
|
-
@scanner.lex_state = :EXPR_FNAME
|
668
|
-
|
669
756
|
skip_tkspace
|
670
|
-
if
|
757
|
+
if :on_comma === peek_tk[:kind] then
|
671
758
|
get_tk
|
672
759
|
skip_tkspace
|
673
760
|
end
|
@@ -681,7 +768,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
681
768
|
al = RDoc::Alias.new(get_tkread, old_name, new_name, comment,
|
682
769
|
single == SINGLE)
|
683
770
|
record_location al
|
684
|
-
al.offset = offset
|
685
771
|
al.line = line_no
|
686
772
|
|
687
773
|
read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
|
@@ -695,34 +781,38 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
695
781
|
# Extracts call parameters from the token stream.
|
696
782
|
|
697
783
|
def parse_call_parameters(tk)
|
698
|
-
end_token = case tk
|
699
|
-
when
|
700
|
-
|
701
|
-
when
|
784
|
+
end_token = case tk[:kind]
|
785
|
+
when :on_lparen
|
786
|
+
:on_rparen
|
787
|
+
when :on_rparen
|
702
788
|
return ""
|
703
789
|
else
|
704
|
-
|
790
|
+
:on_nl
|
705
791
|
end
|
706
792
|
nest = 0
|
707
793
|
|
708
794
|
loop do
|
709
|
-
|
710
|
-
|
795
|
+
break if tk.nil?
|
796
|
+
case tk[:kind]
|
797
|
+
when :on_semicolon
|
711
798
|
break
|
712
|
-
when
|
799
|
+
when :on_lparen
|
713
800
|
nest += 1
|
714
801
|
when end_token
|
715
|
-
if end_token ==
|
802
|
+
if end_token == :on_rparen
|
716
803
|
nest -= 1
|
717
|
-
break if
|
804
|
+
break if RDoc::Parser::RipperStateLex.end?(tk) and nest <= 0
|
718
805
|
else
|
719
|
-
break
|
806
|
+
break if RDoc::Parser::RipperStateLex.end?(tk)
|
720
807
|
end
|
721
|
-
when
|
808
|
+
when :on_comment, :on_embdoc
|
722
809
|
unget_tk(tk)
|
723
810
|
break
|
724
|
-
when
|
725
|
-
|
811
|
+
when :on_op
|
812
|
+
if tk[:text] =~ /^(.{1,2})?=$/
|
813
|
+
unget_tk(tk)
|
814
|
+
break
|
815
|
+
end
|
726
816
|
end
|
727
817
|
tk = get_tk
|
728
818
|
end
|
@@ -734,33 +824,33 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
734
824
|
# Parses a class in +context+ with +comment+
|
735
825
|
|
736
826
|
def parse_class container, single, tk, comment
|
737
|
-
|
738
|
-
line_no = tk.line_no
|
827
|
+
line_no = tk[:line_no]
|
739
828
|
|
740
829
|
declaration_context = container
|
741
|
-
container, name_t, given_name = get_class_or_module container
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
when
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
return # don't update offset or line
|
753
|
-
else
|
754
|
-
parse_class_singleton container, name, comment
|
755
|
-
end
|
830
|
+
container, name_t, given_name, = get_class_or_module container
|
831
|
+
|
832
|
+
if name_t[:kind] == :on_const
|
833
|
+
cls = parse_class_regular container, declaration_context, single,
|
834
|
+
name_t, given_name, comment
|
835
|
+
elsif name_t[:kind] == :on_op && name_t[:text] == '<<'
|
836
|
+
case name = get_class_specification
|
837
|
+
when 'self', container.name
|
838
|
+
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
|
839
|
+
parse_statements container, SINGLE
|
840
|
+
return # don't update line
|
756
841
|
else
|
757
|
-
|
758
|
-
return
|
842
|
+
cls = parse_class_singleton container, name, comment
|
759
843
|
end
|
844
|
+
else
|
845
|
+
warn "Expected class name or '<<'. Got #{name_t[:kind]}: #{name_t[:text].inspect}"
|
846
|
+
return
|
847
|
+
end
|
760
848
|
|
761
|
-
cls.offset = offset
|
762
849
|
cls.line = line_no
|
763
850
|
|
851
|
+
# after end modifiers
|
852
|
+
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
|
853
|
+
|
764
854
|
cls
|
765
855
|
end
|
766
856
|
|
@@ -776,7 +866,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
776
866
|
given_name = $'
|
777
867
|
end
|
778
868
|
|
779
|
-
|
869
|
+
tk = peek_tk
|
870
|
+
if tk[:kind] == :on_op && tk[:text] == '<' then
|
780
871
|
get_tk
|
781
872
|
skip_tkspace
|
782
873
|
superclass = get_class_specification
|
@@ -846,102 +937,125 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
846
937
|
# true, no found constants will be added to RDoc.
|
847
938
|
|
848
939
|
def parse_constant container, tk, comment, ignore_constants = false
|
849
|
-
|
850
|
-
line_no = tk.line_no
|
940
|
+
line_no = tk[:line_no]
|
851
941
|
|
852
|
-
name = tk
|
853
|
-
|
942
|
+
name = tk[:text]
|
943
|
+
skip_tkspace_without_nl
|
854
944
|
|
855
945
|
return unless name =~ /^\w+$/
|
856
946
|
|
857
|
-
|
858
|
-
|
859
|
-
if TkCOLON2 === eq_tk then
|
860
|
-
unget_tk eq_tk
|
947
|
+
new_modules = []
|
948
|
+
if :on_op == peek_tk[:kind] && '::' == peek_tk[:text] then
|
861
949
|
unget_tk tk
|
862
950
|
|
863
|
-
container, name_t, = get_class_or_module container,
|
951
|
+
container, name_t, _, new_modules = get_class_or_module container, true
|
864
952
|
|
865
|
-
name = name_t
|
953
|
+
name = name_t[:text]
|
954
|
+
end
|
866
955
|
|
867
|
-
|
956
|
+
is_array_or_hash = false
|
957
|
+
if peek_tk && :on_lbracket == peek_tk[:kind]
|
958
|
+
get_tk
|
959
|
+
nest = 1
|
960
|
+
while bracket_tk = get_tk
|
961
|
+
case bracket_tk[:kind]
|
962
|
+
when :on_lbracket
|
963
|
+
nest += 1
|
964
|
+
when :on_rbracket
|
965
|
+
nest -= 1
|
966
|
+
break if nest == 0
|
967
|
+
end
|
968
|
+
end
|
969
|
+
skip_tkspace_without_nl
|
970
|
+
is_array_or_hash = true
|
868
971
|
end
|
869
972
|
|
870
|
-
unless
|
871
|
-
unget_tk eq_tk
|
973
|
+
unless peek_tk && :on_op == peek_tk[:kind] && '=' == peek_tk[:text] then
|
872
974
|
return false
|
873
975
|
end
|
976
|
+
get_tk
|
874
977
|
|
875
|
-
|
876
|
-
|
877
|
-
|
978
|
+
unless ignore_constants
|
979
|
+
new_modules.each do |prev_c, new_module|
|
980
|
+
prev_c.add_module_by_normal_module new_module
|
981
|
+
new_module.ignore unless prev_c.document_children
|
982
|
+
@top_level.add_to_classes_or_modules new_module
|
983
|
+
end
|
878
984
|
end
|
879
985
|
|
880
986
|
value = ''
|
881
987
|
con = RDoc::Constant.new name, value, comment
|
882
988
|
|
883
|
-
body = parse_constant_body container, con
|
989
|
+
body = parse_constant_body container, con, is_array_or_hash
|
884
990
|
|
885
991
|
return unless body
|
886
992
|
|
887
|
-
value
|
993
|
+
con.value = body
|
888
994
|
record_location con
|
889
|
-
con.offset = offset
|
890
995
|
con.line = line_no
|
891
996
|
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
|
892
997
|
|
998
|
+
return if is_array_or_hash
|
999
|
+
|
893
1000
|
@stats.add_constant con
|
894
1001
|
container.add_constant con
|
895
1002
|
|
896
1003
|
true
|
897
1004
|
end
|
898
1005
|
|
899
|
-
def parse_constant_body container, constant # :nodoc:
|
1006
|
+
def parse_constant_body container, constant, is_array_or_hash # :nodoc:
|
900
1007
|
nest = 0
|
901
|
-
rhs_name = ''
|
1008
|
+
rhs_name = ''.dup
|
902
1009
|
|
903
1010
|
get_tkread
|
904
1011
|
|
905
1012
|
tk = get_tk
|
906
1013
|
|
1014
|
+
body = nil
|
907
1015
|
loop do
|
908
|
-
|
909
|
-
|
1016
|
+
break if tk.nil?
|
1017
|
+
if :on_semicolon == tk[:kind] then
|
910
1018
|
break if nest <= 0
|
911
|
-
|
912
|
-
TkDO, TkIF, TkUNLESS, TkCASE, TkDEF, TkBEGIN then
|
1019
|
+
elsif [:on_tlambeg, :on_lparen, :on_lbrace, :on_lbracket].include?(tk[:kind]) then
|
913
1020
|
nest += 1
|
914
|
-
|
1021
|
+
elsif (:on_kw == tk[:kind] && 'def' == tk[:text]) then
|
1022
|
+
nest += 1
|
1023
|
+
elsif (:on_kw == tk[:kind] && %w{do if unless case begin}.include?(tk[:text])) then
|
1024
|
+
if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0
|
1025
|
+
nest += 1
|
1026
|
+
end
|
1027
|
+
elsif [:on_rparen, :on_rbrace, :on_rbracket].include?(tk[:kind]) ||
|
1028
|
+
(:on_kw == tk[:kind] && 'end' == tk[:text]) then
|
915
1029
|
nest -= 1
|
916
|
-
|
917
|
-
|
918
|
-
|
1030
|
+
elsif (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) then
|
1031
|
+
unget_tk tk
|
1032
|
+
if nest <= 0 and RDoc::Parser::RipperStateLex.end?(tk) then
|
1033
|
+
body = get_tkread_clean(/^[ \t]+/, '')
|
1034
|
+
read_documentation_modifiers constant, RDoc::CONSTANT_MODIFIERS
|
919
1035
|
break
|
920
1036
|
else
|
921
|
-
unget_tk tk
|
922
1037
|
read_documentation_modifiers constant, RDoc::CONSTANT_MODIFIERS
|
923
1038
|
end
|
924
|
-
|
925
|
-
rhs_name << tk
|
1039
|
+
elsif :on_const == tk[:kind] then
|
1040
|
+
rhs_name << tk[:text]
|
926
1041
|
|
927
|
-
|
928
|
-
|
1042
|
+
next_tk = peek_tk
|
1043
|
+
if nest <= 0 and (next_tk.nil? || :on_nl == next_tk[:kind]) then
|
1044
|
+
create_module_alias container, constant, rhs_name unless is_array_or_hash
|
929
1045
|
break
|
930
1046
|
end
|
931
|
-
|
932
|
-
if nest <= 0 and
|
1047
|
+
elsif :on_nl == tk[:kind] then
|
1048
|
+
if nest <= 0 and RDoc::Parser::RipperStateLex.end?(tk) then
|
933
1049
|
unget_tk tk
|
934
1050
|
break
|
935
1051
|
end
|
936
|
-
|
1052
|
+
elsif :on_op == tk[:kind] && '::' == tk[:text]
|
937
1053
|
rhs_name << '::'
|
938
|
-
when nil then
|
939
|
-
break
|
940
1054
|
end
|
941
1055
|
tk = get_tk
|
942
1056
|
end
|
943
1057
|
|
944
|
-
get_tkread_clean(/^[ \t]+/, '')
|
1058
|
+
body ? body : get_tkread_clean(/^[ \t]+/, '')
|
945
1059
|
end
|
946
1060
|
|
947
1061
|
##
|
@@ -950,24 +1064,22 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
950
1064
|
|
951
1065
|
def parse_comment container, tk, comment
|
952
1066
|
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
|
953
|
-
column = tk
|
954
|
-
|
955
|
-
line_no = tk.line_no
|
956
|
-
|
957
|
-
text = comment.text
|
1067
|
+
column = tk[:char_no]
|
1068
|
+
line_no = comment.line.nil? ? tk[:line_no] : comment.line
|
958
1069
|
|
959
|
-
|
1070
|
+
comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
|
1071
|
+
singleton = !!$~
|
960
1072
|
|
961
1073
|
co =
|
962
|
-
if text.sub
|
963
|
-
|
964
|
-
|
1074
|
+
if (comment.text = comment.text.sub(/^# +:?method: *(\S*).*?\n/i, '')) && !!$~ then
|
1075
|
+
line_no += $`.count("\n")
|
1076
|
+
parse_comment_ghost container, comment.text, $1, column, line_no, comment
|
1077
|
+
elsif (comment.text = comment.text.sub(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '')) && !!$~ then
|
965
1078
|
parse_comment_attr container, $1, $3, comment
|
966
1079
|
end
|
967
1080
|
|
968
1081
|
if co then
|
969
1082
|
co.singleton = singleton
|
970
|
-
co.offset = offset
|
971
1083
|
co.line = line_no
|
972
1084
|
end
|
973
1085
|
|
@@ -998,12 +1110,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
998
1110
|
record_location meth
|
999
1111
|
|
1000
1112
|
meth.start_collecting_tokens
|
1001
|
-
indent =
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
|
1113
|
+
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
1114
|
+
position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
1115
|
+
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
1116
|
+
newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
|
1117
|
+
meth.add_tokens [position_comment, newline, indent]
|
1007
1118
|
|
1008
1119
|
meth.params =
|
1009
1120
|
if text.sub!(/^#\s+:?args?:\s*(.*?)\s*$/i, '') then
|
@@ -1032,23 +1143,21 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1032
1143
|
|
1033
1144
|
def parse_comment_tomdoc container, tk, comment
|
1034
1145
|
return unless signature = RDoc::TomDoc.signature(comment)
|
1035
|
-
|
1036
|
-
line_no = tk
|
1146
|
+
column = tk[:char_no]
|
1147
|
+
line_no = tk[:line_no]
|
1037
1148
|
|
1038
1149
|
name, = signature.split %r%[ \(]%, 2
|
1039
1150
|
|
1040
1151
|
meth = RDoc::GhostMethod.new get_tkread, name
|
1041
1152
|
record_location meth
|
1042
|
-
meth.offset = offset
|
1043
1153
|
meth.line = line_no
|
1044
1154
|
|
1045
1155
|
meth.start_collecting_tokens
|
1046
|
-
indent =
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
|
1156
|
+
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
1157
|
+
position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
1158
|
+
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
1159
|
+
newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
|
1160
|
+
meth.add_tokens [position_comment, newline, indent]
|
1052
1161
|
|
1053
1162
|
meth.call_seq = signature
|
1054
1163
|
|
@@ -1071,14 +1180,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1071
1180
|
loop do
|
1072
1181
|
skip_tkspace_comment
|
1073
1182
|
|
1074
|
-
name =
|
1183
|
+
name = get_included_module_with_optional_parens
|
1075
1184
|
|
1076
1185
|
unless name.empty? then
|
1077
1186
|
obj = container.add klass, name, comment
|
1078
1187
|
record_location obj
|
1079
1188
|
end
|
1080
1189
|
|
1081
|
-
return
|
1190
|
+
return if peek_tk.nil? || :on_comma != peek_tk[:kind]
|
1082
1191
|
|
1083
1192
|
get_tk
|
1084
1193
|
end
|
@@ -1090,11 +1199,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1090
1199
|
# Returns true if the comment was not consumed.
|
1091
1200
|
|
1092
1201
|
def parse_identifier container, single, tk, comment # :nodoc:
|
1093
|
-
case tk
|
1202
|
+
case tk[:text]
|
1094
1203
|
when 'private', 'protected', 'public', 'private_class_method',
|
1095
1204
|
'public_class_method', 'module_function' then
|
1096
1205
|
parse_visibility container, single, tk
|
1097
1206
|
return true
|
1207
|
+
when 'private_constant', 'public_constant'
|
1208
|
+
parse_constant_visibility container, single, tk
|
1209
|
+
return true
|
1098
1210
|
when 'attr' then
|
1099
1211
|
parse_attr container, single, tk, comment
|
1100
1212
|
when /^attr_(reader|writer|accessor)$/ then
|
@@ -1159,7 +1271,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1159
1271
|
tmp = RDoc::CodeObject.new
|
1160
1272
|
read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS
|
1161
1273
|
|
1162
|
-
|
1274
|
+
regexp = /^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i
|
1275
|
+
if regexp =~ comment.text then
|
1276
|
+
comment.text = comment.text.sub(regexp, '')
|
1163
1277
|
rw = case $1
|
1164
1278
|
when 'attr_reader' then 'R'
|
1165
1279
|
when 'attr_writer' then 'W'
|
@@ -1183,17 +1297,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1183
1297
|
# Parses a meta-programmed method
|
1184
1298
|
|
1185
1299
|
def parse_meta_method(container, single, tk, comment)
|
1186
|
-
column = tk
|
1187
|
-
|
1188
|
-
line_no = tk.line_no
|
1300
|
+
column = tk[:char_no]
|
1301
|
+
line_no = tk[:line_no]
|
1189
1302
|
|
1190
1303
|
start_collecting_tokens
|
1191
1304
|
add_token tk
|
1192
1305
|
add_token_listener self
|
1193
1306
|
|
1194
|
-
|
1307
|
+
skip_tkspace_without_nl
|
1195
1308
|
|
1196
|
-
|
1309
|
+
comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
|
1310
|
+
singleton = !!$~
|
1197
1311
|
|
1198
1312
|
name = parse_meta_method_name comment, tk
|
1199
1313
|
|
@@ -1201,19 +1315,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1201
1315
|
|
1202
1316
|
meth = RDoc::MetaMethod.new get_tkread, name
|
1203
1317
|
record_location meth
|
1204
|
-
meth.offset = offset
|
1205
1318
|
meth.line = line_no
|
1206
1319
|
meth.singleton = singleton
|
1207
1320
|
|
1208
1321
|
remove_token_listener self
|
1209
1322
|
|
1210
1323
|
meth.start_collecting_tokens
|
1211
|
-
indent =
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
|
1324
|
+
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
1325
|
+
position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
1326
|
+
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
1327
|
+
newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
|
1328
|
+
meth.add_tokens [position_comment, newline, indent]
|
1217
1329
|
meth.add_tokens @token_stream
|
1218
1330
|
|
1219
1331
|
parse_meta_method_params container, single, meth, tk, comment
|
@@ -1237,17 +1349,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1237
1349
|
|
1238
1350
|
name_t = get_tk
|
1239
1351
|
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
when TkASSIGN then # ignore
|
1352
|
+
if :on_symbol == name_t[:kind] then
|
1353
|
+
name_t[:text][1..-1]
|
1354
|
+
elsif :on_tstring == name_t[:kind] then
|
1355
|
+
name_t[:text][1..-2]
|
1356
|
+
elsif :on_op == name_t[:kind] && '=' == name_t[:text] then # ignore
|
1246
1357
|
remove_token_listener self
|
1247
1358
|
|
1248
1359
|
nil
|
1249
1360
|
else
|
1250
|
-
warn "unknown name token #{name_t.inspect} for meta-method '#{tk
|
1361
|
+
warn "unknown name token #{name_t.inspect} for meta-method '#{tk[:text]}'"
|
1251
1362
|
'unknown'
|
1252
1363
|
end
|
1253
1364
|
end
|
@@ -1259,6 +1370,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1259
1370
|
token_listener meth do
|
1260
1371
|
meth.params = ''
|
1261
1372
|
|
1373
|
+
look_for_directives_in meth, comment
|
1262
1374
|
comment.normalize
|
1263
1375
|
comment.extract_call_seq meth
|
1264
1376
|
|
@@ -1267,14 +1379,13 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1267
1379
|
last_tk = tk
|
1268
1380
|
|
1269
1381
|
while tk = get_tk do
|
1270
|
-
|
1271
|
-
when TkSEMICOLON then
|
1382
|
+
if :on_semicolon == tk[:kind] then
|
1272
1383
|
break
|
1273
|
-
|
1274
|
-
break unless last_tk and
|
1275
|
-
|
1384
|
+
elsif :on_nl == tk[:kind] then
|
1385
|
+
break unless last_tk and :on_comma == last_tk[:kind]
|
1386
|
+
elsif :on_sp == tk[:kind] then
|
1276
1387
|
# expression continues
|
1277
|
-
|
1388
|
+
elsif :on_kw == tk[:kind] && 'do' == tk[:text] then
|
1278
1389
|
parse_statements container, single, meth
|
1279
1390
|
break
|
1280
1391
|
else
|
@@ -1291,9 +1402,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1291
1402
|
singleton = nil
|
1292
1403
|
added_container = false
|
1293
1404
|
name = nil
|
1294
|
-
column = tk
|
1295
|
-
|
1296
|
-
line_no = tk.line_no
|
1405
|
+
column = tk[:char_no]
|
1406
|
+
line_no = tk[:line_no]
|
1297
1407
|
|
1298
1408
|
start_collecting_tokens
|
1299
1409
|
add_token tk
|
@@ -1307,19 +1417,18 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1307
1417
|
return unless name
|
1308
1418
|
|
1309
1419
|
meth = RDoc::AnyMethod.new get_tkread, name
|
1420
|
+
look_for_directives_in meth, comment
|
1310
1421
|
meth.singleton = single == SINGLE ? true : singleton
|
1311
1422
|
|
1312
1423
|
record_location meth
|
1313
|
-
meth.offset = offset
|
1314
1424
|
meth.line = line_no
|
1315
1425
|
|
1316
1426
|
meth.start_collecting_tokens
|
1317
|
-
indent =
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
meth.add_tokens [token, NEWLINE_TOKEN, indent]
|
1427
|
+
indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
|
1428
|
+
token = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
|
1429
|
+
token[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
|
1430
|
+
newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
|
1431
|
+
meth.add_tokens [token, newline, indent]
|
1323
1432
|
meth.add_tokens @token_stream
|
1324
1433
|
|
1325
1434
|
parse_method_params_and_body container, single, meth, added_container
|
@@ -1329,6 +1438,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1329
1438
|
|
1330
1439
|
meth.comment = comment
|
1331
1440
|
|
1441
|
+
# after end modifiers
|
1442
|
+
read_documentation_modifiers meth, RDoc::METHOD_MODIFIERS
|
1443
|
+
|
1332
1444
|
@stats.add_method meth
|
1333
1445
|
end
|
1334
1446
|
|
@@ -1337,7 +1449,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1337
1449
|
|
1338
1450
|
def parse_method_params_and_body container, single, meth, added_container
|
1339
1451
|
token_listener meth do
|
1340
|
-
@scanner.continue = false
|
1341
1452
|
parse_method_parameters meth
|
1342
1453
|
|
1343
1454
|
if meth.document_self or not @track_visibility then
|
@@ -1380,15 +1491,13 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1380
1491
|
# it is a singleton or regular method.
|
1381
1492
|
|
1382
1493
|
def parse_method_name container # :nodoc:
|
1383
|
-
@scanner.lex_state = :EXPR_FNAME
|
1384
|
-
|
1385
1494
|
skip_tkspace
|
1386
1495
|
name_t = get_tk
|
1387
|
-
back_tk =
|
1496
|
+
back_tk = skip_tkspace_without_nl
|
1388
1497
|
singleton = false
|
1389
1498
|
|
1390
|
-
|
1391
|
-
|
1499
|
+
dot = get_tk
|
1500
|
+
if dot[:kind] == :on_period || (dot[:kind] == :on_op && dot[:text] == '::') then
|
1392
1501
|
singleton = true
|
1393
1502
|
|
1394
1503
|
name, container = parse_method_name_singleton container, name_t
|
@@ -1409,16 +1518,15 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1409
1518
|
# is parsed from the token stream for a regular method.
|
1410
1519
|
|
1411
1520
|
def parse_method_name_regular container, name_t # :nodoc:
|
1412
|
-
|
1413
|
-
|
1414
|
-
name_t.text
|
1521
|
+
if :on_op == name_t[:kind] && (%w{* & [] []= <<}.include?(name_t[:text])) then
|
1522
|
+
name_t[:text]
|
1415
1523
|
else
|
1416
|
-
unless
|
1524
|
+
unless [:on_kw, :on_const, :on_ident].include?(name_t[:kind]) then
|
1417
1525
|
warn "expected method name token, . or ::, got #{name_t.inspect}"
|
1418
1526
|
skip_method container
|
1419
1527
|
return
|
1420
1528
|
end
|
1421
|
-
name_t
|
1529
|
+
name_t[:text]
|
1422
1530
|
end
|
1423
1531
|
end
|
1424
1532
|
|
@@ -1428,47 +1536,42 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1428
1536
|
# for a singleton method.
|
1429
1537
|
|
1430
1538
|
def parse_method_name_singleton container, name_t # :nodoc:
|
1431
|
-
@scanner.lex_state = :EXPR_FNAME
|
1432
1539
|
skip_tkspace
|
1433
1540
|
name_t2 = get_tk
|
1434
1541
|
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
name_t2.name
|
1446
|
-
end
|
1447
|
-
when TkCONSTANT then
|
1448
|
-
name = name_t2.name
|
1542
|
+
if (:on_kw == name_t[:kind] && 'self' == name_t[:text]) || (:on_op == name_t[:kind] && '%' == name_t[:text]) then
|
1543
|
+
# NOTE: work around '[' being consumed early
|
1544
|
+
if :on_lbracket == name_t2[:kind]
|
1545
|
+
get_tk
|
1546
|
+
name = '[]'
|
1547
|
+
else
|
1548
|
+
name = name_t2[:text]
|
1549
|
+
end
|
1550
|
+
elsif :on_const == name_t[:kind] then
|
1551
|
+
name = name_t2[:text]
|
1449
1552
|
|
1450
|
-
|
1553
|
+
container = get_method_container container, name_t
|
1451
1554
|
|
1452
|
-
|
1555
|
+
return unless container
|
1453
1556
|
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1557
|
+
name
|
1558
|
+
elsif :on_ident == name_t[:kind] || :on_ivar == name_t[:kind] || :on_gvar == name_t[:kind] then
|
1559
|
+
parse_method_dummy container
|
1457
1560
|
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1561
|
+
name = nil
|
1562
|
+
elsif (:on_kw == name_t[:kind]) && ('true' == name_t[:text] || 'false' == name_t[:text] || 'nil' == name_t[:text]) then
|
1563
|
+
klass_name = "#{name_t[:text].capitalize}Class"
|
1564
|
+
container = @store.find_class_named klass_name
|
1565
|
+
container ||= @top_level.add_class RDoc::NormalClass, klass_name
|
1463
1566
|
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1567
|
+
name = name_t2[:text]
|
1568
|
+
else
|
1569
|
+
warn "unexpected method name token #{name_t.inspect}"
|
1570
|
+
# break
|
1571
|
+
skip_method container
|
1469
1572
|
|
1470
|
-
|
1471
|
-
|
1573
|
+
name = nil
|
1574
|
+
end
|
1472
1575
|
|
1473
1576
|
return name, container
|
1474
1577
|
end
|
@@ -1478,45 +1581,56 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1478
1581
|
|
1479
1582
|
def parse_method_or_yield_parameters(method = nil,
|
1480
1583
|
modifiers = RDoc::METHOD_MODIFIERS)
|
1481
|
-
|
1584
|
+
skip_tkspace_without_nl
|
1482
1585
|
tk = get_tk
|
1483
1586
|
end_token = get_end_token tk
|
1484
1587
|
return '' unless end_token
|
1485
1588
|
|
1486
1589
|
nest = 0
|
1590
|
+
continue = false
|
1487
1591
|
|
1488
|
-
|
1489
|
-
case tk
|
1490
|
-
when
|
1592
|
+
while tk != nil do
|
1593
|
+
case tk[:kind]
|
1594
|
+
when :on_semicolon then
|
1491
1595
|
break if nest == 0
|
1492
|
-
when
|
1596
|
+
when :on_lbracket then
|
1597
|
+
nest += 1
|
1598
|
+
when :on_rbracket then
|
1599
|
+
nest -= 1
|
1600
|
+
when :on_lbrace then
|
1493
1601
|
nest += 1
|
1494
|
-
when
|
1602
|
+
when :on_rbrace then
|
1495
1603
|
nest -= 1
|
1496
1604
|
if nest <= 0
|
1497
1605
|
# we might have a.each { |i| yield i }
|
1498
1606
|
unget_tk(tk) if nest < 0
|
1499
1607
|
break
|
1500
1608
|
end
|
1501
|
-
when
|
1609
|
+
when :on_lparen then
|
1502
1610
|
nest += 1
|
1503
|
-
when end_token then
|
1504
|
-
if end_token ==
|
1611
|
+
when end_token[:kind] then
|
1612
|
+
if end_token[:kind] == :on_rparen
|
1505
1613
|
nest -= 1
|
1506
1614
|
break if nest <= 0
|
1507
1615
|
else
|
1508
|
-
break
|
1616
|
+
break
|
1509
1617
|
end
|
1510
|
-
when
|
1618
|
+
when :on_rparen then
|
1511
1619
|
nest -= 1
|
1512
|
-
when
|
1513
|
-
unget_tk tk
|
1514
|
-
read_documentation_modifiers method, modifiers
|
1515
|
-
@read.pop
|
1516
|
-
when TkCOMMENT then
|
1620
|
+
when :on_comment, :on_embdoc then
|
1517
1621
|
@read.pop
|
1518
|
-
|
1519
|
-
|
1622
|
+
if :on_nl == end_token[:kind] and "\n" == tk[:text][-1] and
|
1623
|
+
(!continue or (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0) then
|
1624
|
+
if method && method.block_params.nil? then
|
1625
|
+
unget_tk tk
|
1626
|
+
read_documentation_modifiers method, modifiers
|
1627
|
+
end
|
1628
|
+
break if !continue and nest <= 0
|
1629
|
+
end
|
1630
|
+
when :on_comma then
|
1631
|
+
continue = true
|
1632
|
+
when :on_ident then
|
1633
|
+
continue = false if continue
|
1520
1634
|
end
|
1521
1635
|
tk = get_tk
|
1522
1636
|
end
|
@@ -1540,7 +1654,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1540
1654
|
|
1541
1655
|
return if method.block_params
|
1542
1656
|
|
1543
|
-
|
1657
|
+
skip_tkspace_without_nl
|
1544
1658
|
read_documentation_modifiers method, RDoc::METHOD_MODIFIERS
|
1545
1659
|
end
|
1546
1660
|
|
@@ -1550,7 +1664,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1550
1664
|
def parse_module container, single, tk, comment
|
1551
1665
|
container, name_t, = get_class_or_module container
|
1552
1666
|
|
1553
|
-
name = name_t
|
1667
|
+
name = name_t[:text]
|
1554
1668
|
|
1555
1669
|
mod = container.add_module RDoc::NormalModule, name
|
1556
1670
|
mod.ignore unless container.document_children
|
@@ -1560,6 +1674,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1560
1674
|
mod.add_comment comment, @top_level
|
1561
1675
|
parse_statements mod
|
1562
1676
|
|
1677
|
+
# after end modifiers
|
1678
|
+
read_documentation_modifiers mod, RDoc::CLASS_MODIFIERS
|
1679
|
+
|
1563
1680
|
@stats.add_module mod
|
1564
1681
|
end
|
1565
1682
|
|
@@ -1570,12 +1687,12 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1570
1687
|
skip_tkspace_comment
|
1571
1688
|
tk = get_tk
|
1572
1689
|
|
1573
|
-
if
|
1690
|
+
if :on_lparen == tk[:kind] then
|
1574
1691
|
skip_tkspace_comment
|
1575
1692
|
tk = get_tk
|
1576
1693
|
end
|
1577
1694
|
|
1578
|
-
name = tk
|
1695
|
+
name = tk[:text][1..-2] if :on_tstring == tk[:kind]
|
1579
1696
|
|
1580
1697
|
if name then
|
1581
1698
|
@top_level.add_require RDoc::Require.new(name, comment)
|
@@ -1588,19 +1705,30 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1588
1705
|
# Parses a rescue
|
1589
1706
|
|
1590
1707
|
def parse_rescue
|
1591
|
-
|
1708
|
+
skip_tkspace_without_nl
|
1592
1709
|
|
1593
1710
|
while tk = get_tk
|
1594
|
-
case tk
|
1595
|
-
when
|
1711
|
+
case tk[:kind]
|
1712
|
+
when :on_nl, :on_semicolon, :on_comment then
|
1596
1713
|
break
|
1597
|
-
when
|
1598
|
-
|
1714
|
+
when :on_comma then
|
1715
|
+
skip_tkspace_without_nl
|
1599
1716
|
|
1600
|
-
get_tk if
|
1717
|
+
get_tk if :on_nl == peek_tk[:kind]
|
1601
1718
|
end
|
1602
1719
|
|
1603
|
-
|
1720
|
+
skip_tkspace_without_nl
|
1721
|
+
end
|
1722
|
+
end
|
1723
|
+
|
1724
|
+
##
|
1725
|
+
# Retrieve comment body without =begin/=end
|
1726
|
+
|
1727
|
+
def retrieve_comment_body(tk)
|
1728
|
+
if :on_embdoc == tk[:kind]
|
1729
|
+
tk[:text].gsub(/\A=begin.*\n/, '').gsub(/=end\n?\z/, '')
|
1730
|
+
else
|
1731
|
+
tk[:text]
|
1604
1732
|
end
|
1605
1733
|
end
|
1606
1734
|
|
@@ -1610,7 +1738,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1610
1738
|
def parse_statements(container, single = NORMAL, current_method = nil,
|
1611
1739
|
comment = new_comment(''))
|
1612
1740
|
raise 'no' unless RDoc::Comment === comment
|
1613
|
-
comment.
|
1741
|
+
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
1614
1742
|
|
1615
1743
|
nest = 1
|
1616
1744
|
save_visibility = container.visibility
|
@@ -1621,35 +1749,55 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1621
1749
|
keep_comment = false
|
1622
1750
|
try_parse_comment = false
|
1623
1751
|
|
1624
|
-
non_comment_seen = true unless
|
1752
|
+
non_comment_seen = true unless (:on_comment == tk[:kind] or :on_embdoc == tk[:kind])
|
1625
1753
|
|
1626
|
-
case tk
|
1627
|
-
when
|
1628
|
-
|
1629
|
-
|
1754
|
+
case tk[:kind]
|
1755
|
+
when :on_nl, :on_ignored_nl, :on_comment, :on_embdoc then
|
1756
|
+
if :on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]
|
1757
|
+
skip_tkspace
|
1758
|
+
tk = get_tk
|
1759
|
+
else
|
1760
|
+
past_tokens = @read.size > 1 ? @read[0..-2] : []
|
1761
|
+
nl_position = 0
|
1762
|
+
past_tokens.reverse.each_with_index do |read_tk, i|
|
1763
|
+
if read_tk =~ /^\n$/ then
|
1764
|
+
nl_position = (past_tokens.size - 1) - i
|
1765
|
+
break
|
1766
|
+
elsif read_tk =~ /^#.*\n$/ then
|
1767
|
+
nl_position = ((past_tokens.size - 1) - i) + 1
|
1768
|
+
break
|
1769
|
+
end
|
1770
|
+
end
|
1771
|
+
comment_only_line = past_tokens[nl_position..-1].all?{ |c| c =~ /^\s+$/ }
|
1772
|
+
unless comment_only_line then
|
1773
|
+
tk = get_tk
|
1774
|
+
end
|
1775
|
+
end
|
1630
1776
|
|
1631
|
-
if
|
1777
|
+
if tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) then
|
1632
1778
|
if non_comment_seen then
|
1633
1779
|
# Look for RDoc in a comment about to be thrown away
|
1634
1780
|
non_comment_seen = parse_comment container, tk, comment unless
|
1635
1781
|
comment.empty?
|
1636
1782
|
|
1637
1783
|
comment = ''
|
1638
|
-
comment.
|
1784
|
+
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
1639
1785
|
end
|
1640
1786
|
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1787
|
+
line_no = nil
|
1788
|
+
while tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) do
|
1789
|
+
comment_body = retrieve_comment_body(tk)
|
1790
|
+
line_no = tk[:line_no] if comment.empty?
|
1791
|
+
comment += comment_body
|
1792
|
+
comment << "\n" unless comment_body =~ /\n\z/
|
1645
1793
|
|
1646
|
-
if
|
1647
|
-
|
1648
|
-
tk = get_tk
|
1794
|
+
if comment_body.size > 1 && comment_body =~ /\n\z/ then
|
1795
|
+
skip_tkspace_without_nl # leading spaces
|
1649
1796
|
end
|
1797
|
+
tk = get_tk
|
1650
1798
|
end
|
1651
1799
|
|
1652
|
-
comment = new_comment comment
|
1800
|
+
comment = new_comment comment, line_no
|
1653
1801
|
|
1654
1802
|
unless comment.empty? then
|
1655
1803
|
look_for_directives_in container, comment
|
@@ -1667,60 +1815,78 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1667
1815
|
|
1668
1816
|
unget_tk tk
|
1669
1817
|
keep_comment = true
|
1818
|
+
container.current_line_visibility = nil
|
1670
1819
|
|
1671
|
-
when
|
1672
|
-
|
1820
|
+
when :on_kw then
|
1821
|
+
case tk[:text]
|
1822
|
+
when 'class' then
|
1823
|
+
parse_class container, single, tk, comment
|
1673
1824
|
|
1674
|
-
|
1675
|
-
|
1825
|
+
when 'module' then
|
1826
|
+
parse_module container, single, tk, comment
|
1676
1827
|
|
1677
|
-
|
1678
|
-
|
1828
|
+
when 'def' then
|
1829
|
+
parse_method container, single, tk, comment
|
1679
1830
|
|
1680
|
-
|
1681
|
-
|
1682
|
-
try_parse_comment = true
|
1683
|
-
end
|
1831
|
+
when 'alias' then
|
1832
|
+
parse_alias container, single, tk, comment unless current_method
|
1684
1833
|
|
1685
|
-
|
1686
|
-
|
1834
|
+
when 'yield' then
|
1835
|
+
if current_method.nil? then
|
1836
|
+
warn "Warning: yield outside of method" if container.document_self
|
1837
|
+
else
|
1838
|
+
parse_yield container, single, tk, current_method
|
1839
|
+
end
|
1687
1840
|
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
end
|
1841
|
+
when 'until', 'while' then
|
1842
|
+
if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0
|
1843
|
+
nest += 1
|
1844
|
+
skip_optional_do_after_expression
|
1845
|
+
end
|
1694
1846
|
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1847
|
+
# Until and While can have a 'do', which shouldn't increase the nesting.
|
1848
|
+
# We can't solve the general case, but we can handle most occurrences by
|
1849
|
+
# ignoring a do at the end of a line.
|
1698
1850
|
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1851
|
+
# 'for' is trickier
|
1852
|
+
when 'for' then
|
1853
|
+
nest += 1
|
1854
|
+
skip_for_variable
|
1855
|
+
skip_optional_do_after_expression
|
1702
1856
|
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
skip_optional_do_after_expression
|
1857
|
+
when 'case', 'do', 'if', 'unless', 'begin' then
|
1858
|
+
if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0
|
1859
|
+
nest += 1
|
1860
|
+
end
|
1708
1861
|
|
1709
|
-
|
1710
|
-
|
1862
|
+
when 'super' then
|
1863
|
+
current_method.calls_super = true if current_method
|
1864
|
+
|
1865
|
+
when 'rescue' then
|
1866
|
+
parse_rescue
|
1711
1867
|
|
1712
|
-
|
1713
|
-
|
1868
|
+
when 'end' then
|
1869
|
+
nest -= 1
|
1870
|
+
if nest == 0 then
|
1871
|
+
container.ongoing_visibility = save_visibility
|
1872
|
+
|
1873
|
+
parse_comment container, tk, comment unless comment.empty?
|
1714
1874
|
|
1715
|
-
|
1716
|
-
|
1875
|
+
return
|
1876
|
+
end
|
1877
|
+
end
|
1717
1878
|
|
1718
|
-
when
|
1879
|
+
when :on_const then
|
1880
|
+
unless parse_constant container, tk, comment, current_method then
|
1881
|
+
try_parse_comment = true
|
1882
|
+
end
|
1883
|
+
|
1884
|
+
when :on_ident then
|
1719
1885
|
if nest == 1 and current_method.nil? then
|
1720
1886
|
keep_comment = parse_identifier container, single, tk, comment
|
1721
1887
|
end
|
1722
1888
|
|
1723
|
-
case tk
|
1889
|
+
case tk[:text]
|
1724
1890
|
when "require" then
|
1725
1891
|
parse_require container, comment
|
1726
1892
|
when "include" then
|
@@ -1729,16 +1895,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1729
1895
|
parse_extend_or_include RDoc::Extend, container, comment
|
1730
1896
|
end
|
1731
1897
|
|
1732
|
-
when TkEND then
|
1733
|
-
nest -= 1
|
1734
|
-
if nest == 0 then
|
1735
|
-
read_documentation_modifiers container, RDoc::CLASS_MODIFIERS
|
1736
|
-
container.ongoing_visibility = save_visibility
|
1737
|
-
|
1738
|
-
parse_comment container, tk, comment unless comment.empty?
|
1739
|
-
|
1740
|
-
return
|
1741
|
-
end
|
1742
1898
|
else
|
1743
1899
|
try_parse_comment = nest == 1
|
1744
1900
|
end
|
@@ -1752,7 +1908,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1752
1908
|
|
1753
1909
|
unless keep_comment then
|
1754
1910
|
comment = new_comment ''
|
1755
|
-
comment.
|
1911
|
+
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
|
1756
1912
|
container.params = nil
|
1757
1913
|
container.block_params = nil
|
1758
1914
|
end
|
@@ -1770,8 +1926,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1770
1926
|
def parse_symbol_arg(no = nil)
|
1771
1927
|
skip_tkspace_comment
|
1772
1928
|
|
1773
|
-
|
1774
|
-
|
1929
|
+
tk = get_tk
|
1930
|
+
if tk[:kind] == :on_lparen
|
1775
1931
|
parse_symbol_arg_paren no
|
1776
1932
|
else
|
1777
1933
|
parse_symbol_arg_space no, tk
|
@@ -1793,10 +1949,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1793
1949
|
end
|
1794
1950
|
|
1795
1951
|
skip_tkspace_comment
|
1796
|
-
case tk2 = get_tk
|
1797
|
-
when
|
1952
|
+
case (tk2 = get_tk)[:kind]
|
1953
|
+
when :on_rparen
|
1798
1954
|
break
|
1799
|
-
when
|
1955
|
+
when :on_comma
|
1800
1956
|
else
|
1801
1957
|
warn("unexpected token: '#{tk2.inspect}'") if $DEBUG_RDOC
|
1802
1958
|
break
|
@@ -1820,10 +1976,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1820
1976
|
end
|
1821
1977
|
|
1822
1978
|
loop do
|
1823
|
-
|
1979
|
+
skip_tkspace_without_nl
|
1824
1980
|
|
1825
1981
|
tk1 = get_tk
|
1826
|
-
|
1982
|
+
if tk1.nil? || :on_comma != tk1[:kind] then
|
1827
1983
|
unget_tk tk1
|
1828
1984
|
break
|
1829
1985
|
end
|
@@ -1842,12 +1998,12 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1842
1998
|
# Returns symbol text from the next token
|
1843
1999
|
|
1844
2000
|
def parse_symbol_in_arg
|
1845
|
-
|
1846
|
-
|
1847
|
-
tk
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
2001
|
+
tk = get_tk
|
2002
|
+
if :on_symbol == tk[:kind] then
|
2003
|
+
tk[:text].sub(/^:/, '')
|
2004
|
+
elsif :on_tstring == tk[:kind] then
|
2005
|
+
tk[:text][1..-2]
|
2006
|
+
elsif :on_dstring == tk[:kind] or :on_ident == tk[:kind] then
|
1851
2007
|
nil # ignore
|
1852
2008
|
else
|
1853
2009
|
warn("Expected symbol or string, got #{tk.inspect}") if $DEBUG_RDOC
|
@@ -1881,19 +2037,37 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1881
2037
|
|
1882
2038
|
skip_tkspace_comment false
|
1883
2039
|
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
2040
|
+
ptk = peek_tk
|
2041
|
+
# Ryan Davis suggested the extension to ignore modifiers, because he
|
2042
|
+
# often writes
|
2043
|
+
#
|
2044
|
+
# protected unless $TESTING
|
2045
|
+
#
|
2046
|
+
if [:on_nl, :on_semicolon].include?(ptk[:kind]) || (:on_kw == ptk[:kind] && (['if', 'unless'].include?(ptk[:text]))) then
|
1891
2047
|
container.ongoing_visibility = vis
|
2048
|
+
elsif :on_kw == ptk[:kind] && 'def' == ptk[:text]
|
2049
|
+
container.current_line_visibility = vis
|
1892
2050
|
else
|
1893
2051
|
update_visibility container, vis_type, vis, singleton
|
1894
2052
|
end
|
1895
2053
|
end
|
1896
2054
|
|
2055
|
+
##
|
2056
|
+
# Parses a Module#private_constant or Module#public_constant call from +tk+.
|
2057
|
+
|
2058
|
+
def parse_constant_visibility(container, single, tk)
|
2059
|
+
args = parse_symbol_arg
|
2060
|
+
case tk[:text]
|
2061
|
+
when 'private_constant'
|
2062
|
+
vis = :private
|
2063
|
+
when 'public_constant'
|
2064
|
+
vis = :public
|
2065
|
+
else
|
2066
|
+
raise RDoc::Error, 'Unreachable'
|
2067
|
+
end
|
2068
|
+
container.set_constant_visibility_for args, vis
|
2069
|
+
end
|
2070
|
+
|
1897
2071
|
##
|
1898
2072
|
# Determines the block parameter for +context+
|
1899
2073
|
|
@@ -1901,7 +2075,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1901
2075
|
return if method.block_params
|
1902
2076
|
|
1903
2077
|
get_tkread
|
1904
|
-
@scanner.continue = false
|
1905
2078
|
method.block_params = parse_method_or_yield_parameters
|
1906
2079
|
end
|
1907
2080
|
|
@@ -1925,11 +2098,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1925
2098
|
while tk = get_tk do
|
1926
2099
|
tokens << tk
|
1927
2100
|
|
1928
|
-
|
1929
|
-
when TkNL, TkDEF then
|
2101
|
+
if :on_nl == tk[:kind] or (:on_kw == tk[:kind] && 'def' == tk[:text]) then
|
1930
2102
|
return
|
1931
|
-
|
1932
|
-
return unless tk
|
2103
|
+
elsif :on_comment == tk[:kind] or :on_embdoc == tk[:kind] then
|
2104
|
+
return unless tk[:text] =~ /\s*:?([\w-]+):\s*(.*)/
|
1933
2105
|
|
1934
2106
|
directive = $1.downcase
|
1935
2107
|
|
@@ -1939,7 +2111,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1939
2111
|
end
|
1940
2112
|
end
|
1941
2113
|
ensure
|
1942
|
-
unless tokens.length == 1 and
|
2114
|
+
unless tokens.length == 1 and (:on_comment == tokens.first[:kind] or :on_embdoc == tokens.first[:kind]) then
|
1943
2115
|
tokens.reverse_each do |token|
|
1944
2116
|
unget_tk token
|
1945
2117
|
end
|
@@ -1953,6 +2125,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1953
2125
|
# See also RDoc::Markup::PreProcess#handle_directive
|
1954
2126
|
|
1955
2127
|
def read_documentation_modifiers context, allowed
|
2128
|
+
skip_tkspace_without_nl
|
1956
2129
|
directive, value = read_directive allowed
|
1957
2130
|
|
1958
2131
|
return unless directive
|
@@ -1979,15 +2152,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1979
2152
|
container.record_location @top_level
|
1980
2153
|
end
|
1981
2154
|
|
1982
|
-
##
|
1983
|
-
# Removes private comments from +comment+
|
1984
|
-
#--
|
1985
|
-
# TODO remove
|
1986
|
-
|
1987
|
-
def remove_private_comments comment
|
1988
|
-
comment.remove_private
|
1989
|
-
end
|
1990
|
-
|
1991
2155
|
##
|
1992
2156
|
# Scans this Ruby file for Ruby constructs
|
1993
2157
|
|
@@ -1999,29 +2163,33 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
1999
2163
|
parse_top_level_statements @top_level
|
2000
2164
|
|
2001
2165
|
rescue StandardError => e
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
count = i
|
2008
|
-
byte = @scanner.getc
|
2009
|
-
break unless byte
|
2010
|
-
bytes << byte
|
2166
|
+
if @content.include?('<%') and @content.include?('%>') then
|
2167
|
+
# Maybe, this is ERB.
|
2168
|
+
$stderr.puts "\033[2KRDoc detects ERB file. Skips it for compatibility:"
|
2169
|
+
$stderr.puts @file_name
|
2170
|
+
return
|
2011
2171
|
end
|
2012
|
-
|
2013
|
-
|
2172
|
+
|
2173
|
+
if @scanner_point >= @scanner.size
|
2174
|
+
now_line_no = @scanner[@scanner.size - 1][:line_no]
|
2175
|
+
else
|
2176
|
+
now_line_no = peek_tk[:line_no]
|
2177
|
+
end
|
2178
|
+
first_tk_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no }
|
2179
|
+
last_tk_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no + 1 }
|
2180
|
+
last_tk_index = last_tk_index ? last_tk_index - 1 : @scanner.size - 1
|
2181
|
+
code = @scanner[first_tk_index..last_tk_index].map{ |t| t[:text] }.join
|
2014
2182
|
|
2015
2183
|
$stderr.puts <<-EOF
|
2016
2184
|
|
2017
|
-
#{self.class} failure around line #{
|
2185
|
+
#{self.class} failure around line #{now_line_no} of
|
2018
2186
|
#{@file_name}
|
2019
2187
|
|
2020
2188
|
EOF
|
2021
2189
|
|
2022
|
-
unless
|
2190
|
+
unless code.empty? then
|
2191
|
+
$stderr.puts code
|
2023
2192
|
$stderr.puts
|
2024
|
-
$stderr.puts bytes.inspect
|
2025
2193
|
end
|
2026
2194
|
|
2027
2195
|
raise e
|
@@ -2035,53 +2203,52 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
2035
2203
|
# while, until, and for have an optional do
|
2036
2204
|
|
2037
2205
|
def skip_optional_do_after_expression
|
2038
|
-
|
2206
|
+
skip_tkspace_without_nl
|
2039
2207
|
tk = get_tk
|
2040
|
-
end_token = get_end_token tk
|
2041
2208
|
|
2042
2209
|
b_nest = 0
|
2043
2210
|
nest = 0
|
2044
|
-
@scanner.continue = false
|
2045
2211
|
|
2046
2212
|
loop do
|
2047
|
-
|
2048
|
-
|
2213
|
+
break unless tk
|
2214
|
+
case tk[:kind]
|
2215
|
+
when :on_semicolon, :on_nl, :on_ignored_nl then
|
2049
2216
|
break if b_nest.zero?
|
2050
|
-
when
|
2217
|
+
when :on_lparen then
|
2051
2218
|
nest += 1
|
2052
|
-
when
|
2053
|
-
|
2054
|
-
when
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
break if
|
2062
|
-
|
2063
|
-
|
2219
|
+
when :on_rparen then
|
2220
|
+
nest -= 1
|
2221
|
+
when :on_kw then
|
2222
|
+
case tk[:text]
|
2223
|
+
when 'begin'
|
2224
|
+
b_nest += 1
|
2225
|
+
when 'end'
|
2226
|
+
b_nest -= 1
|
2227
|
+
when 'do'
|
2228
|
+
break if nest.zero?
|
2229
|
+
end
|
2230
|
+
when :on_comment, :on_embdoc then
|
2231
|
+
if b_nest.zero? and "\n" == tk[:text][-1] then
|
2232
|
+
break
|
2064
2233
|
end
|
2065
|
-
when nil then
|
2066
|
-
break
|
2067
2234
|
end
|
2068
2235
|
tk = get_tk
|
2069
2236
|
end
|
2070
2237
|
|
2071
|
-
|
2238
|
+
skip_tkspace_without_nl
|
2072
2239
|
|
2073
|
-
get_tk if
|
2240
|
+
get_tk if peek_tk && :on_kw == peek_tk[:kind] && 'do' == peek_tk[:text]
|
2074
2241
|
end
|
2075
2242
|
|
2076
2243
|
##
|
2077
2244
|
# skip the var [in] part of a 'for' statement
|
2078
2245
|
|
2079
2246
|
def skip_for_variable
|
2080
|
-
|
2247
|
+
skip_tkspace_without_nl
|
2081
2248
|
get_tk
|
2082
|
-
|
2249
|
+
skip_tkspace_without_nl
|
2083
2250
|
tk = get_tk
|
2084
|
-
unget_tk(tk) unless
|
2251
|
+
unget_tk(tk) unless :on_kw == tk[:kind] and 'in' == tk[:text]
|
2085
2252
|
end
|
2086
2253
|
|
2087
2254
|
##
|
@@ -2098,8 +2265,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
2098
2265
|
|
2099
2266
|
def skip_tkspace_comment(skip_nl = true)
|
2100
2267
|
loop do
|
2101
|
-
skip_tkspace
|
2102
|
-
|
2268
|
+
skip_nl ? skip_tkspace : skip_tkspace_without_nl
|
2269
|
+
next_tk = peek_tk
|
2270
|
+
return if next_tk.nil? || (:on_comment != next_tk[:kind] and :on_embdoc != next_tk[:kind])
|
2103
2271
|
get_tk
|
2104
2272
|
end
|
2105
2273
|
end
|
@@ -2157,4 +2325,3 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|
2157
2325
|
end
|
2158
2326
|
|
2159
2327
|
end
|
2160
|
-
|