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.

Files changed (277) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.rdoc +8 -7
  3. data/Gemfile +12 -0
  4. data/History.rdoc +48 -4
  5. data/LEGAL.rdoc +2 -2
  6. data/README.rdoc +5 -5
  7. data/Rakefile +73 -155
  8. data/bin/console +7 -0
  9. data/bin/setup +6 -0
  10. data/{bin → exe}/rdoc +0 -0
  11. data/{bin → exe}/ri +0 -0
  12. data/lib/rdoc/alias.rb +1 -0
  13. data/lib/rdoc/anon_class.rb +1 -0
  14. data/lib/rdoc/any_method.rb +59 -14
  15. data/lib/rdoc/attr.rb +1 -0
  16. data/lib/rdoc/class_module.rb +5 -2
  17. data/lib/rdoc/code_object.rb +3 -11
  18. data/lib/rdoc/code_objects.rb +1 -0
  19. data/lib/rdoc/comment.rb +32 -11
  20. data/lib/rdoc/constant.rb +3 -2
  21. data/lib/rdoc/context/section.rb +7 -13
  22. data/lib/rdoc/context.rb +78 -23
  23. data/lib/rdoc/cross_reference.rb +33 -14
  24. data/lib/rdoc/encoding.rb +92 -55
  25. data/lib/rdoc/erb_partial.rb +2 -1
  26. data/lib/rdoc/erbio.rb +8 -3
  27. data/lib/rdoc/extend.rb +1 -0
  28. data/lib/rdoc/generator/darkfish.rb +62 -32
  29. data/lib/rdoc/generator/json_index.rb +8 -5
  30. data/lib/rdoc/generator/markup.rb +3 -12
  31. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  32. data/lib/rdoc/generator/pot/po.rb +84 -0
  33. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  34. data/lib/rdoc/generator/pot.rb +4 -3
  35. data/lib/rdoc/generator/ri.rb +1 -0
  36. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  37. data/lib/rdoc/generator/template/darkfish/_head.rhtml +11 -8
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +2 -2
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +2 -2
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  41. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +2 -2
  42. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  43. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +5 -5
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +5 -5
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +5 -5
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +4 -4
  49. data/lib/rdoc/generator/template/darkfish/class.rhtml +45 -47
  50. data/lib/rdoc/generator/template/darkfish/css/fonts.css +6 -6
  51. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +55 -6
  52. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -4
  53. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +23 -100
  54. data/lib/rdoc/generator/template/darkfish/js/search.js +32 -31
  55. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +15 -16
  56. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +16 -16
  57. data/lib/rdoc/generator/template/json_index/js/navigation.js +4 -41
  58. data/lib/rdoc/generator/template/json_index/js/searcher.js +7 -6
  59. data/lib/rdoc/generator.rb +1 -1
  60. data/lib/rdoc/ghost_method.rb +1 -0
  61. data/lib/rdoc/i18n/locale.rb +2 -1
  62. data/lib/rdoc/i18n/text.rb +5 -4
  63. data/lib/rdoc/i18n.rb +3 -2
  64. data/lib/rdoc/include.rb +1 -0
  65. data/lib/rdoc/known_classes.rb +1 -0
  66. data/lib/rdoc/markdown/entities.rb +1 -0
  67. data/lib/rdoc/markdown/{literals_1_9.kpeg → literals.kpeg} +1 -0
  68. data/lib/rdoc/markdown/{literals_1_9.rb → literals.rb} +1 -4
  69. data/lib/rdoc/markdown.kpeg +94 -51
  70. data/lib/rdoc/markdown.rb +1171 -619
  71. data/lib/rdoc/markup/attr_changer.rb +1 -0
  72. data/lib/rdoc/markup/attr_span.rb +9 -2
  73. data/lib/rdoc/markup/attribute_manager.rb +115 -49
  74. data/lib/rdoc/markup/attributes.rb +7 -6
  75. data/lib/rdoc/markup/blank_line.rb +1 -0
  76. data/lib/rdoc/markup/block_quote.rb +1 -0
  77. data/lib/rdoc/markup/document.rb +1 -0
  78. data/lib/rdoc/markup/formatter.rb +25 -23
  79. data/lib/rdoc/markup/hard_break.rb +1 -0
  80. data/lib/rdoc/markup/heading.rb +4 -3
  81. data/lib/rdoc/markup/include.rb +1 -0
  82. data/lib/rdoc/markup/indented_paragraph.rb +1 -0
  83. data/lib/rdoc/markup/list.rb +1 -0
  84. data/lib/rdoc/markup/list_item.rb +1 -0
  85. data/lib/rdoc/markup/paragraph.rb +1 -0
  86. data/lib/rdoc/markup/parser.rb +78 -61
  87. data/lib/rdoc/markup/pre_process.rb +12 -9
  88. data/lib/rdoc/markup/raw.rb +1 -0
  89. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  90. data/lib/rdoc/markup/rule.rb +1 -0
  91. data/lib/rdoc/markup/to_ansi.rb +1 -0
  92. data/lib/rdoc/markup/to_bs.rb +4 -5
  93. data/lib/rdoc/markup/to_html.rb +71 -25
  94. data/lib/rdoc/markup/to_html_crossref.rb +41 -25
  95. data/lib/rdoc/markup/to_html_snippet.rb +10 -9
  96. data/lib/rdoc/markup/to_joined_paragraph.rb +7 -31
  97. data/lib/rdoc/markup/to_label.rb +10 -9
  98. data/lib/rdoc/markup/to_markdown.rb +9 -8
  99. data/lib/rdoc/markup/to_rdoc.rb +35 -6
  100. data/lib/rdoc/markup/to_table_of_contents.rb +2 -0
  101. data/lib/rdoc/markup/to_test.rb +1 -0
  102. data/lib/rdoc/markup/to_tt_only.rb +3 -2
  103. data/lib/rdoc/markup/verbatim.rb +1 -0
  104. data/lib/rdoc/markup.rb +14 -16
  105. data/lib/rdoc/meta_method.rb +1 -0
  106. data/lib/rdoc/method_attr.rb +2 -1
  107. data/lib/rdoc/mixin.rb +1 -0
  108. data/lib/rdoc/normal_class.rb +3 -2
  109. data/lib/rdoc/normal_module.rb +1 -0
  110. data/lib/rdoc/options.rb +92 -58
  111. data/lib/rdoc/parser/c.rb +219 -223
  112. data/lib/rdoc/parser/changelog.rb +155 -18
  113. data/lib/rdoc/parser/markdown.rb +1 -0
  114. data/lib/rdoc/parser/rd.rb +1 -0
  115. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  116. data/lib/rdoc/parser/ruby.rb +635 -468
  117. data/lib/rdoc/parser/ruby_tools.rb +33 -33
  118. data/lib/rdoc/parser/simple.rb +3 -3
  119. data/lib/rdoc/parser/text.rb +1 -0
  120. data/lib/rdoc/parser.rb +17 -50
  121. data/lib/rdoc/rd/block_parser.rb +66 -65
  122. data/lib/rdoc/rd/block_parser.ry +3 -3
  123. data/lib/rdoc/rd/inline.rb +5 -4
  124. data/lib/rdoc/rd/inline_parser.rb +52 -51
  125. data/lib/rdoc/rd/inline_parser.ry +1 -1
  126. data/lib/rdoc/rd.rb +1 -0
  127. data/lib/rdoc/rdoc.rb +68 -63
  128. data/lib/rdoc/require.rb +1 -0
  129. data/lib/rdoc/ri/driver.rb +133 -58
  130. data/lib/rdoc/ri/formatter.rb +1 -0
  131. data/lib/rdoc/ri/paths.rb +4 -20
  132. data/lib/rdoc/ri/store.rb +1 -0
  133. data/lib/rdoc/ri/task.rb +71 -0
  134. data/lib/rdoc/ri.rb +1 -0
  135. data/lib/rdoc/rubygems_hook.rb +5 -12
  136. data/lib/rdoc/servlet.rb +24 -14
  137. data/lib/rdoc/single_class.rb +1 -0
  138. data/lib/rdoc/stats/normal.rb +20 -21
  139. data/lib/rdoc/stats/quiet.rb +1 -0
  140. data/lib/rdoc/stats/verbose.rb +1 -0
  141. data/lib/rdoc/stats.rb +1 -0
  142. data/lib/rdoc/store.rb +41 -41
  143. data/lib/rdoc/task.rb +2 -3
  144. data/lib/rdoc/text.rb +19 -38
  145. data/lib/rdoc/token_stream.rb +56 -32
  146. data/lib/rdoc/tom_doc.rb +17 -11
  147. data/lib/rdoc/top_level.rb +9 -2
  148. data/lib/rdoc/version.rb +8 -0
  149. data/lib/rdoc.rb +24 -10
  150. data/man/ri.1 +247 -0
  151. data/rdoc.gemspec +248 -0
  152. metadata +43 -236
  153. data/.autotest +0 -24
  154. data/.document +0 -5
  155. data/Manifest.txt +0 -306
  156. data/lib/gauntlet_rdoc.rb +0 -84
  157. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  158. data/lib/rdoc/markdown/literals_1_8.kpeg +0 -18
  159. data/lib/rdoc/markdown/literals_1_8.rb +0 -416
  160. data/lib/rdoc/markup/formatter_test_case.rb +0 -767
  161. data/lib/rdoc/markup/inline.rb +0 -1
  162. data/lib/rdoc/markup/special.rb +0 -40
  163. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -114
  164. data/lib/rdoc/ruby_lex.rb +0 -1377
  165. data/lib/rdoc/ruby_token.rb +0 -460
  166. data/lib/rdoc/test_case.rb +0 -217
  167. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +0 -21
  168. data/test/MarkdownTest_1.0.3/Auto links.text +0 -13
  169. data/test/MarkdownTest_1.0.3/Backslash escapes.text +0 -120
  170. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +0 -11
  171. data/test/MarkdownTest_1.0.3/Code Blocks.text +0 -14
  172. data/test/MarkdownTest_1.0.3/Code Spans.text +0 -6
  173. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +0 -8
  174. data/test/MarkdownTest_1.0.3/Horizontal rules.text +0 -67
  175. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +0 -15
  176. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +0 -69
  177. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +0 -13
  178. data/test/MarkdownTest_1.0.3/Links, inline style.text +0 -12
  179. data/test/MarkdownTest_1.0.3/Links, reference style.text +0 -71
  180. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +0 -20
  181. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +0 -7
  182. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +0 -306
  183. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +0 -888
  184. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +0 -5
  185. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +0 -131
  186. data/test/MarkdownTest_1.0.3/Strong and em together.text +0 -7
  187. data/test/MarkdownTest_1.0.3/Tabs.text +0 -21
  188. data/test/MarkdownTest_1.0.3/Tidyness.text +0 -5
  189. data/test/README +0 -1
  190. data/test/binary.dat +0 -0
  191. data/test/hidden.zip.txt +0 -1
  192. data/test/test.ja.largedoc +0 -3
  193. data/test/test.ja.rdoc +0 -10
  194. data/test/test.ja.txt +0 -8
  195. data/test/test.txt +0 -1
  196. data/test/test_rdoc_alias.rb +0 -13
  197. data/test/test_rdoc_any_method.rb +0 -460
  198. data/test/test_rdoc_attr.rb +0 -190
  199. data/test/test_rdoc_class_module.rb +0 -1492
  200. data/test/test_rdoc_code_object.rb +0 -450
  201. data/test/test_rdoc_comment.rb +0 -504
  202. data/test/test_rdoc_constant.rb +0 -181
  203. data/test/test_rdoc_context.rb +0 -901
  204. data/test/test_rdoc_context_section.rb +0 -130
  205. data/test/test_rdoc_cross_reference.rb +0 -192
  206. data/test/test_rdoc_encoding.rb +0 -227
  207. data/test/test_rdoc_extend.rb +0 -94
  208. data/test/test_rdoc_generator_darkfish.rb +0 -229
  209. data/test/test_rdoc_generator_json_index.rb +0 -324
  210. data/test/test_rdoc_generator_markup.rb +0 -59
  211. data/test/test_rdoc_generator_pot.rb +0 -91
  212. data/test/test_rdoc_generator_pot_po.rb +0 -51
  213. data/test/test_rdoc_generator_pot_po_entry.rb +0 -139
  214. data/test/test_rdoc_generator_ri.rb +0 -78
  215. data/test/test_rdoc_i18n_locale.rb +0 -73
  216. data/test/test_rdoc_i18n_text.rb +0 -123
  217. data/test/test_rdoc_include.rb +0 -108
  218. data/test/test_rdoc_markdown.rb +0 -980
  219. data/test/test_rdoc_markdown_test.rb +0 -1884
  220. data/test/test_rdoc_markup.rb +0 -95
  221. data/test/test_rdoc_markup_attribute_manager.rb +0 -364
  222. data/test/test_rdoc_markup_attributes.rb +0 -39
  223. data/test/test_rdoc_markup_document.rb +0 -207
  224. data/test/test_rdoc_markup_formatter.rb +0 -175
  225. data/test/test_rdoc_markup_hard_break.rb +0 -31
  226. data/test/test_rdoc_markup_heading.rb +0 -29
  227. data/test/test_rdoc_markup_include.rb +0 -19
  228. data/test/test_rdoc_markup_indented_paragraph.rb +0 -53
  229. data/test/test_rdoc_markup_paragraph.rb +0 -32
  230. data/test/test_rdoc_markup_parser.rb +0 -1680
  231. data/test/test_rdoc_markup_pre_process.rb +0 -473
  232. data/test/test_rdoc_markup_raw.rb +0 -22
  233. data/test/test_rdoc_markup_to_ansi.rb +0 -369
  234. data/test/test_rdoc_markup_to_bs.rb +0 -366
  235. data/test/test_rdoc_markup_to_html.rb +0 -662
  236. data/test/test_rdoc_markup_to_html_crossref.rb +0 -225
  237. data/test/test_rdoc_markup_to_html_snippet.rb +0 -711
  238. data/test/test_rdoc_markup_to_joined_paragraph.rb +0 -32
  239. data/test/test_rdoc_markup_to_label.rb +0 -112
  240. data/test/test_rdoc_markup_to_markdown.rb +0 -389
  241. data/test/test_rdoc_markup_to_rdoc.rb +0 -377
  242. data/test/test_rdoc_markup_to_table_of_contents.rb +0 -126
  243. data/test/test_rdoc_markup_to_tt_only.rb +0 -246
  244. data/test/test_rdoc_markup_verbatim.rb +0 -29
  245. data/test/test_rdoc_method_attr.rb +0 -193
  246. data/test/test_rdoc_normal_class.rb +0 -47
  247. data/test/test_rdoc_normal_module.rb +0 -42
  248. data/test/test_rdoc_options.rb +0 -766
  249. data/test/test_rdoc_parser.rb +0 -327
  250. data/test/test_rdoc_parser_c.rb +0 -1896
  251. data/test/test_rdoc_parser_changelog.rb +0 -315
  252. data/test/test_rdoc_parser_markdown.rb +0 -61
  253. data/test/test_rdoc_parser_rd.rb +0 -55
  254. data/test/test_rdoc_parser_ruby.rb +0 -3322
  255. data/test/test_rdoc_parser_simple.rb +0 -115
  256. data/test/test_rdoc_rd.rb +0 -30
  257. data/test/test_rdoc_rd_block_parser.rb +0 -535
  258. data/test/test_rdoc_rd_inline.rb +0 -63
  259. data/test/test_rdoc_rd_inline_parser.rb +0 -177
  260. data/test/test_rdoc_rdoc.rb +0 -455
  261. data/test/test_rdoc_require.rb +0 -25
  262. data/test/test_rdoc_ri_driver.rb +0 -1436
  263. data/test/test_rdoc_ri_paths.rb +0 -155
  264. data/test/test_rdoc_ruby_lex.rb +0 -421
  265. data/test/test_rdoc_ruby_token.rb +0 -19
  266. data/test/test_rdoc_rubygems_hook.rb +0 -251
  267. data/test/test_rdoc_servlet.rb +0 -534
  268. data/test/test_rdoc_single_class.rb +0 -20
  269. data/test/test_rdoc_stats.rb +0 -722
  270. data/test/test_rdoc_store.rb +0 -993
  271. data/test/test_rdoc_task.rb +0 -173
  272. data/test/test_rdoc_text.rb +0 -557
  273. data/test/test_rdoc_token_stream.rb +0 -42
  274. data/test/test_rdoc_tom_doc.rb +0 -520
  275. data/test/test_rdoc_top_level.rb +0 -287
  276. data/test/xref_data.rb +0 -76
  277. data/test/xref_test_case.rb +0 -67
@@ -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
- @scanner = RDoc::RubyLex.new content, @options
168
- @scanner.exception_on_syntax_error = false
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.name
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.force_encoding @encoding if @encoding
243
+ comment = ''.dup
244
+ comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
229
245
  first_line = true
230
- first_comment_tk_class = nil
246
+ first_comment_tk_kind = nil
247
+ line_no = nil
231
248
 
232
249
  tk = get_tk
233
250
 
234
- while TkCOMMENT === tk
235
- if first_line and tk.text =~ /\A#!/ then
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 tk.text =~ /\A#\s*-\*-/ then
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 first_comment_tk_class and not first_comment_tk_class === tk
244
- first_comment_tk_class = tk.class
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 << tk.text << "\n"
266
+ comment << comment_body
248
267
  tk = get_tk
249
268
 
250
- if TkNL === tk then
251
- skip_tkspace false
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
- get_tkread
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.name, @top_level if mod
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. Returns false if TkFALSE or TkNIL are
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
- case tk
314
- when TkTRUE
330
+ if :on_kw == tk[:kind] && 'true' == tk[:text]
315
331
  true
316
- when TkFALSE, TkNIL
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
- case name_t
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
- skip_tkspace false
343
- given_name << name_t.name
357
+ skip_tkspace_without_nl
358
+ given_name << name_t[:text]
344
359
 
345
- while TkCOLON2 === peek_tk do
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.name
364
+ container = container.find_module_named name_t[:text]
348
365
  container ||=
349
366
  if ignore_constants then
350
- RDoc::Context.new
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.name
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 false
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
- given_name << '::' << name_t.name
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
- skip_tkspace false
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
- case peek_tk
376
- when TkSELF then return 'self'
377
- when TkGVAR then return ''
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
- skip_tkspace false
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 TkNL, TkCOMMENT, TkSEMICOLON then
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
- skip_tkspace false
440
+ skip_tkspace_without_nl
405
441
  tk = get_tk
406
442
 
407
- while TkCOLON2 === tk or TkCOLON3 === tk or TkCONSTANT === tk do
408
- res += tk.name
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 a constant that may be surrounded by parens
453
+ # Get an included module that may be surrounded by parens
418
454
 
419
- def get_constant_with_optional_parens
420
- skip_tkspace false
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 TkLPAREN === (tk = peek_tk) or TkfLPAREN === tk do
425
- get_tk
426
- skip_tkspace
427
- nest += 1
428
- end
429
-
430
- name = get_constant
431
-
432
- while nest > 0
433
- skip_tkspace
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
- name
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 TkLPAREN, TkfLPAREN
452
- TkRPAREN
453
- when TkRPAREN
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
- TkNL
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.name)
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.name
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.name.split("::").inject(Object) do |state, item|
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.name}. Assuming it's a module")
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.name, sclass
589
+ container = prev_container.add_class type, name_t[:text], sclass
493
590
  else
494
- container = prev_container.add_module type, name_t.name
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 TkSYMBOL then
510
- text = tk.text.sub(/^:/, '')
605
+ case tk[:kind]
606
+ when :on_symbol then
607
+ text = tk[:text].sub(/^:/, '')
511
608
 
512
- if TkASSIGN === peek_tk then
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 TkId, TkOp then
519
- tk.name
520
- when TkAMPER,
521
- TkDSTRING,
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 context, comment
553
- @preprocess.handle comment, context do |directive, param|
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
- context.set_current_section param, comment.dup
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
- remove_private_comments comment
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
- prefix << "#{@scanner.line_no}:#{@scanner.char_no}:" if @scanner
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
- offset = tk.seek
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
- skip_tkspace false
693
+ skip_tkspace_without_nl
601
694
  tk = get_tk
602
695
 
603
- if TkCOMMA === tk then
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
- offset = tk.seek
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.name
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
- offset = tk.seek
656
- line_no = tk.line_no
745
+ line_no = tk[:line_no]
657
746
 
658
747
  skip_tkspace
659
748
 
660
- if TkLPAREN === peek_tk then
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 TkCOMMA === peek_tk then
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 TkLPAREN, TkfLPAREN
700
- TkRPAREN
701
- when TkRPAREN
784
+ end_token = case tk[:kind]
785
+ when :on_lparen
786
+ :on_rparen
787
+ when :on_rparen
702
788
  return ""
703
789
  else
704
- TkNL
790
+ :on_nl
705
791
  end
706
792
  nest = 0
707
793
 
708
794
  loop do
709
- case tk
710
- when TkSEMICOLON
795
+ break if tk.nil?
796
+ case tk[:kind]
797
+ when :on_semicolon
711
798
  break
712
- when TkLPAREN, TkfLPAREN
799
+ when :on_lparen
713
800
  nest += 1
714
801
  when end_token
715
- if end_token == TkRPAREN
802
+ if end_token == :on_rparen
716
803
  nest -= 1
717
- break if @scanner.lex_state == :EXPR_END and nest <= 0
804
+ break if RDoc::Parser::RipperStateLex.end?(tk) and nest <= 0
718
805
  else
719
- break unless @scanner.continue
806
+ break if RDoc::Parser::RipperStateLex.end?(tk)
720
807
  end
721
- when TkCOMMENT, TkASSIGN, TkOPASGN
808
+ when :on_comment, :on_embdoc
722
809
  unget_tk(tk)
723
810
  break
724
- when nil then
725
- break
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
- offset = tk.seek
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
- cls =
744
- case name_t
745
- when TkCONSTANT
746
- parse_class_regular container, declaration_context, single,
747
- name_t, given_name, comment
748
- when TkLSHFT
749
- case name = get_class_specification
750
- when 'self', container.name
751
- parse_statements container, SINGLE
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
- warn "Expected class name or '<<'. Got #{name_t.class}: #{name_t.text.inspect}"
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
- if TkLT === peek_tk then
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
- offset = tk.seek
850
- line_no = tk.line_no
940
+ line_no = tk[:line_no]
851
941
 
852
- name = tk.name
853
- skip_tkspace false
942
+ name = tk[:text]
943
+ skip_tkspace_without_nl
854
944
 
855
945
  return unless name =~ /^\w+$/
856
946
 
857
- eq_tk = get_tk
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, ignore_constants
951
+ container, name_t, _, new_modules = get_class_or_module container, true
864
952
 
865
- name = name_t.name
953
+ name = name_t[:text]
954
+ end
866
955
 
867
- eq_tk = get_tk
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 TkASSIGN === eq_tk then
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
- if TkGT === peek_tk then
876
- unget_tk eq_tk
877
- return
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.replace body
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
- case tk
909
- when TkSEMICOLON then
1016
+ break if tk.nil?
1017
+ if :on_semicolon == tk[:kind] then
910
1018
  break if nest <= 0
911
- when TkLPAREN, TkfLPAREN, TkLBRACE, TkfLBRACE, TkLBRACK, TkfLBRACK,
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
- when TkRPAREN, TkRBRACE, TkRBRACK, TkEND then
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
- when TkCOMMENT then
917
- if nest <= 0 and stop_at_EXPR_END then
918
- unget_tk tk
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
- when TkCONSTANT then
925
- rhs_name << tk.name
1039
+ elsif :on_const == tk[:kind] then
1040
+ rhs_name << tk[:text]
926
1041
 
927
- if nest <= 0 and TkNL === peek_tk then
928
- create_module_alias container, constant, rhs_name
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
- when TkNL then
932
- if nest <= 0 and stop_at_EXPR_END then
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
- when TkCOLON2, TkCOLON3 then
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.char_no
954
- offset = tk.seek
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
- singleton = !!text.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
1070
+ comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
1071
+ singleton = !!$~
960
1072
 
961
1073
  co =
962
- if text.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
963
- parse_comment_ghost container, text, $1, column, line_no, comment
964
- elsif text.sub!(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
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 = TkSPACE.new 0, 1, 1
1002
- indent.set_text " " * column
1003
-
1004
- position_comment = TkCOMMENT.new 0, line_no, 1
1005
- position_comment.set_text "# File #{@top_level.relative_name}, line #{line_no}"
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
- offset = tk.seek
1036
- line_no = tk.line_no
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 = TkSPACE.new 0, 1, 1
1047
- indent.set_text " " * offset
1048
-
1049
- position_comment = TkCOMMENT.new 0, line_no, 1
1050
- position_comment.set_text "# File #{@top_level.relative_name}, line #{line_no}"
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 = get_constant_with_optional_parens
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 unless TkCOMMA === peek_tk
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.name
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
- if comment.text.sub!(/^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
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.char_no
1187
- offset = tk.seek
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
- skip_tkspace false
1307
+ skip_tkspace_without_nl
1195
1308
 
1196
- singleton = !!comment.text.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
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 = TkSPACE.new 0, 1, 1
1212
- indent.set_text " " * column
1213
-
1214
- position_comment = TkCOMMENT.new 0, line_no, 1
1215
- position_comment.value = "# File #{@top_level.relative_name}, line #{line_no}"
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
- case name_t
1241
- when TkSYMBOL then
1242
- name_t.text[1..-1]
1243
- when TkSTRING then
1244
- name_t.value[1..-2]
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.name}'"
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
- case tk
1271
- when TkSEMICOLON then
1382
+ if :on_semicolon == tk[:kind] then
1272
1383
  break
1273
- when TkNL then
1274
- break unless last_tk and TkCOMMA === last_tk
1275
- when TkSPACE then
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
- when TkDO then
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.char_no
1295
- offset = tk.seek
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 = TkSPACE.new 0, 1, 1
1318
- indent.set_text " " * column
1319
-
1320
- token = TkCOMMENT.new 0, line_no, 1
1321
- token.set_text "# File #{@top_level.relative_name}, line #{line_no}"
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 = skip_tkspace
1496
+ back_tk = skip_tkspace_without_nl
1388
1497
  singleton = false
1389
1498
 
1390
- case dot = get_tk
1391
- when TkDOT, TkCOLON2 then
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
- case name_t
1413
- when TkSTAR, TkAMPER then
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 name_t.respond_to? :name then
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.name
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
- name =
1436
- case name_t
1437
- when TkSELF, TkMOD then
1438
- case name_t2
1439
- # NOTE: work around '[' being consumed early and not being re-tokenized
1440
- # as a TkAREF
1441
- when TkfLBRACK then
1442
- get_tk
1443
- '[]'
1444
- else
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
- container = get_method_container container, name_t
1553
+ container = get_method_container container, name_t
1451
1554
 
1452
- return unless container
1555
+ return unless container
1453
1556
 
1454
- name
1455
- when TkIDENTIFIER, TkIVAR, TkGVAR then
1456
- parse_method_dummy container
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
- nil
1459
- when TkTRUE, TkFALSE, TkNIL then
1460
- klass_name = "#{name_t.name.capitalize}Class"
1461
- container = @store.find_class_named klass_name
1462
- container ||= @top_level.add_class RDoc::NormalClass, klass_name
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
- name_t2.name
1465
- else
1466
- warn "unexpected method name token #{name_t.inspect}"
1467
- # break
1468
- skip_method container
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
- nil
1471
- end
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
- skip_tkspace false
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
- loop do
1489
- case tk
1490
- when TkSEMICOLON then
1592
+ while tk != nil do
1593
+ case tk[:kind]
1594
+ when :on_semicolon then
1491
1595
  break if nest == 0
1492
- when TkLBRACE, TkfLBRACE then
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 TkRBRACE then
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 TkLPAREN, TkfLPAREN then
1609
+ when :on_lparen then
1502
1610
  nest += 1
1503
- when end_token then
1504
- if end_token == TkRPAREN
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 unless @scanner.continue
1616
+ break
1509
1617
  end
1510
- when TkRPAREN then
1618
+ when :on_rparen then
1511
1619
  nest -= 1
1512
- when method && method.block_params.nil? && TkCOMMENT then
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
- when nil then
1519
- break
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
- skip_tkspace false
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.name
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 TkLPAREN === tk then
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.text if TkSTRING === 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
- skip_tkspace false
1708
+ skip_tkspace_without_nl
1592
1709
 
1593
1710
  while tk = get_tk
1594
- case tk
1595
- when TkNL, TkSEMICOLON then
1711
+ case tk[:kind]
1712
+ when :on_nl, :on_semicolon, :on_comment then
1596
1713
  break
1597
- when TkCOMMA then
1598
- skip_tkspace false
1714
+ when :on_comma then
1715
+ skip_tkspace_without_nl
1599
1716
 
1600
- get_tk if TkNL === peek_tk
1717
+ get_tk if :on_nl == peek_tk[:kind]
1601
1718
  end
1602
1719
 
1603
- skip_tkspace false
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.force_encoding @encoding if @encoding
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 TkCOMMENT === tk
1752
+ non_comment_seen = true unless (:on_comment == tk[:kind] or :on_embdoc == tk[:kind])
1625
1753
 
1626
- case tk
1627
- when TkNL then
1628
- skip_tkspace
1629
- tk = get_tk
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 TkCOMMENT === tk then
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.force_encoding @encoding if @encoding
1784
+ comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
1639
1785
  end
1640
1786
 
1641
- while TkCOMMENT === tk do
1642
- comment << tk.text << "\n"
1643
-
1644
- tk = get_tk
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 TkNL === tk then
1647
- skip_tkspace false # leading spaces
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 TkCLASS then
1672
- parse_class container, single, tk, comment
1820
+ when :on_kw then
1821
+ case tk[:text]
1822
+ when 'class' then
1823
+ parse_class container, single, tk, comment
1673
1824
 
1674
- when TkMODULE then
1675
- parse_module container, single, tk, comment
1825
+ when 'module' then
1826
+ parse_module container, single, tk, comment
1676
1827
 
1677
- when TkDEF then
1678
- parse_method container, single, tk, comment
1828
+ when 'def' then
1829
+ parse_method container, single, tk, comment
1679
1830
 
1680
- when TkCONSTANT then
1681
- unless parse_constant container, tk, comment, current_method then
1682
- try_parse_comment = true
1683
- end
1831
+ when 'alias' then
1832
+ parse_alias container, single, tk, comment unless current_method
1684
1833
 
1685
- when TkALIAS then
1686
- parse_alias container, single, tk, comment unless current_method
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
- when TkYIELD then
1689
- if current_method.nil? then
1690
- warn "Warning: yield outside of method" if container.document_self
1691
- else
1692
- parse_yield container, single, tk, current_method
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
- # Until and While can have a 'do', which shouldn't increase the nesting.
1696
- # We can't solve the general case, but we can handle most occurrences by
1697
- # ignoring a do at the end of a line.
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
- when TkUNTIL, TkWHILE then
1700
- nest += 1
1701
- skip_optional_do_after_expression
1851
+ # 'for' is trickier
1852
+ when 'for' then
1853
+ nest += 1
1854
+ skip_for_variable
1855
+ skip_optional_do_after_expression
1702
1856
 
1703
- # 'for' is trickier
1704
- when TkFOR then
1705
- nest += 1
1706
- skip_for_variable
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
- when TkCASE, TkDO, TkIF, TkUNLESS, TkBEGIN then
1710
- nest += 1
1862
+ when 'super' then
1863
+ current_method.calls_super = true if current_method
1864
+
1865
+ when 'rescue' then
1866
+ parse_rescue
1711
1867
 
1712
- when TkSUPER then
1713
- current_method.calls_super = true if current_method
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
- when TkRESCUE then
1716
- parse_rescue
1875
+ return
1876
+ end
1877
+ end
1717
1878
 
1718
- when TkIDENTIFIER then
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.name
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.force_encoding @encoding if @encoding
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
- case tk = get_tk
1774
- when TkLPAREN
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 TkRPAREN
1952
+ case (tk2 = get_tk)[:kind]
1953
+ when :on_rparen
1798
1954
  break
1799
- when TkCOMMA
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
- skip_tkspace false
1979
+ skip_tkspace_without_nl
1824
1980
 
1825
1981
  tk1 = get_tk
1826
- unless TkCOMMA === tk1 then
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
- case tk = get_tk
1846
- when TkSYMBOL
1847
- tk.text.sub(/^:/, '')
1848
- when TkSTRING
1849
- eval @read[-1]
1850
- when TkDSTRING, TkIDENTIFIER then
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
- case peek_tk
1885
- # Ryan Davis suggested the extension to ignore modifiers, because he
1886
- # often writes
1887
- #
1888
- # protected unless $TESTING
1889
- #
1890
- when TkNL, TkUNLESS_MOD, TkIF_MOD, TkSEMICOLON then
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
- case tk
1929
- when TkNL, TkDEF then
2101
+ if :on_nl == tk[:kind] or (:on_kw == tk[:kind] && 'def' == tk[:text]) then
1930
2102
  return
1931
- when TkCOMMENT then
1932
- return unless tk.text =~ /\s*:?([\w-]+):\s*(.*)/
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 TkCOMMENT === tokens.first then
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
- bytes = ''
2003
-
2004
- 20.times do @scanner.ungetc end
2005
- count = 0
2006
- 60.times do |i|
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
- count -= 20
2013
- count.times do @scanner.ungetc end
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 #{@scanner.line_no} of
2185
+ #{self.class} failure around line #{now_line_no} of
2018
2186
  #{@file_name}
2019
2187
 
2020
2188
  EOF
2021
2189
 
2022
- unless bytes.empty? then
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
- skip_tkspace false
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
- case tk
2048
- when TkSEMICOLON then
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 TkLPAREN, TkfLPAREN then
2217
+ when :on_lparen then
2051
2218
  nest += 1
2052
- when TkBEGIN then
2053
- b_nest += 1
2054
- when TkEND then
2055
- b_nest -= 1
2056
- when TkDO
2057
- break if nest.zero?
2058
- when end_token then
2059
- if end_token == TkRPAREN
2060
- nest -= 1
2061
- break if @scanner.lex_state == :EXPR_END and nest.zero?
2062
- else
2063
- break unless @scanner.continue
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
- skip_tkspace false
2238
+ skip_tkspace_without_nl
2072
2239
 
2073
- get_tk if TkDO === peek_tk
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
- skip_tkspace false
2247
+ skip_tkspace_without_nl
2081
2248
  get_tk
2082
- skip_tkspace false
2249
+ skip_tkspace_without_nl
2083
2250
  tk = get_tk
2084
- unget_tk(tk) unless TkIN === tk
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 skip_nl
2102
- return unless TkCOMMENT === peek_tk
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
-