rdoc 3.9.5 → 3.10.pre.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 (183) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -3
  3. data/History.txt +63 -13
  4. data/LICENSE.rdoc +57 -0
  5. data/Manifest.txt +60 -6
  6. data/Rakefile +24 -12
  7. data/TODO.rdoc +30 -0
  8. data/bin/rdoc +0 -2
  9. data/lib/rdoc.rb +55 -2
  10. data/lib/rdoc/alias.rb +0 -2
  11. data/lib/rdoc/anon_class.rb +0 -2
  12. data/lib/rdoc/any_method.rb +0 -3
  13. data/lib/rdoc/attr.rb +0 -2
  14. data/lib/rdoc/class_module.rb +40 -7
  15. data/lib/rdoc/code_object.rb +1 -3
  16. data/lib/rdoc/code_objects.rb +3 -21
  17. data/lib/rdoc/comment.rb +225 -0
  18. data/lib/rdoc/constant.rb +0 -2
  19. data/lib/rdoc/context.rb +37 -120
  20. data/lib/rdoc/context/section.rb +114 -0
  21. data/lib/rdoc/cross_reference.rb +16 -7
  22. data/lib/rdoc/encoding.rb +0 -2
  23. data/lib/rdoc/gauntlet.rb +1 -1
  24. data/lib/rdoc/generator.rb +7 -2
  25. data/lib/rdoc/generator/darkfish.rb +126 -20
  26. data/lib/rdoc/generator/json_index.rb +240 -0
  27. data/lib/rdoc/generator/markup.rb +17 -54
  28. data/lib/rdoc/generator/ri.rb +0 -3
  29. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
  41. data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
  42. data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
  43. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  44. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  45. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  46. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  47. data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
  48. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
  49. data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
  50. data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
  51. data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
  52. data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
  53. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
  54. data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
  55. data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
  56. data/lib/rdoc/ghost_method.rb +0 -2
  57. data/lib/rdoc/include.rb +0 -2
  58. data/lib/rdoc/markup.rb +204 -43
  59. data/lib/rdoc/markup/attr_changer.rb +25 -0
  60. data/lib/rdoc/markup/attr_span.rb +29 -0
  61. data/lib/rdoc/markup/attribute.rb +51 -0
  62. data/lib/rdoc/markup/document.rb +22 -1
  63. data/lib/rdoc/markup/formatter.rb +4 -11
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -2
  65. data/lib/rdoc/markup/heading.rb +44 -0
  66. data/lib/rdoc/markup/include.rb +42 -0
  67. data/lib/rdoc/markup/inline.rb +1 -144
  68. data/lib/rdoc/markup/list.rb +2 -1
  69. data/lib/rdoc/markup/parser.rb +6 -16
  70. data/lib/rdoc/markup/pre_process.rb +64 -10
  71. data/lib/rdoc/markup/raw.rb +1 -1
  72. data/lib/rdoc/markup/special.rb +40 -0
  73. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
  74. data/lib/rdoc/markup/to_ansi.rb +0 -2
  75. data/lib/rdoc/markup/to_bs.rb +0 -2
  76. data/lib/rdoc/markup/to_html.rb +102 -34
  77. data/lib/rdoc/markup/to_html_crossref.rb +36 -5
  78. data/lib/rdoc/markup/to_html_snippet.rb +270 -0
  79. data/lib/rdoc/markup/to_label.rb +55 -0
  80. data/lib/rdoc/markup/to_rdoc.rb +0 -3
  81. data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
  82. data/lib/rdoc/markup/to_test.rb +0 -3
  83. data/lib/rdoc/markup/to_tt_only.rb +0 -3
  84. data/lib/rdoc/markup/verbatim.rb +18 -0
  85. data/lib/rdoc/meta_method.rb +0 -2
  86. data/lib/rdoc/method_attr.rb +17 -1
  87. data/lib/rdoc/normal_class.rb +0 -2
  88. data/lib/rdoc/normal_module.rb +0 -2
  89. data/lib/rdoc/options.rb +18 -3
  90. data/lib/rdoc/parser.rb +74 -42
  91. data/lib/rdoc/parser/c.rb +79 -118
  92. data/lib/rdoc/parser/rd.rb +22 -0
  93. data/lib/rdoc/parser/ruby.rb +86 -54
  94. data/lib/rdoc/parser/simple.rb +21 -9
  95. data/lib/rdoc/parser/text.rb +11 -0
  96. data/lib/rdoc/rd.rb +95 -0
  97. data/lib/rdoc/rd/block_parser.ry +638 -0
  98. data/lib/rdoc/rd/inline.rb +71 -0
  99. data/lib/rdoc/rd/inline_parser.ry +575 -0
  100. data/lib/rdoc/rdoc.rb +8 -23
  101. data/lib/rdoc/require.rb +0 -2
  102. data/lib/rdoc/ri.rb +4 -2
  103. data/lib/rdoc/ri/driver.rb +2 -6
  104. data/lib/rdoc/ri/store.rb +0 -1
  105. data/lib/rdoc/ruby_lex.rb +43 -20
  106. data/lib/rdoc/ruby_token.rb +44 -2
  107. data/lib/rdoc/single_class.rb +0 -2
  108. data/lib/rdoc/stats.rb +0 -5
  109. data/lib/rdoc/task.rb +2 -6
  110. data/lib/rdoc/test_case.rb +59 -0
  111. data/lib/rdoc/text.rb +42 -30
  112. data/lib/rdoc/token_stream.rb +45 -0
  113. data/lib/rdoc/tom_doc.rb +232 -0
  114. data/lib/rdoc/top_level.rb +36 -4
  115. data/test/test_attribute_manager.rb +26 -29
  116. data/test/test_rdoc_any_method.rb +2 -26
  117. data/test/test_rdoc_attr.rb +4 -4
  118. data/test/test_rdoc_class_module.rb +95 -12
  119. data/test/test_rdoc_code_object.rb +10 -3
  120. data/test/test_rdoc_comment.rb +504 -0
  121. data/test/test_rdoc_context.rb +60 -11
  122. data/test/test_rdoc_context_section.rb +16 -17
  123. data/test/test_rdoc_cross_reference.rb +17 -2
  124. data/test/test_rdoc_encoding.rb +4 -7
  125. data/test/test_rdoc_generator_darkfish.rb +12 -11
  126. data/test/test_rdoc_generator_json_index.rb +255 -0
  127. data/test/test_rdoc_generator_markup.rb +56 -0
  128. data/test/test_rdoc_generator_ri.rb +8 -11
  129. data/test/test_rdoc_markup.rb +9 -5
  130. data/test/test_rdoc_markup_attribute_manager.rb +5 -8
  131. data/test/test_rdoc_markup_document.rb +34 -6
  132. data/test/test_rdoc_markup_formatter.rb +11 -13
  133. data/test/test_rdoc_markup_heading.rb +20 -0
  134. data/test/test_rdoc_markup_include.rb +19 -0
  135. data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
  136. data/test/test_rdoc_markup_paragraph.rb +2 -5
  137. data/test/test_rdoc_markup_parser.rb +87 -7
  138. data/test/test_rdoc_markup_pre_process.rb +60 -9
  139. data/test/test_rdoc_markup_raw.rb +4 -6
  140. data/test/test_rdoc_markup_to_ansi.rb +1 -4
  141. data/test/test_rdoc_markup_to_bs.rb +1 -4
  142. data/test/test_rdoc_markup_to_html.rb +170 -31
  143. data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
  144. data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
  145. data/test/test_rdoc_markup_to_label.rb +50 -0
  146. data/test/test_rdoc_markup_to_rdoc.rb +1 -4
  147. data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
  148. data/test/test_rdoc_markup_to_tt_only.rb +1 -4
  149. data/test/test_rdoc_markup_verbatim.rb +16 -0
  150. data/test/test_rdoc_method_attr.rb +16 -1
  151. data/test/test_rdoc_options.rb +17 -7
  152. data/test/test_rdoc_parser.rb +75 -6
  153. data/test/test_rdoc_parser_c.rb +56 -104
  154. data/test/test_rdoc_parser_rd.rb +52 -0
  155. data/test/test_rdoc_parser_ruby.rb +264 -323
  156. data/test/test_rdoc_parser_simple.rb +33 -17
  157. data/test/test_rdoc_rd.rb +30 -0
  158. data/test/test_rdoc_rd_block_parser.rb +527 -0
  159. data/test/test_rdoc_rd_inline.rb +63 -0
  160. data/test/test_rdoc_rd_inline_parser.rb +173 -0
  161. data/test/test_rdoc_rdoc.rb +7 -9
  162. data/test/test_rdoc_ri_driver.rb +10 -15
  163. data/test/test_rdoc_ri_paths.rb +6 -6
  164. data/test/test_rdoc_ri_store.rb +6 -13
  165. data/test/test_rdoc_ruby_lex.rb +53 -5
  166. data/test/test_rdoc_rubygems_hook.rb +2 -1
  167. data/test/test_rdoc_stats.rb +83 -103
  168. data/test/test_rdoc_task.rb +5 -4
  169. data/test/test_rdoc_text.rb +156 -11
  170. data/test/test_rdoc_token_stream.rb +42 -0
  171. data/test/test_rdoc_tom_doc.rb +458 -0
  172. data/test/test_rdoc_top_level.rb +49 -2
  173. data/test/xref_test_case.rb +4 -8
  174. metadata +217 -111
  175. metadata.gz.sig +0 -0
  176. checksums.yaml +0 -7
  177. checksums.yaml.gz.sig +0 -0
  178. data/CVE-2013-0256.rdoc +0 -49
  179. data/LICENSE.txt +0 -57
  180. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
  181. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  182. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  183. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
@@ -0,0 +1,638 @@
1
+ class BlockParser
2
+
3
+ preclow
4
+ nonassoc DUMMY
5
+ left ITEMLISTLINE
6
+ ENUMLISTLINE
7
+ DESCLISTLINE
8
+ METHODLISTLINE
9
+ STRINGLINE
10
+ prechigh
11
+
12
+ token STRINGLINE
13
+ ITEMLISTLINE
14
+ ENUMLISTLINE
15
+ DESCLISTLINE
16
+ METHODLISTLINE
17
+ WHITELINE
18
+ SUBTREE
19
+ HEADLINE
20
+ INCLUDE
21
+ INDENT
22
+ DEDENT
23
+ DUMMY
24
+
25
+ rule
26
+ document : blocks { result = RDoc::Markup::Document.new(*val[0]) }
27
+ | { raise ParseError, "file empty" }
28
+ ;
29
+
30
+ blocks : blocks block { result = val[0].concat val[1] }
31
+ | block { result = val[0] }
32
+ ;
33
+
34
+ block : textblock { result = val }
35
+ | verbatim { result = val }
36
+ | lists
37
+ | headline { result = val }
38
+ | include { result = val }
39
+ | WHITELINE { result = [RDoc::Markup::BlankLine.new] }
40
+ | SUBTREE { result = val[0].parts }
41
+ ;
42
+
43
+ headline : HEADLINE {
44
+ # val[0] is like [level, title]
45
+ title = @inline_parser.parse(val[0][1])
46
+ result = RDoc::Markup::Heading.new(val[0][0], title)
47
+ }
48
+ ;
49
+
50
+ include : INCLUDE {
51
+ result = RDoc::Markup::Include.new val[0], @include_path
52
+ }
53
+ ;
54
+
55
+ textblock : textblockcontent = DUMMY {
56
+ # val[0] is Array of String
57
+ result = paragraph val[0]
58
+ }
59
+ ;
60
+
61
+ textblockcontent : textblockcontent STRINGLINE { result << val[1].rstrip }
62
+ | STRINGLINE { result = [val[0].rstrip] }
63
+ ;
64
+
65
+ verbatim : INDENT verbatimcontent DEDENT {
66
+ # val[1] is Array of String
67
+ content = cut_off val[1]
68
+ result = RDoc::Markup::Verbatim.new(*content)
69
+
70
+ # imform to lexer.
71
+ @in_verbatim = false
72
+ }
73
+ ;
74
+
75
+ verbatim_after_lists : verbatimcontent {
76
+ # val[0] is Array of String
77
+ content = cut_off val[0]
78
+ result = RDoc::Markup::Verbatim.new(*content)
79
+
80
+ # imform to lexer.
81
+ @in_verbatim = false
82
+ }
83
+ ;
84
+
85
+ verbatimcontent : verbatimcontent STRINGLINE {
86
+ result << val[1]
87
+ } | verbatimcontent INDENT verbatimcontent DEDENT {
88
+ result.concat val[2]
89
+ } | verbatimcontent WHITELINE {
90
+ result << "\n"
91
+ } | STRINGLINE {
92
+ result = val
93
+ # inform to lexer.
94
+ @in_verbatim = true
95
+ }
96
+ ;
97
+
98
+ list : itemlist
99
+ | enumlist
100
+ | desclist
101
+ | methodlist
102
+ ;
103
+
104
+ lists : lists2 = DUMMY {
105
+ result = val[0]
106
+ } | INDENT lists2 DEDENT {
107
+ result = val[1]
108
+ } | INDENT lists2 verbatim_after_lists DEDENT {
109
+ result = val[1].push(val[2])
110
+ }
111
+ ;
112
+
113
+ lists2 : lists2 list { result = val[0] << val[1] }
114
+ | list { result = [val[0]] }
115
+ ;
116
+
117
+ itemlist : itemlistitems = DUMMY {
118
+ result = RDoc::Markup::List.new :BULLET, *val[0]
119
+ }
120
+ ;
121
+
122
+ itemlistitems : itemlistitems itemlistitem { result.push(val[1]) }
123
+ | itemlistitem { result = val }
124
+ ;
125
+
126
+ itemlistitem : first_textblock_in_itemlist other_blocks_in_list DEDENT {
127
+ result = RDoc::Markup::ListItem.new nil, val[0], *val[1]
128
+ }
129
+ ;
130
+
131
+ enumlist : enumlistitems = DUMMY {
132
+ result = RDoc::Markup::List.new :NUMBER, *val[0]
133
+ }
134
+ ;
135
+
136
+ enumlistitems : enumlistitems enumlistitem { result.push(val[1]) }
137
+ | enumlistitem { result = val }
138
+ ;
139
+
140
+ enumlistitem : first_textblock_in_enumlist other_blocks_in_list DEDENT {
141
+ result = RDoc::Markup::ListItem.new nil, val[0], *val[1]
142
+ }
143
+ ;
144
+
145
+ desclist : desclistitems = DUMMY {
146
+ result = RDoc::Markup::List.new :NOTE, *val[0]
147
+ }
148
+ ;
149
+
150
+ desclistitems : desclistitems desclistitem { result.push(val[1]) }
151
+ | desclistitem { result = val }
152
+ ;
153
+
154
+ desclistitem : DESCLISTLINE description_part DEDENT {
155
+ term = @inline_parser.parse val[0].strip
156
+
157
+ result = RDoc::Markup::ListItem.new term, *val[1]
158
+ }
159
+ ;
160
+
161
+ methodlist : methodlistitems = DUMMY {
162
+ result = RDoc::Markup::List.new :LABEL, *val[0]
163
+ }
164
+ ;
165
+
166
+ methodlistitems : methodlistitems methodlistitem { result.push(val[1]) }
167
+ | methodlistitem { result = val }
168
+ ;
169
+
170
+ methodlistitem : METHODLISTLINE description_part DEDENT {
171
+ result = RDoc::Markup::ListItem.new "<tt>#{val[0].strip}</tt>", *val[1]
172
+ }
173
+ ;
174
+
175
+ description_part : whitelines textblock blocks_in_list {
176
+ result = [val[1]].concat(val[2])
177
+ } | whitelines textblock {
178
+ result = [val[1]]
179
+ } | whitelines INDENT blocks_in_list DEDENT {
180
+ result = val[2]
181
+ } | whitelines {
182
+ result = []
183
+ }
184
+ ;
185
+
186
+ blocks_in_list : blocks_in_list block_in_list { result.concat val[1] }
187
+ | block_in_list
188
+ ;
189
+
190
+ block_in_list : textblock { result = val }
191
+ | verbatim { result = val }
192
+ | lists
193
+ | WHITELINE { result = [] }
194
+ ;
195
+
196
+ whitelines : whitelines2
197
+ |
198
+ ;
199
+
200
+ whitelines2 : WHITELINE whitelines2
201
+ | WHITELINE
202
+ ;
203
+
204
+ first_textblock_in_itemlist : ITEMLISTLINE textblockcontent {
205
+ result = paragraph [val[0]].concat(val[1])
206
+ } | ITEMLISTLINE {
207
+ result = paragraph [val[0]]
208
+ }
209
+ ;
210
+
211
+ first_textblock_in_enumlist : ENUMLISTLINE textblockcontent {
212
+ result = paragraph [val[0]].concat(val[1])
213
+ } | ENUMLISTLINE {
214
+ result = paragraph [val[0]]
215
+ }
216
+ ;
217
+
218
+ other_blocks_in_list : verbatim blocks_in_list {
219
+ result = [val[0]].concat(val[1])
220
+ } | lists blocks_in_list { result.concat val[1] }
221
+ | WHITELINE blocks_in_list { result = val[1] }
222
+ | verbatim { result = val }
223
+ | lists
224
+ | WHITELINE { result = [] }
225
+ | { result = [] }
226
+ ;
227
+ end
228
+
229
+ ---- inner
230
+
231
+ # :stopdoc:
232
+
233
+ TMPFILE = ["rdtmp", $$, 0]
234
+
235
+ MARK_TO_LEVEL = {
236
+ '=' => 1,
237
+ '==' => 2,
238
+ '===' => 3,
239
+ '====' => 4,
240
+ '+' => 5,
241
+ '++' => 6,
242
+ }
243
+
244
+ # :startdoc:
245
+
246
+ ##
247
+ # Footnotes for this document
248
+
249
+ attr_reader :footnotes
250
+
251
+ ##
252
+ # Labels for items in this document
253
+
254
+ attr_reader :labels
255
+
256
+ ##
257
+ # Path to find included files in
258
+
259
+ attr_accessor :include_path
260
+
261
+ ##
262
+ # Creates a new RDoc::RD::BlockParser. Use #parse to parse an rd-format
263
+ # document.
264
+
265
+ def initialize
266
+ @inline_parser = RDoc::RD::InlineParser.new self
267
+ @include_path = []
268
+
269
+ # for testing
270
+ @footnotes = []
271
+ @labels = {}
272
+ end
273
+
274
+ ##
275
+ # Parses +src+ and returns an RDoc::Markup::Document.
276
+
277
+ def parse src
278
+ @src = src
279
+ @src.push false
280
+
281
+ @footnotes = []
282
+ @labels = {}
283
+
284
+ # @i: index(line no.) of src
285
+ @i = 0
286
+
287
+ # stack for current indentation
288
+ @indent_stack = []
289
+
290
+ # how indented.
291
+ @current_indent = @indent_stack.join("")
292
+
293
+ # RDoc::RD::BlockParser for tmp src
294
+ @subparser = nil
295
+
296
+ # which part is in now
297
+ @in_part = nil
298
+ @part_content = []
299
+
300
+ @in_verbatim = false
301
+
302
+ @yydebug = true
303
+
304
+ document = do_parse
305
+
306
+ unless @footnotes.empty? then
307
+ blankline = document.parts.pop
308
+
309
+ document.parts << RDoc::Markup::Rule.new(1)
310
+ document.parts.concat @footnotes
311
+
312
+ document.parts.push blankline
313
+ end
314
+
315
+ document
316
+ end
317
+
318
+ ##
319
+ # Returns the next token from the document
320
+
321
+ def next_token # :nodoc:
322
+ # preprocessing
323
+ # if it is not in RD part
324
+ # => method
325
+ while @in_part != "rd"
326
+ line = @src[@i]
327
+ @i += 1 # next line
328
+
329
+ case line
330
+ # src end
331
+ when false
332
+ return [false, false]
333
+ # RD part begin
334
+ when /^=begin\s*(?:\bRD\b.*)?\s*$/
335
+ if @in_part # if in non-RD part
336
+ @part_content.push(line)
337
+ else
338
+ @in_part = "rd"
339
+ return [:WHITELINE, "=begin\n"] # <= for textblockand
340
+ end
341
+ # non-RD part begin
342
+ when /^=begin\s+(\w+)/
343
+ part = $1
344
+ if @in_part # if in non-RD part
345
+ @part_content.push(line)
346
+ else
347
+ @in_part = part if @tree.filter[part] # if filter exists
348
+ # p "BEGIN_PART: #{@in_part}" # DEBUG
349
+ end
350
+ # non-RD part end
351
+ when /^=end/
352
+ if @in_part # if in non-RD part
353
+ # p "END_PART: #{@in_part}" # DEBUG
354
+ # make Part-in object
355
+ part = RDoc::RD::Part.new(@part_content.join(""), @tree, "r")
356
+ @part_content.clear
357
+ # call filter, part_out is output(Part object)
358
+ part_out = @tree.filter[@in_part].call(part)
359
+
360
+ if @tree.filter[@in_part].mode == :rd # if output is RD formated
361
+ subtree = parse_subtree(part_out.to_a)
362
+ else # if output is target formated
363
+ basename = TMPFILE.join('.')
364
+ TMPFILE[-1] += 1
365
+ tmpfile = open(@tree.tmp_dir + "/" + basename + ".#{@in_part}", "w")
366
+ tmpfile.print(part_out)
367
+ tmpfile.close
368
+ subtree = parse_subtree(["=begin\n", "<<< #{basename}\n", "=end\n"])
369
+ end
370
+ @in_part = nil
371
+ return [:SUBTREE, subtree]
372
+ end
373
+ else
374
+ if @in_part # if in non-RD part
375
+ @part_content.push(line)
376
+ end
377
+ end
378
+ end
379
+
380
+ @current_indent = @indent_stack.join("")
381
+ line = @src[@i]
382
+ case line
383
+ when false
384
+ if_current_indent_equal("") do
385
+ [false, false]
386
+ end
387
+ when /^=end/
388
+ if_current_indent_equal("") do
389
+ @in_part = nil
390
+ [:WHITELINE, "=end"] # MUST CHANGE??
391
+ end
392
+ when /^\s*$/
393
+ @i += 1 # next line
394
+ return [:WHITELINE, ':WHITELINE']
395
+ when /^\#/ # comment line
396
+ @i += 1 # next line
397
+ self.next_token()
398
+ when /^(={1,4})(?!=)\s*(?=\S)/, /^(\+{1,2})(?!\+)\s*(?=\S)/
399
+ rest = $' # '
400
+ rest.strip!
401
+ mark = $1
402
+ if_current_indent_equal("") do
403
+ return [:HEADLINE, [MARK_TO_LEVEL[mark], rest]]
404
+ end
405
+ when /^<<<\s*(\S+)/
406
+ file = $1
407
+ if_current_indent_equal("") do
408
+ suffix = file[-3 .. -1]
409
+ if suffix == ".rd" or suffix == ".rb"
410
+ subtree = parse_subtree(get_included(file))
411
+ [:SUBTREE, subtree]
412
+ else
413
+ [:INCLUDE, file]
414
+ end
415
+ end
416
+ when /^(\s*)\*(\s*)/
417
+ rest = $' # '
418
+ newIndent = $2
419
+ if_current_indent_equal($1) do
420
+ if @in_verbatim
421
+ [:STRINGLINE, line]
422
+ else
423
+ @indent_stack.push("\s" << newIndent)
424
+ [:ITEMLISTLINE, rest]
425
+ end
426
+ end
427
+ when /^(\s*)(\(\d+\))(\s*)/
428
+ rest = $' # '
429
+ mark = $2
430
+ newIndent = $3
431
+ if_current_indent_equal($1) do
432
+ if @in_verbatim
433
+ [:STRINGLINE, line]
434
+ else
435
+ @indent_stack.push("\s" * mark.size << newIndent)
436
+ [:ENUMLISTLINE, rest]
437
+ end
438
+ end
439
+ when /^(\s*):(\s*)/
440
+ rest = $' # '
441
+ newIndent = $2
442
+ if_current_indent_equal($1) do
443
+ if @in_verbatim
444
+ [:STRINGLINE, line]
445
+ else
446
+ @indent_stack.push("\s#{$2}")
447
+ [:DESCLISTLINE, rest]
448
+ end
449
+ end
450
+ when /^(\s*)---(?!-|\s*$)/
451
+ indent = $1
452
+ rest = $'
453
+ /\s*/ === rest
454
+ term = $'
455
+ new_indent = $&
456
+ if_current_indent_equal(indent) do
457
+ if @in_verbatim
458
+ [:STRINGLINE, line]
459
+ else
460
+ @indent_stack.push("\s\s\s" + new_indent)
461
+ [:METHODLISTLINE, term]
462
+ end
463
+ end
464
+ when /^(\s*)/
465
+ if_current_indent_equal($1) do
466
+ [:STRINGLINE, line]
467
+ end
468
+ else
469
+ raise "[BUG] parsing error may occured."
470
+ end
471
+ end
472
+
473
+ ##
474
+ # Yields to the given block if +indent+ matches the current indent, otherwise
475
+ # an indentation token is processed.
476
+
477
+ def if_current_indent_equal(indent)
478
+ indent = indent.sub(/\t/, "\s" * 8)
479
+ if @current_indent == indent
480
+ @i += 1 # next line
481
+ yield
482
+ elsif indent.index(@current_indent) == 0
483
+ @indent_stack.push(indent[@current_indent.size .. -1])
484
+ [:INDENT, ":INDENT"]
485
+ else
486
+ @indent_stack.pop
487
+ [:DEDENT, ":DEDENT"]
488
+ end
489
+ end
490
+ private :if_current_indent_equal
491
+
492
+ ##
493
+ # Cuts off excess whitespace in +src+
494
+
495
+ def cut_off(src)
496
+ ret = []
497
+ whiteline_buf = []
498
+
499
+ line = src.shift
500
+ /^\s*/ =~ line
501
+
502
+ indent = Regexp.quote($&)
503
+ ret.push($')
504
+
505
+ while line = src.shift
506
+ if /^(\s*)$/ =~ line
507
+ whiteline_buf.push(line)
508
+ elsif /^#{indent}/ =~ line
509
+ unless whiteline_buf.empty?
510
+ ret.concat(whiteline_buf)
511
+ whiteline_buf.clear
512
+ end
513
+ ret.push($')
514
+ else
515
+ raise "[BUG]: probably Parser Error while cutting off.\n"
516
+ end
517
+ end
518
+ ret
519
+ end
520
+ private :cut_off
521
+
522
+ def set_term_to_element(parent, term)
523
+ # parent.set_term_under_document_struct(term, @tree.document_struct)
524
+ parent.set_term_without_document_struct(term)
525
+ end
526
+ private :set_term_to_element
527
+
528
+ ##
529
+ # Raises a ParseError
530
+
531
+ def on_error(et, ev, _values)
532
+ prv, cur, nxt = format_line_num(@i, @i+1, @i+2)
533
+
534
+ raise ParseError, <<Msg
535
+
536
+ RD syntax error: line #{@i+1}:
537
+ #{prv} |#{@src[@i-1].chomp}
538
+ #{cur}=>|#{@src[@i].chomp}
539
+ #{nxt} |#{@src[@i+1].chomp}
540
+
541
+ Msg
542
+ end
543
+
544
+ ##
545
+ # Current line number
546
+
547
+ def line_index
548
+ @i
549
+ end
550
+
551
+ ##
552
+ # Parses subtree +src+
553
+
554
+ def parse_subtree src
555
+ @subparser ||= RDoc::RD::BlockParser.new
556
+
557
+ @subparser.parse src
558
+ end
559
+ private :parse_subtree
560
+
561
+ ##
562
+ # Retrieves the content for +file+ from the include_path
563
+
564
+ def get_included(file)
565
+ included = []
566
+
567
+ @include_path.each do |dir|
568
+ file_name = File.join dir, file
569
+
570
+ if File.exist? file_name then
571
+ included = IO.readlines file_name
572
+ break
573
+ end
574
+ end
575
+
576
+ included
577
+ end
578
+ private :get_included
579
+
580
+ ##
581
+ # Formats line numbers +line_numbers+ prettily
582
+
583
+ def format_line_num(*line_numbers)
584
+ width = line_numbers.collect{|i| i.to_s.length }.max
585
+ line_numbers.collect{|i| sprintf("%#{width}d", i) }
586
+ end
587
+ private :format_line_num
588
+
589
+ ##
590
+ # Retrieves the content of +values+ as a single String
591
+
592
+ def content values
593
+ values.map { |value| value.content }.join
594
+ end
595
+
596
+ ##
597
+ # Creates a paragraph for +value+
598
+
599
+ def paragraph value
600
+ content = cut_off(value).join(' ').rstrip
601
+ contents = @inline_parser.parse content
602
+
603
+ RDoc::Markup::Paragraph.new(*contents)
604
+ end
605
+
606
+ ##
607
+ # Adds footnote +content+ to the document
608
+
609
+ def add_footnote content
610
+ index = @footnotes.length + 1
611
+
612
+ footmark_link = "{^#{index}}[rdoc-label:footmark-#{index}:foottext-#{index}]"
613
+
614
+ @footnotes << RDoc::Markup::Paragraph.new(footmark_link, *content)
615
+
616
+ index
617
+ end
618
+
619
+ ##
620
+ # Adds label +label+ to the document
621
+
622
+ def add_label label
623
+ @labels[label] = true
624
+
625
+ label
626
+ end
627
+
628
+ # :stopdoc:
629
+
630
+ ---- header
631
+ class RDoc::RD
632
+
633
+ ##
634
+ # RD format parser for headings, paragraphs, lists, verbatim sections that
635
+ # exist as blocks.
636
+
637
+ ---- footer
638
+ end