rdoc 6.17.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +193 -0
- data/LEGAL.rdoc +6 -0
- data/LICENSE.rdoc +4 -0
- data/README.md +132 -8
- data/RI.md +75 -75
- data/doc/markup_reference/markdown.md +659 -0
- data/doc/markup_reference/rdoc.rdoc +1169 -0
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +70 -74
- data/lib/rdoc/code_object/any_method.rb +308 -293
- data/lib/rdoc/code_object/attr.rb +150 -142
- data/lib/rdoc/code_object/class_module.rb +802 -715
- data/lib/rdoc/code_object/constant.rb +181 -144
- data/lib/rdoc/code_object/context/section.rb +140 -130
- data/lib/rdoc/code_object/context.rb +925 -941
- data/lib/rdoc/code_object/extend.rb +7 -5
- data/lib/rdoc/code_object/include.rb +7 -5
- data/lib/rdoc/code_object/method_attr.rb +328 -315
- data/lib/rdoc/code_object/mixin.rb +97 -92
- data/lib/rdoc/code_object/normal_class.rb +77 -78
- data/lib/rdoc/code_object/normal_module.rb +61 -59
- data/lib/rdoc/code_object/require.rb +23 -39
- data/lib/rdoc/code_object/single_class.rb +21 -19
- data/lib/rdoc/code_object/top_level.rb +215 -202
- data/lib/rdoc/code_object.rb +305 -305
- data/lib/rdoc/comment.rb +274 -337
- data/lib/rdoc/cross_reference.rb +195 -206
- data/lib/rdoc/encoding.rb +105 -103
- data/lib/rdoc/erb_partial.rb +13 -11
- data/lib/rdoc/erbio.rb +29 -27
- data/lib/rdoc/generator/aliki.rb +196 -30
- data/lib/rdoc/generator/darkfish.rb +647 -629
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +165 -122
- data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
- data/lib/rdoc/generator/pot/po.rb +52 -51
- data/lib/rdoc/generator/pot/po_entry.rb +138 -132
- data/lib/rdoc/generator/pot.rb +85 -81
- data/lib/rdoc/generator/ri.rb +23 -19
- data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
- data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
- data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
- data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
- data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
- data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
- data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
- data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
- data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
- data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/generator.rb +48 -46
- data/lib/rdoc/i18n/locale.rb +99 -95
- data/lib/rdoc/i18n/text.rb +109 -105
- data/lib/rdoc/i18n.rb +7 -5
- data/lib/rdoc/markdown/byte_runtime.rb +80 -0
- data/lib/rdoc/markdown.kpeg +52 -33
- data/lib/rdoc/markdown.rb +365 -177
- data/lib/rdoc/markup/blank_line.rb +25 -23
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/element.rb +21 -0
- data/lib/rdoc/markup/formatter.rb +220 -203
- data/lib/rdoc/markup/hard_break.rb +30 -27
- data/lib/rdoc/markup/heading.rb +163 -77
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +316 -0
- data/lib/rdoc/markup/list.rb +80 -88
- data/lib/rdoc/markup/list_item.rb +73 -85
- data/lib/rdoc/markup/paragraph.rb +23 -19
- data/lib/rdoc/markup/parser.rb +501 -497
- data/lib/rdoc/markup/pre_process.rb +284 -305
- data/lib/rdoc/markup/raw.rb +52 -55
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/table.rb +48 -40
- data/lib/rdoc/markup/to_ansi.rb +143 -92
- data/lib/rdoc/markup/to_bs.rb +86 -102
- data/lib/rdoc/markup/to_html.rb +608 -506
- data/lib/rdoc/markup/to_html_crossref.rb +219 -210
- data/lib/rdoc/markup/to_html_snippet.rb +210 -205
- data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
- data/lib/rdoc/markup/to_label.rb +64 -51
- data/lib/rdoc/markup/to_markdown.rb +212 -184
- data/lib/rdoc/markup/to_rdoc.rb +341 -277
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +62 -50
- data/lib/rdoc/markup/to_tt_only.rb +83 -92
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +196 -215
- data/lib/rdoc/options.rb +1063 -1076
- data/lib/rdoc/parser/c.rb +1039 -1036
- data/lib/rdoc/parser/changelog.rb +320 -287
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +279 -0
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1231 -2222
- data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +230 -221
- data/lib/rdoc/rbs_helper.rb +186 -0
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +547 -366
- data/lib/rdoc/ri/driver.rb +1141 -1130
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +456 -0
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -11
- data/lib/rdoc/rubygems_hook.rb +194 -192
- data/lib/rdoc/server.rb +462 -0
- data/lib/rdoc/stats/normal.rb +46 -42
- data/lib/rdoc/stats/quiet.rb +39 -35
- data/lib/rdoc/stats/verbose.rb +35 -31
- data/lib/rdoc/stats.rb +363 -338
- data/lib/rdoc/store.rb +919 -725
- data/lib/rdoc/task.rb +260 -255
- data/lib/rdoc/text.rb +164 -240
- data/lib/rdoc/token_stream.rb +88 -106
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- data/lib/rdoc.rb +35 -7
- data/lib/rubygems_plugin.rb +2 -11
- data/rdoc-logo.svg +43 -0
- data/rdoc.gemspec +9 -7
- metadata +46 -32
- data/CONTRIBUTING.rdoc +0 -219
- data/ExampleMarkdown.md +0 -39
- data/ExampleRDoc.rdoc +0 -210
- data/lib/rdoc/code_object/anon_class.rb +0 -10
- data/lib/rdoc/code_object/ghost_method.rb +0 -6
- data/lib/rdoc/code_object/meta_method.rb +0 -6
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- data/lib/rdoc/markdown/literals.rb +0 -454
- data/lib/rdoc/markup/attr_changer.rb +0 -22
- data/lib/rdoc/markup/attr_span.rb +0 -35
- data/lib/rdoc/markup/attribute_manager.rb +0 -405
- data/lib/rdoc/markup/attributes.rb +0 -70
- data/lib/rdoc/markup/regexp_handling.rb +0 -40
- data/lib/rdoc/parser/prism_ruby.rb +0 -1100
- data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
- data/lib/rdoc/parser/ruby_tools.rb +0 -163
- data/lib/rdoc/servlet.rb +0 -452
data/lib/rdoc/token_stream.rb
CHANGED
|
@@ -1,130 +1,112 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# A TokenStream is a list of tokens, gathered during the parse of some entity
|
|
5
|
-
# (say a method). Entities populate these streams by being registered with the
|
|
6
|
-
# lexer. Any class can collect tokens by including TokenStream. From the
|
|
7
|
-
# outside, you use such an object by calling the start_collecting_tokens
|
|
8
|
-
# method, followed by calls to add_token and pop_token.
|
|
9
|
-
|
|
10
|
-
module RDoc::TokenStream
|
|
11
|
-
|
|
3
|
+
module RDoc
|
|
12
4
|
##
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
:on_symbol, :on_CHAR then 'ruby-value'
|
|
44
|
-
when :on_heredoc_beg, :on_heredoc_end
|
|
45
|
-
then 'ruby-identifier'
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
comment_with_nl = false
|
|
49
|
-
if :on_comment == t[:kind] or :on_embdoc == t[:kind] or :on_heredoc_end == t[:kind]
|
|
50
|
-
comment_with_nl = true if "\n" == t[:text][-1]
|
|
51
|
-
text = t[:text].rstrip
|
|
52
|
-
else
|
|
53
|
-
text = t[:text]
|
|
54
|
-
end
|
|
5
|
+
# A TokenStream is a list of tokens, gathered during the parse of some entity
|
|
6
|
+
# (say a method). Entities populate these streams by being registered with the
|
|
7
|
+
# lexer. Any class can collect tokens by including TokenStream. From the
|
|
8
|
+
# outside, you use such an object by calling the start_collecting_tokens
|
|
9
|
+
# method, followed by calls to add_token and pop_token.
|
|
10
|
+
|
|
11
|
+
module TokenStream
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# Converts +token_stream+ to HTML wrapping various tokens with
|
|
15
|
+
# <tt><span></tt> elements. Some tokens types are wrapped in spans
|
|
16
|
+
# with the given class names. Other token types are not wrapped in spans.
|
|
17
|
+
|
|
18
|
+
def self.to_html(token_stream)
|
|
19
|
+
token_stream.map do |t|
|
|
20
|
+
next unless t
|
|
21
|
+
|
|
22
|
+
style = case t[:kind]
|
|
23
|
+
when :operator then 'ruby-operator'
|
|
24
|
+
when :keyword then 'ruby-keyword'
|
|
25
|
+
when :constant then 'ruby-constant'
|
|
26
|
+
when :ivar then 'ruby-ivar'
|
|
27
|
+
when :comment then 'ruby-comment'
|
|
28
|
+
when :value then 'ruby-value'
|
|
29
|
+
when :string then 'ruby-string'
|
|
30
|
+
when :symbol then 'ruby-value'
|
|
31
|
+
when :x_string then 'ruby-string'
|
|
32
|
+
when :regexp then 'ruby-regexp'
|
|
33
|
+
when :identifier then 'ruby-identifier'
|
|
34
|
+
end
|
|
55
35
|
|
|
56
|
-
|
|
57
|
-
starting_title = false
|
|
58
|
-
style = 'ruby-identifier ruby-title'
|
|
59
|
-
end
|
|
36
|
+
text = t[:text]
|
|
60
37
|
|
|
61
|
-
|
|
62
|
-
starting_title = true
|
|
63
|
-
end
|
|
38
|
+
text = CGI.escapeHTML text
|
|
64
39
|
|
|
65
|
-
|
|
40
|
+
if style
|
|
41
|
+
end_with_newline = text.end_with?("\n")
|
|
42
|
+
text = text.chomp if end_with_newline
|
|
43
|
+
"<span class=\"#{style}\">#{text}</span>#{"\n" if end_with_newline}"
|
|
44
|
+
else
|
|
45
|
+
text
|
|
46
|
+
end
|
|
47
|
+
end.join
|
|
48
|
+
end
|
|
66
49
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
else
|
|
70
|
-
text
|
|
71
|
-
end
|
|
72
|
-
end.join
|
|
73
|
-
end
|
|
50
|
+
##
|
|
51
|
+
# Adds +tokens+ to the collected tokens
|
|
74
52
|
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
def add_tokens(tokens)
|
|
54
|
+
token_stream.concat(tokens)
|
|
55
|
+
end
|
|
77
56
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
end
|
|
57
|
+
##
|
|
58
|
+
# Adds one +token+ to the collected tokens
|
|
81
59
|
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
def add_token(token)
|
|
61
|
+
token_stream.push(token)
|
|
62
|
+
end
|
|
84
63
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
##
|
|
65
|
+
# Starts collecting tokens
|
|
66
|
+
#
|
|
67
|
+
# The optional +loader+ is called once on first access and its result is reused.
|
|
88
68
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
69
|
+
def collect_tokens(language, loader: nil)
|
|
70
|
+
@token_stream = []
|
|
71
|
+
@token_stream_loader = loader
|
|
72
|
+
@token_stream_language = language
|
|
73
|
+
end
|
|
92
74
|
|
|
93
|
-
|
|
94
|
-
@token_stream = []
|
|
95
|
-
@token_stream_language = language
|
|
96
|
-
end
|
|
75
|
+
alias start_collecting_tokens collect_tokens
|
|
97
76
|
|
|
98
|
-
|
|
77
|
+
##
|
|
78
|
+
# Remove the last token from the collected tokens
|
|
99
79
|
|
|
100
|
-
|
|
101
|
-
|
|
80
|
+
def pop_token
|
|
81
|
+
token_stream.pop
|
|
82
|
+
end
|
|
102
83
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
end
|
|
84
|
+
##
|
|
85
|
+
# Current token stream
|
|
106
86
|
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
def token_stream
|
|
88
|
+
if @token_stream_loader
|
|
89
|
+
@token_stream = @token_stream_loader.call
|
|
90
|
+
@token_stream_loader = nil
|
|
91
|
+
end
|
|
92
|
+
@token_stream
|
|
93
|
+
end
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
end
|
|
95
|
+
##
|
|
96
|
+
# Returns a string representation of the token stream
|
|
113
97
|
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
def tokens_to_s
|
|
99
|
+
(token_stream or return '').compact.map { |token| token[:text] }.join ''
|
|
100
|
+
end
|
|
116
101
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
##
|
|
103
|
+
# Returns the source language of the token stream as a string
|
|
104
|
+
#
|
|
105
|
+
# Returns 'c' or 'ruby'
|
|
120
106
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# Returns 'c' or 'ruby'
|
|
107
|
+
def source_language
|
|
108
|
+
@token_stream_language == :c ? 'c' : 'ruby'
|
|
109
|
+
end
|
|
125
110
|
|
|
126
|
-
def source_language
|
|
127
|
-
@token_stream_language == :c ? 'c' : 'ruby'
|
|
128
111
|
end
|
|
129
|
-
|
|
130
112
|
end
|
data/lib/rdoc/tom_doc.rb
CHANGED
|
@@ -1,257 +1,259 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# :markup: tomdoc
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# The TomDoc specification can be found at http://tomdoc.org.
|
|
7
|
-
#
|
|
8
|
-
# To choose TomDoc as your only default format see RDoc::Options@Saved+Options
|
|
9
|
-
# for instructions on setting up a <code>.rdoc_options</code> file to store
|
|
10
|
-
# your project default.
|
|
11
|
-
#
|
|
12
|
-
# There are a few differences between this parser and the specification. A
|
|
13
|
-
# best-effort was made to follow the specification as closely as possible but
|
|
14
|
-
# some choices to deviate were made.
|
|
15
|
-
#
|
|
16
|
-
# A future version of RDoc will warn when a MUST or MUST NOT is violated and
|
|
17
|
-
# may warn when a SHOULD or SHOULD NOT is violated. RDoc will always try
|
|
18
|
-
# to emit documentation even if given invalid TomDoc.
|
|
19
|
-
#
|
|
20
|
-
# Here are some implementation choices this parser currently makes:
|
|
21
|
-
#
|
|
22
|
-
# This parser allows rdoc-style inline markup but you should not depended on
|
|
23
|
-
# it.
|
|
24
|
-
#
|
|
25
|
-
# This parser allows a space between the comment and the method body.
|
|
26
|
-
#
|
|
27
|
-
# This parser does not require the default value to be described for an
|
|
28
|
-
# optional argument.
|
|
29
|
-
#
|
|
30
|
-
# This parser does not examine the order of sections. An Examples section may
|
|
31
|
-
# precede the Arguments section.
|
|
32
|
-
#
|
|
33
|
-
# This class is documented in TomDoc format. Since this is a subclass of the
|
|
34
|
-
# RDoc markup parser there isn't much to see here, unfortunately.
|
|
35
|
-
|
|
36
|
-
class RDoc::TomDoc < RDoc::Markup::Parser
|
|
37
|
-
|
|
38
|
-
# Internal: Token accessor
|
|
39
|
-
|
|
40
|
-
attr_reader :tokens
|
|
41
|
-
|
|
42
|
-
# Internal: Adds a post-processor which sets the RDoc section based on the
|
|
43
|
-
# comment's status.
|
|
4
|
+
module RDoc
|
|
5
|
+
# A parser for TomDoc based on TomDoc 1.0.0-rc1 (02adef9b5a)
|
|
44
6
|
#
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
def self.add_post_processor # :nodoc:
|
|
48
|
-
RDoc::Markup::PreProcess.post_process do |comment, code_object|
|
|
49
|
-
next unless code_object and
|
|
50
|
-
RDoc::Comment === comment and comment.format == 'tomdoc'
|
|
51
|
-
|
|
52
|
-
comment.text.gsub!(/\A(\s*# |)(Public|Internal|Deprecated):\s+/) do
|
|
53
|
-
section = code_object.add_section $2
|
|
54
|
-
code_object.temporary_section = section
|
|
55
|
-
|
|
56
|
-
$1
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
add_post_processor
|
|
62
|
-
|
|
63
|
-
# Public: Parses TomDoc from text
|
|
7
|
+
# The TomDoc specification can be found at http://tomdoc.org.
|
|
64
8
|
#
|
|
65
|
-
#
|
|
9
|
+
# To choose TomDoc as your only default format see RDoc::Options@Saved+Options
|
|
10
|
+
# for instructions on setting up a <code>.rdoc_options</code> file to store
|
|
11
|
+
# your project default.
|
|
66
12
|
#
|
|
67
|
-
#
|
|
13
|
+
# There are a few differences between this parser and the specification. A
|
|
14
|
+
# best-effort was made to follow the specification as closely as possible but
|
|
15
|
+
# some choices to deviate were made.
|
|
68
16
|
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
17
|
+
# A future version of RDoc will warn when a MUST or MUST NOT is violated and
|
|
18
|
+
# may warn when a SHOULD or SHOULD NOT is violated. RDoc will always try
|
|
19
|
+
# to emit documentation even if given invalid TomDoc.
|
|
71
20
|
#
|
|
72
|
-
#
|
|
73
|
-
# TOMDOC
|
|
74
|
-
# # => #<RDoc::Markup::Document:0xXXX @parts=[...], @file=nil>
|
|
21
|
+
# Here are some implementation choices this parser currently makes:
|
|
75
22
|
#
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
def self.parse(text)
|
|
79
|
-
parser = new
|
|
80
|
-
|
|
81
|
-
parser.tokenize text
|
|
82
|
-
doc = RDoc::Markup::Document.new
|
|
83
|
-
parser.parse doc
|
|
84
|
-
doc
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Internal: Extracts the Signature section's method signature
|
|
23
|
+
# This parser allows rdoc-style inline markup but you should not depended on
|
|
24
|
+
# it.
|
|
88
25
|
#
|
|
89
|
-
#
|
|
90
|
-
# extracted
|
|
26
|
+
# This parser allows a space between the comment and the method body.
|
|
91
27
|
#
|
|
92
|
-
#
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
28
|
+
# This parser does not require the default value to be described for an
|
|
29
|
+
# optional argument.
|
|
30
|
+
#
|
|
31
|
+
# This parser does not examine the order of sections. An Examples section may
|
|
32
|
+
# precede the Arguments section.
|
|
33
|
+
#
|
|
34
|
+
# This class is documented in TomDoc format. Since this is a subclass of the
|
|
35
|
+
# RDoc markup parser there isn't much to see here, unfortunately.
|
|
96
36
|
|
|
97
|
-
|
|
37
|
+
class TomDoc < Markup::Parser
|
|
98
38
|
|
|
99
|
-
|
|
100
|
-
found_heading = false
|
|
101
|
-
found_signature = false
|
|
39
|
+
# Internal: Token accessor
|
|
102
40
|
|
|
103
|
-
|
|
104
|
-
next false if found_signature
|
|
41
|
+
attr_reader :tokens
|
|
105
42
|
|
|
106
|
-
|
|
107
|
-
|
|
43
|
+
# Internal: Adds a post-processor which sets the RDoc section based on the
|
|
44
|
+
# comment's status.
|
|
45
|
+
#
|
|
46
|
+
# Returns nothing.
|
|
108
47
|
|
|
109
|
-
|
|
48
|
+
def self.add_post_processor # :nodoc:
|
|
49
|
+
Markup::PreProcess.post_process do |comment, code_object|
|
|
50
|
+
next unless code_object and
|
|
51
|
+
Comment === comment and comment.format == 'tomdoc'
|
|
110
52
|
|
|
111
|
-
|
|
53
|
+
comment.text.gsub!(/\A(\s*# |)(Public|Internal|Deprecated):\s+/) do
|
|
54
|
+
section = code_object.add_section $2
|
|
55
|
+
code_object.temporary_section = section
|
|
112
56
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
found_signature = true
|
|
57
|
+
$1
|
|
58
|
+
end
|
|
116
59
|
end
|
|
117
60
|
end
|
|
118
61
|
|
|
119
|
-
|
|
120
|
-
|
|
62
|
+
add_post_processor
|
|
63
|
+
|
|
64
|
+
# Public: Parses TomDoc from text
|
|
65
|
+
#
|
|
66
|
+
# text - A String containing TomDoc-format text.
|
|
67
|
+
#
|
|
68
|
+
# Examples
|
|
69
|
+
#
|
|
70
|
+
# RDoc::TomDoc.parse <<-TOMDOC
|
|
71
|
+
# This method does some things
|
|
72
|
+
#
|
|
73
|
+
# Returns nothing.
|
|
74
|
+
# TOMDOC
|
|
75
|
+
# # => #<RDoc::Markup::Document:0xXXX @parts=[...], @file=nil>
|
|
76
|
+
#
|
|
77
|
+
# Returns an RDoc::Markup::Document representing the TomDoc format.
|
|
78
|
+
|
|
79
|
+
def self.parse(text)
|
|
80
|
+
parser = new
|
|
81
|
+
|
|
82
|
+
parser.tokenize text
|
|
83
|
+
doc = Markup::Document.new
|
|
84
|
+
parser.parse doc
|
|
85
|
+
doc
|
|
86
|
+
end
|
|
121
87
|
|
|
122
|
-
|
|
88
|
+
# Internal: Extracts the Signature section's method signature
|
|
89
|
+
#
|
|
90
|
+
# comment - An RDoc::Comment that will be parsed and have the signature
|
|
91
|
+
# extracted
|
|
92
|
+
#
|
|
93
|
+
# Returns a String containing the signature and nil if not
|
|
123
94
|
|
|
124
|
-
|
|
125
|
-
|
|
95
|
+
def self.signature(comment)
|
|
96
|
+
return unless comment.tomdoc?
|
|
126
97
|
|
|
127
|
-
|
|
128
|
-
@seen_returns = false
|
|
129
|
-
end
|
|
98
|
+
document = comment.parse
|
|
130
99
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
#
|
|
135
|
-
# Returns an RDoc::Markup::Heading
|
|
100
|
+
signature = nil
|
|
101
|
+
found_heading = false
|
|
102
|
+
found_signature = false
|
|
136
103
|
|
|
137
|
-
|
|
138
|
-
|
|
104
|
+
document.parts.delete_if do |part|
|
|
105
|
+
next false if found_signature
|
|
139
106
|
|
|
140
|
-
|
|
107
|
+
found_heading ||=
|
|
108
|
+
Markup::Heading === part && part.text == 'Signature'
|
|
141
109
|
|
|
142
|
-
|
|
143
|
-
end
|
|
110
|
+
next false unless found_heading
|
|
144
111
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
112
|
+
next true if Markup::BlankLine === part
|
|
113
|
+
|
|
114
|
+
if Markup::Verbatim === part
|
|
115
|
+
signature = part
|
|
116
|
+
found_signature = true
|
|
117
|
+
end
|
|
118
|
+
end
|
|
152
119
|
|
|
153
|
-
|
|
154
|
-
|
|
120
|
+
signature and signature.text
|
|
121
|
+
end
|
|
155
122
|
|
|
156
|
-
|
|
123
|
+
# Public: Creates a new TomDoc parser. See also RDoc::Markup::parse
|
|
157
124
|
|
|
158
|
-
|
|
159
|
-
|
|
125
|
+
def initialize
|
|
126
|
+
super
|
|
160
127
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
#
|
|
165
|
-
# Returns an RDoc::Markup::Paragraph.
|
|
128
|
+
@section = nil
|
|
129
|
+
@seen_returns = false
|
|
130
|
+
end
|
|
166
131
|
|
|
167
|
-
|
|
168
|
-
|
|
132
|
+
# Internal: Builds a heading from the token stream
|
|
133
|
+
#
|
|
134
|
+
# level - The level of heading to create
|
|
135
|
+
#
|
|
136
|
+
# Returns an RDoc::Markup::Heading
|
|
169
137
|
|
|
170
|
-
|
|
138
|
+
def build_heading(level)
|
|
139
|
+
heading = super
|
|
171
140
|
|
|
172
|
-
|
|
173
|
-
type, data, = get
|
|
141
|
+
@section = heading.text
|
|
174
142
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
@section = 'Returns' if data =~ /\A(Returns|Raises)/
|
|
143
|
+
heading
|
|
144
|
+
end
|
|
178
145
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
146
|
+
# Internal: Builds a verbatim from the token stream. A verbatim in the
|
|
147
|
+
# Examples section will be marked as in Ruby format.
|
|
148
|
+
#
|
|
149
|
+
# margin - The indentation from the margin for lines that belong to this
|
|
150
|
+
# verbatim section.
|
|
151
|
+
#
|
|
152
|
+
# Returns an RDoc::Markup::Verbatim
|
|
153
|
+
|
|
154
|
+
def build_verbatim(margin)
|
|
155
|
+
verbatim = super
|
|
156
|
+
|
|
157
|
+
verbatim.format = :ruby if @section == 'Examples'
|
|
158
|
+
|
|
159
|
+
verbatim
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Internal: Builds a paragraph from the token stream
|
|
163
|
+
#
|
|
164
|
+
# margin - Unused
|
|
165
|
+
#
|
|
166
|
+
# Returns an RDoc::Markup::Paragraph.
|
|
167
|
+
|
|
168
|
+
def build_paragraph(margin)
|
|
169
|
+
p :paragraph_start => margin if @debug
|
|
170
|
+
|
|
171
|
+
paragraph = Markup::Paragraph.new
|
|
172
|
+
|
|
173
|
+
until @tokens.empty? do
|
|
174
|
+
type, data, = get
|
|
175
|
+
|
|
176
|
+
case type
|
|
177
|
+
when :TEXT
|
|
178
|
+
@section = 'Returns' if data =~ /\A(Returns|Raises)/
|
|
179
|
+
|
|
180
|
+
paragraph << data
|
|
181
|
+
when :NEWLINE
|
|
182
|
+
if :TEXT == peek_token[0]
|
|
183
|
+
# Lines beginning with 'Raises' in the Returns section should not be
|
|
184
|
+
# treated as multiline text
|
|
185
|
+
if 'Returns' == @section and
|
|
186
|
+
peek_token[1].start_with?('Raises')
|
|
187
|
+
break
|
|
188
|
+
else
|
|
189
|
+
paragraph << ' '
|
|
190
|
+
end
|
|
187
191
|
else
|
|
188
|
-
|
|
192
|
+
break
|
|
189
193
|
end
|
|
190
194
|
else
|
|
195
|
+
unget
|
|
191
196
|
break
|
|
192
197
|
end
|
|
193
|
-
else
|
|
194
|
-
unget
|
|
195
|
-
break
|
|
196
198
|
end
|
|
197
|
-
end
|
|
198
199
|
|
|
199
|
-
|
|
200
|
+
p :paragraph_end => margin if @debug
|
|
200
201
|
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
paragraph
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
##
|
|
206
|
+
# Detects a section change to "Returns" and adds a heading
|
|
203
207
|
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
def parse_text(parent, indent) # :nodoc:
|
|
209
|
+
paragraph = build_paragraph indent
|
|
206
210
|
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
if false == @seen_returns and 'Returns' == @section
|
|
212
|
+
@seen_returns = true
|
|
213
|
+
parent << Markup::Heading.new(3, 'Returns')
|
|
214
|
+
parent << Markup::BlankLine.new
|
|
215
|
+
end
|
|
209
216
|
|
|
210
|
-
|
|
211
|
-
@seen_returns = true
|
|
212
|
-
parent << RDoc::Markup::Heading.new(3, 'Returns')
|
|
213
|
-
parent << RDoc::Markup::BlankLine.new
|
|
217
|
+
parent << paragraph
|
|
214
218
|
end
|
|
215
219
|
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
# Internal: Turns text into an Array of tokens
|
|
221
|
+
#
|
|
222
|
+
# text - A String containing TomDoc-format text.
|
|
223
|
+
#
|
|
224
|
+
# Returns self.
|
|
225
|
+
|
|
226
|
+
def tokenize(text)
|
|
227
|
+
text = text.sub(/\A(Public|Internal|Deprecated):\s+/, '')
|
|
228
|
+
|
|
229
|
+
setup_scanner text
|
|
230
|
+
|
|
231
|
+
until @s.eos? do
|
|
232
|
+
pos = @s.pos
|
|
233
|
+
|
|
234
|
+
# leading spaces will be reflected by the column of the next token
|
|
235
|
+
# the only thing we loose are trailing spaces at the end of the file
|
|
236
|
+
next if @s.scan(/ +/)
|
|
237
|
+
|
|
238
|
+
@tokens << case
|
|
239
|
+
when @s.scan(/\r?\n/)
|
|
240
|
+
token = [:NEWLINE, @s.matched, *pos]
|
|
241
|
+
@s.newline!
|
|
242
|
+
token
|
|
243
|
+
when @s.scan(/(Examples|Signature)$/)
|
|
244
|
+
@tokens << [:HEADER, 3, *pos]
|
|
245
|
+
|
|
246
|
+
[:TEXT, @s[1], *pos]
|
|
247
|
+
when @s.scan(/([:\w][\w\[\]]*)[ ]+- /)
|
|
248
|
+
[:NOTE, @s[1], *pos]
|
|
249
|
+
else
|
|
250
|
+
@s.scan(/.*/)
|
|
251
|
+
[:TEXT, @s.matched.sub(/\r$/, ''), *pos]
|
|
252
|
+
end
|
|
253
|
+
end
|
|
218
254
|
|
|
219
|
-
|
|
220
|
-
#
|
|
221
|
-
# text - A String containing TomDoc-format text.
|
|
222
|
-
#
|
|
223
|
-
# Returns self.
|
|
224
|
-
|
|
225
|
-
def tokenize(text)
|
|
226
|
-
text = text.sub(/\A(Public|Internal|Deprecated):\s+/, '')
|
|
227
|
-
|
|
228
|
-
setup_scanner text
|
|
229
|
-
|
|
230
|
-
until @s.eos? do
|
|
231
|
-
pos = @s.pos
|
|
232
|
-
|
|
233
|
-
# leading spaces will be reflected by the column of the next token
|
|
234
|
-
# the only thing we loose are trailing spaces at the end of the file
|
|
235
|
-
next if @s.scan(/ +/)
|
|
236
|
-
|
|
237
|
-
@tokens << case
|
|
238
|
-
when @s.scan(/\r?\n/) then
|
|
239
|
-
token = [:NEWLINE, @s.matched, *pos]
|
|
240
|
-
@s.newline!
|
|
241
|
-
token
|
|
242
|
-
when @s.scan(/(Examples|Signature)$/) then
|
|
243
|
-
@tokens << [:HEADER, 3, *pos]
|
|
244
|
-
|
|
245
|
-
[:TEXT, @s[1], *pos]
|
|
246
|
-
when @s.scan(/([:\w][\w\[\]]*)[ ]+- /) then
|
|
247
|
-
[:NOTE, @s[1], *pos]
|
|
248
|
-
else
|
|
249
|
-
@s.scan(/.*/)
|
|
250
|
-
[:TEXT, @s.matched.sub(/\r$/, ''), *pos]
|
|
251
|
-
end
|
|
255
|
+
self
|
|
252
256
|
end
|
|
253
257
|
|
|
254
|
-
self
|
|
255
258
|
end
|
|
256
|
-
|
|
257
259
|
end
|