rdoc 3.1 → 6.3.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CONTRIBUTING.rdoc +220 -0
- data/CVE-2013-0256.rdoc +49 -0
- data/ExampleMarkdown.md +37 -0
- data/ExampleRDoc.rdoc +208 -0
- data/Gemfile +12 -0
- data/History.rdoc +1666 -0
- data/LEGAL.rdoc +50 -0
- data/LICENSE.rdoc +57 -0
- data/README.rdoc +129 -0
- data/RI.rdoc +57 -0
- data/Rakefile +84 -81
- data/TODO.rdoc +59 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/{bin → exe}/rdoc +11 -2
- data/exe/ri +12 -0
- data/lib/rdoc/alias.rb +1 -2
- data/lib/rdoc/anon_class.rb +3 -2
- data/lib/rdoc/any_method.rb +234 -40
- data/lib/rdoc/attr.rb +79 -11
- data/lib/rdoc/class_module.rb +443 -71
- data/lib/rdoc/code_object.rb +216 -20
- data/lib/rdoc/code_objects.rb +4 -21
- data/lib/rdoc/comment.rb +250 -0
- data/lib/rdoc/constant.rb +110 -9
- data/lib/rdoc/context/section.rb +232 -0
- data/lib/rdoc/context.rb +392 -172
- data/lib/rdoc/cross_reference.rb +202 -0
- data/lib/rdoc/encoding.rb +83 -28
- data/lib/rdoc/erb_partial.rb +19 -0
- data/lib/rdoc/erbio.rb +8 -3
- data/lib/rdoc/extend.rb +10 -0
- data/lib/rdoc/generator/darkfish.rb +507 -84
- data/lib/rdoc/generator/json_index.rb +300 -0
- data/lib/rdoc/generator/markup.rb +27 -74
- data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
- data/lib/rdoc/generator/pot/po.rb +84 -0
- data/lib/rdoc/generator/pot/po_entry.rb +141 -0
- data/lib/rdoc/generator/pot.rb +98 -0
- data/lib/rdoc/generator/ri.rb +8 -62
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
- data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +18 -60
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -83
- data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
- data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
- data/lib/rdoc/generator/template/json_index/.document +1 -0
- data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
- data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
- data/lib/rdoc/generator.rb +24 -13
- data/lib/rdoc/ghost_method.rb +1 -2
- data/lib/rdoc/i18n/locale.rb +102 -0
- data/lib/rdoc/i18n/text.rb +126 -0
- data/lib/rdoc/i18n.rb +10 -0
- data/lib/rdoc/include.rb +5 -95
- data/lib/rdoc/known_classes.rb +5 -2
- data/lib/rdoc/markdown/entities.rb +2132 -0
- data/lib/rdoc/markdown/literals.kpeg +23 -0
- data/lib/rdoc/markdown/literals.rb +416 -0
- data/lib/rdoc/markdown.kpeg +1237 -0
- data/lib/rdoc/markdown.rb +16684 -0
- data/lib/rdoc/markup/attr_changer.rb +23 -0
- data/lib/rdoc/markup/attr_span.rb +36 -0
- data/lib/rdoc/markup/attribute_manager.rb +135 -62
- data/lib/rdoc/markup/attributes.rb +71 -0
- data/lib/rdoc/markup/blank_line.rb +1 -0
- data/lib/rdoc/markup/block_quote.rb +15 -0
- data/lib/rdoc/markup/document.rb +96 -9
- data/lib/rdoc/markup/formatter.rb +138 -25
- data/lib/rdoc/markup/hard_break.rb +32 -0
- data/lib/rdoc/markup/heading.rb +61 -2
- data/lib/rdoc/markup/include.rb +43 -0
- data/lib/rdoc/markup/indented_paragraph.rb +48 -0
- data/lib/rdoc/markup/list.rb +25 -4
- data/lib/rdoc/markup/list_item.rb +18 -4
- data/lib/rdoc/markup/paragraph.rb +15 -0
- data/lib/rdoc/markup/parser.rb +180 -88
- data/lib/rdoc/markup/pre_process.rb +183 -38
- data/lib/rdoc/markup/raw.rb +6 -5
- data/lib/rdoc/markup/regexp_handling.rb +41 -0
- data/lib/rdoc/markup/rule.rb +1 -0
- data/lib/rdoc/markup/table.rb +47 -0
- data/lib/rdoc/markup/to_ansi.rb +17 -7
- data/lib/rdoc/markup/to_bs.rb +5 -8
- data/lib/rdoc/markup/to_html.rb +238 -137
- data/lib/rdoc/markup/to_html_crossref.rb +125 -152
- data/lib/rdoc/markup/to_html_snippet.rb +285 -0
- data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
- data/lib/rdoc/markup/to_label.rb +75 -0
- data/lib/rdoc/markup/to_markdown.rb +192 -0
- data/lib/rdoc/markup/to_rdoc.rb +85 -15
- data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
- data/lib/rdoc/markup/to_test.rb +2 -4
- data/lib/rdoc/markup/to_tt_only.rb +121 -0
- data/lib/rdoc/markup/verbatim.rb +39 -0
- data/lib/rdoc/markup.rb +388 -110
- data/lib/rdoc/meta_method.rb +1 -2
- data/lib/rdoc/method_attr.rb +87 -21
- data/lib/rdoc/mixin.rb +121 -0
- data/lib/rdoc/normal_class.rb +39 -10
- data/lib/rdoc/normal_module.rb +22 -7
- data/lib/rdoc/options.rb +613 -73
- data/lib/rdoc/parser/c.rb +621 -287
- data/lib/rdoc/parser/changelog.rb +335 -0
- data/lib/rdoc/parser/markdown.rb +24 -0
- data/lib/rdoc/parser/rd.rb +23 -0
- data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
- data/lib/rdoc/parser/ruby.rb +1368 -762
- data/lib/rdoc/parser/ruby_tools.rb +42 -35
- data/lib/rdoc/parser/simple.rb +23 -11
- data/lib/rdoc/parser/text.rb +12 -0
- data/lib/rdoc/parser.rb +162 -89
- data/lib/rdoc/rd/block_parser.rb +1056 -0
- data/lib/rdoc/rd/block_parser.ry +639 -0
- data/lib/rdoc/rd/inline.rb +72 -0
- data/lib/rdoc/rd/inline_parser.rb +1208 -0
- data/lib/rdoc/rd/inline_parser.ry +593 -0
- data/lib/rdoc/rd.rb +100 -0
- data/lib/rdoc/rdoc.rb +208 -115
- data/lib/rdoc/require.rb +1 -2
- data/lib/rdoc/ri/driver.rb +734 -239
- data/lib/rdoc/ri/formatter.rb +1 -0
- data/lib/rdoc/ri/paths.rb +91 -48
- data/lib/rdoc/ri/store.rb +3 -261
- data/lib/rdoc/ri/task.rb +71 -0
- data/lib/rdoc/ri.rb +5 -2
- data/lib/rdoc/rubygems_hook.rb +246 -0
- data/lib/rdoc/servlet.rb +451 -0
- data/lib/rdoc/single_class.rb +14 -2
- data/lib/rdoc/stats/normal.rb +19 -12
- data/lib/rdoc/stats/quiet.rb +1 -0
- data/lib/rdoc/stats/verbose.rb +1 -0
- data/lib/rdoc/stats.rb +262 -104
- data/lib/rdoc/store.rb +979 -0
- data/lib/rdoc/task.rb +84 -44
- data/lib/rdoc/text.rb +117 -72
- data/lib/rdoc/token_stream.rb +73 -4
- data/lib/rdoc/tom_doc.rb +263 -0
- data/lib/rdoc/top_level.rb +111 -261
- data/lib/rdoc/version.rb +8 -0
- data/lib/rdoc.rb +127 -64
- data/man/ri.1 +247 -0
- data/rdoc.gemspec +249 -0
- metadata +171 -291
- data/.autotest +0 -16
- data/.document +0 -5
- data/History.txt +0 -594
- data/LICENSE.txt +0 -57
- data/Manifest.txt +0 -158
- data/README.txt +0 -45
- data/RI.txt +0 -58
- data/bin/ri +0 -5
- data/lib/rdoc/gauntlet.rb +0 -52
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -296
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
- data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -32
- data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
- data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
- data/lib/rdoc/generator/template/darkfish/rdoc.css +0 -706
- data/lib/rdoc/markup/formatter_test_case.rb +0 -689
- data/lib/rdoc/markup/inline.rb +0 -137
- data/lib/rdoc/markup/text_formatter_test_case.rb +0 -116
- data/lib/rdoc/ruby_lex.rb +0 -1291
- data/lib/rdoc/ruby_token.rb +0 -416
- data/test/README +0 -1
- data/test/binary.dat +0 -0
- data/test/hidden.zip.txt +0 -1
- data/test/test.ja.rdoc +0 -10
- data/test/test.ja.txt +0 -8
- data/test/test.txt +0 -1
- data/test/test_attribute_manager.rb +0 -120
- data/test/test_rdoc_alias.rb +0 -13
- data/test/test_rdoc_any_method.rb +0 -126
- data/test/test_rdoc_attr.rb +0 -61
- data/test/test_rdoc_class_module.rb +0 -233
- data/test/test_rdoc_code_object.rb +0 -165
- data/test/test_rdoc_constant.rb +0 -15
- data/test/test_rdoc_context.rb +0 -370
- data/test/test_rdoc_encoding.rb +0 -166
- data/test/test_rdoc_generator_darkfish.rb +0 -119
- data/test/test_rdoc_generator_ri.rb +0 -76
- data/test/test_rdoc_include.rb +0 -96
- data/test/test_rdoc_markup.rb +0 -37
- data/test/test_rdoc_markup_attribute_manager.rb +0 -240
- data/test/test_rdoc_markup_document.rb +0 -51
- data/test/test_rdoc_markup_paragraph.rb +0 -9
- data/test/test_rdoc_markup_parser.rb +0 -1395
- data/test/test_rdoc_markup_pre_process.rb +0 -185
- data/test/test_rdoc_markup_raw.rb +0 -27
- data/test/test_rdoc_markup_to_ansi.rb +0 -328
- data/test/test_rdoc_markup_to_bs.rb +0 -341
- data/test/test_rdoc_markup_to_html.rb +0 -335
- data/test/test_rdoc_markup_to_html_crossref.rb +0 -169
- data/test/test_rdoc_markup_to_rdoc.rb +0 -327
- data/test/test_rdoc_method_attr.rb +0 -122
- data/test/test_rdoc_normal_class.rb +0 -17
- data/test/test_rdoc_normal_module.rb +0 -31
- data/test/test_rdoc_options.rb +0 -342
- data/test/test_rdoc_parser.rb +0 -83
- data/test/test_rdoc_parser_c.rb +0 -912
- data/test/test_rdoc_parser_ruby.rb +0 -1754
- data/test/test_rdoc_parser_simple.rb +0 -99
- data/test/test_rdoc_rdoc.rb +0 -164
- data/test/test_rdoc_require.rb +0 -25
- data/test/test_rdoc_ri_driver.rb +0 -846
- data/test/test_rdoc_ri_paths.rb +0 -43
- data/test/test_rdoc_ri_store.rb +0 -352
- data/test/test_rdoc_ruby_lex.rb +0 -23
- data/test/test_rdoc_stats.rb +0 -38
- data/test/test_rdoc_task.rb +0 -92
- data/test/test_rdoc_text.rb +0 -251
- data/test/test_rdoc_top_level.rb +0 -120
- data/test/xref_data.rb +0 -62
- data/test/xref_test_case.rb +0 -61
- data.tar.gz.sig +0 -3
- metadata.gz.sig +0 -0
@@ -1,11 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
##
|
2
|
-
# Collection of methods for writing parsers
|
3
|
-
# RDoc::RubyToken
|
3
|
+
# Collection of methods for writing parsers
|
4
4
|
|
5
5
|
module RDoc::Parser::RubyTools
|
6
6
|
|
7
|
-
include RDoc::RubyToken
|
8
|
-
|
9
7
|
##
|
10
8
|
# Adds a token listener +obj+, but you should probably use token_listener
|
11
9
|
|
@@ -21,38 +19,24 @@ module RDoc::Parser::RubyTools
|
|
21
19
|
tk = nil
|
22
20
|
|
23
21
|
if @tokens.empty? then
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
if @scanner_point >= @scanner.size
|
23
|
+
return nil
|
24
|
+
else
|
25
|
+
tk = @scanner[@scanner_point]
|
26
|
+
@scanner_point += 1
|
27
|
+
@read.push tk[:text]
|
28
|
+
end
|
27
29
|
else
|
28
30
|
@read.push @unget_read.shift
|
29
31
|
tk = @tokens.shift
|
30
|
-
puts "get_tk2 => #{tk.inspect}" if $TOKEN_DEBUG
|
31
32
|
end
|
32
33
|
|
33
|
-
tk
|
34
|
-
|
35
|
-
if TkSYMBEG === tk then
|
36
|
-
set_token_position tk.line_no, tk.char_no
|
37
|
-
|
38
|
-
case tk1 = get_tk
|
39
|
-
when TkId, TkOp, TkSTRING, TkDSTRING, TkSTAR, TkAMPER then
|
40
|
-
if tk1.respond_to?(:name) then
|
41
|
-
tk = Token(TkSYMBOL).set_text(":" + tk1.name)
|
42
|
-
else
|
43
|
-
tk = Token(TkSYMBOL).set_text(":" + tk1.text)
|
44
|
-
end
|
45
|
-
|
46
|
-
# remove the identifier we just read (we're about to replace it with a
|
47
|
-
# symbol)
|
48
|
-
@token_listeners.each do |obj|
|
49
|
-
obj.pop_token
|
50
|
-
end if @token_listeners
|
51
|
-
else
|
52
|
-
tk = tk1
|
53
|
-
end
|
34
|
+
if tk == nil || :on___end__ == tk[:kind]
|
35
|
+
tk = nil
|
54
36
|
end
|
55
37
|
|
38
|
+
return nil unless tk
|
39
|
+
|
56
40
|
# inform any listeners of our shiny new token
|
57
41
|
@token_listeners.each do |obj|
|
58
42
|
obj.add_token(tk)
|
@@ -70,7 +54,13 @@ module RDoc::Parser::RubyTools
|
|
70
54
|
|
71
55
|
loop do
|
72
56
|
tk = get_tk
|
73
|
-
|
57
|
+
|
58
|
+
case tk
|
59
|
+
when *tokens then
|
60
|
+
unget_tk tk
|
61
|
+
break
|
62
|
+
end
|
63
|
+
|
74
64
|
read << tk
|
75
65
|
end
|
76
66
|
|
@@ -116,19 +106,34 @@ module RDoc::Parser::RubyTools
|
|
116
106
|
@tokens = []
|
117
107
|
@unget_read = []
|
118
108
|
@nest = 0
|
109
|
+
@scanner_point = 0
|
119
110
|
end
|
120
111
|
|
121
112
|
##
|
122
|
-
# Skips whitespace tokens including newlines
|
113
|
+
# Skips whitespace tokens including newlines
|
123
114
|
|
124
|
-
def skip_tkspace
|
115
|
+
def skip_tkspace
|
125
116
|
tokens = []
|
126
117
|
|
127
|
-
while
|
128
|
-
tokens.push
|
118
|
+
while (tk = get_tk) and (:on_sp == tk[:kind] or :on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]) do
|
119
|
+
tokens.push(tk)
|
129
120
|
end
|
130
121
|
|
131
|
-
unget_tk
|
122
|
+
unget_tk(tk)
|
123
|
+
tokens
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Skips whitespace tokens excluding newlines
|
128
|
+
|
129
|
+
def skip_tkspace_without_nl
|
130
|
+
tokens = []
|
131
|
+
|
132
|
+
while (tk = get_tk) and :on_sp == tk[:kind] do
|
133
|
+
tokens.push(tk)
|
134
|
+
end
|
135
|
+
|
136
|
+
unget_tk(tk)
|
132
137
|
tokens
|
133
138
|
end
|
134
139
|
|
@@ -153,6 +158,8 @@ module RDoc::Parser::RubyTools
|
|
153
158
|
@token_listeners.each do |obj|
|
154
159
|
obj.pop_token
|
155
160
|
end if @token_listeners
|
161
|
+
|
162
|
+
nil
|
156
163
|
end
|
157
164
|
|
158
165
|
end
|
data/lib/rdoc/parser/simple.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
##
|
2
3
|
# Parse a non-source file. We basically take the whole thing as one big
|
3
4
|
# comment.
|
4
5
|
|
5
6
|
class RDoc::Parser::Simple < RDoc::Parser
|
6
7
|
|
8
|
+
include RDoc::Parser::Text
|
9
|
+
|
7
10
|
parse_files_matching(//)
|
8
11
|
|
9
12
|
attr_reader :content # :nodoc:
|
@@ -16,7 +19,7 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|
16
19
|
|
17
20
|
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
18
21
|
|
19
|
-
preprocess.handle @content, @top_level
|
22
|
+
@content = preprocess.handle @content, @top_level
|
20
23
|
end
|
21
24
|
|
22
25
|
##
|
@@ -24,20 +27,14 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|
24
27
|
|
25
28
|
def scan
|
26
29
|
comment = remove_coding_comment @content
|
27
|
-
comment =
|
30
|
+
comment = remove_private_comment comment
|
31
|
+
|
32
|
+
comment = RDoc::Comment.new comment, @top_level
|
28
33
|
|
29
34
|
@top_level.comment = comment
|
30
|
-
@top_level.parser = self.class
|
31
35
|
@top_level
|
32
36
|
end
|
33
37
|
|
34
|
-
##
|
35
|
-
# Removes comments wrapped in <tt>--/++</tt>
|
36
|
-
|
37
|
-
def remove_private_comments text
|
38
|
-
text.gsub(/^--\n.*?^\+\+/m, '').sub(/^--\n.*/m, '')
|
39
|
-
end
|
40
|
-
|
41
38
|
##
|
42
39
|
# Removes the encoding magic comment from +text+
|
43
40
|
|
@@ -45,5 +42,20 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|
45
42
|
text.sub(/\A# .*coding[=:].*$/, '')
|
46
43
|
end
|
47
44
|
|
48
|
-
|
45
|
+
##
|
46
|
+
# Removes private comments.
|
47
|
+
#
|
48
|
+
# Unlike RDoc::Comment#remove_private this implementation only looks for two
|
49
|
+
# dashes at the beginning of the line. Three or more dashes are considered
|
50
|
+
# to be a rule and ignored.
|
51
|
+
|
52
|
+
def remove_private_comment comment
|
53
|
+
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
|
54
|
+
empty = ''
|
55
|
+
empty = RDoc::Encoding.change_encoding empty, comment.encoding
|
56
|
+
|
57
|
+
comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty)
|
58
|
+
comment.sub(%r%^--\n.*%m, empty)
|
59
|
+
end
|
49
60
|
|
61
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Indicates this parser is text and doesn't contain code constructs.
|
4
|
+
#
|
5
|
+
# Include this module in a RDoc::Parser subclass to make it show up as a file,
|
6
|
+
# not as part of a class or module.
|
7
|
+
#--
|
8
|
+
# This is not named File to avoid overriding ::File
|
9
|
+
|
10
|
+
module RDoc::Parser::Text
|
11
|
+
end
|
12
|
+
|
data/lib/rdoc/parser.rb
CHANGED
@@ -1,42 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rdoc/markup/pre_process'
|
4
|
-
require 'rdoc/stats'
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
# frozen_string_literal: true
|
5
3
|
|
6
4
|
##
|
7
|
-
# A parser is simple a class that implements
|
5
|
+
# A parser is simple a class that subclasses RDoc::Parser and implements #scan
|
6
|
+
# to fill in an RDoc::TopLevel with parsed data.
|
8
7
|
#
|
9
|
-
#
|
8
|
+
# The initialize method takes an RDoc::TopLevel to fill with parsed content,
|
9
|
+
# the name of the file to be parsed, the content of the file, an RDoc::Options
|
10
|
+
# object and an RDoc::Stats object to inform the user of parsed items. The
|
11
|
+
# scan method is then called to parse the file and must return the
|
12
|
+
# RDoc::TopLevel object. By calling super these items will be set for you.
|
10
13
|
#
|
11
|
-
#
|
14
|
+
# In order to be used by RDoc the parser needs to register the file extensions
|
15
|
+
# it can parse. Use ::parse_files_matching to register extensions.
|
12
16
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# The initialize method takes a file name to be used, the body of the file,
|
16
|
-
# and an RDoc::Options object. The scan method is then called to return an
|
17
|
-
# appropriately parsed TopLevel code object.
|
18
|
-
#
|
19
|
-
# The ParseFactory is used to redirect to the correct parser given a
|
20
|
-
# filename extension. This magic works because individual parsers have to
|
21
|
-
# register themselves with us as they are loaded in. The do this using the
|
22
|
-
# following incantation
|
23
|
-
#
|
24
|
-
# require "rdoc/parser"
|
17
|
+
# require 'rdoc'
|
25
18
|
#
|
26
19
|
# class RDoc::Parser::Xyz < RDoc::Parser
|
27
|
-
# parse_files_matching /\.xyz$/
|
20
|
+
# parse_files_matching /\.xyz$/
|
28
21
|
#
|
29
|
-
# def initialize
|
30
|
-
#
|
22
|
+
# def initialize top_level, file_name, content, options, stats
|
23
|
+
# super
|
24
|
+
#
|
25
|
+
# # extra initialization if needed
|
31
26
|
# end
|
32
27
|
#
|
33
28
|
# def scan
|
34
|
-
#
|
29
|
+
# # parse file and fill in @top_level
|
35
30
|
# end
|
36
31
|
# end
|
37
|
-
#
|
38
|
-
# Just to make life interesting, if we suspect a plain text file, we also
|
39
|
-
# look for a shebang line just in case it's a potential shell script
|
40
32
|
|
41
33
|
class RDoc::Parser
|
42
34
|
|
@@ -45,8 +37,8 @@ class RDoc::Parser
|
|
45
37
|
class << self
|
46
38
|
|
47
39
|
##
|
48
|
-
#
|
49
|
-
# will
|
40
|
+
# An Array of arrays that maps file extension (or name) regular
|
41
|
+
# expressions to parser classes that will parse matching filenames.
|
50
42
|
#
|
51
43
|
# Use parse_files_matching to register a parser's file extensions.
|
52
44
|
|
@@ -54,6 +46,11 @@ class RDoc::Parser
|
|
54
46
|
|
55
47
|
end
|
56
48
|
|
49
|
+
##
|
50
|
+
# The name of the file being parsed
|
51
|
+
|
52
|
+
attr_reader :file_name
|
53
|
+
|
57
54
|
##
|
58
55
|
# Alias an extension to another extension. After this call, files ending
|
59
56
|
# "new_ext" will be parsed using the same parser as "old_ext"
|
@@ -62,7 +59,7 @@ class RDoc::Parser
|
|
62
59
|
old_ext = old_ext.sub(/^\.(.*)/, '\1')
|
63
60
|
new_ext = new_ext.sub(/^\.(.*)/, '\1')
|
64
61
|
|
65
|
-
parser =
|
62
|
+
parser = can_parse_by_name "xxx.#{old_ext}"
|
66
63
|
return false unless parser
|
67
64
|
|
68
65
|
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
|
@@ -79,48 +76,15 @@ class RDoc::Parser
|
|
79
76
|
|
80
77
|
s = File.read(file, 1024) or return false
|
81
78
|
|
82
|
-
have_encoding = s.respond_to? :encoding
|
83
|
-
|
84
|
-
if have_encoding then
|
85
|
-
return false if s.encoding != Encoding::ASCII_8BIT and s.valid_encoding?
|
86
|
-
end
|
87
|
-
|
88
79
|
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
|
89
80
|
|
90
|
-
|
91
|
-
|
81
|
+
mode = 'r:utf-8' # default source encoding has been changed to utf-8
|
82
|
+
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
|
83
|
+
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
|
84
|
+
mode = "rb:#{encoding}" if encoding
|
85
|
+
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
|
92
86
|
|
93
|
-
|
94
|
-
else
|
95
|
-
if 0.respond_to? :fdiv then
|
96
|
-
s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
|
97
|
-
else # HACK 1.8.6
|
98
|
-
(s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
##
|
104
|
-
# Processes common directives for CodeObjects for the C and Ruby parsers.
|
105
|
-
#
|
106
|
-
# Applies +directive+'s +value+ to +code_object+, if appropriate
|
107
|
-
|
108
|
-
def self.process_directive code_object, directive, value
|
109
|
-
case directive
|
110
|
-
when 'nodoc' then
|
111
|
-
code_object.document_self = nil # notify nodoc
|
112
|
-
code_object.document_children = value.downcase != 'all'
|
113
|
-
when 'doc' then
|
114
|
-
code_object.document_self = true
|
115
|
-
code_object.force_documentation = true
|
116
|
-
when 'yield', 'yields' then
|
117
|
-
# remove parameter &block
|
118
|
-
code_object.params.sub!(/,?\s*&\w+/, '') if code_object.params
|
119
|
-
|
120
|
-
code_object.block_params = value
|
121
|
-
when 'arg', 'args' then
|
122
|
-
code_object.params = value
|
123
|
-
end
|
87
|
+
not s.valid_encoding?
|
124
88
|
end
|
125
89
|
|
126
90
|
##
|
@@ -133,46 +97,100 @@ class RDoc::Parser
|
|
133
97
|
zip_signature == "PK\x03\x04" or
|
134
98
|
zip_signature == "PK\x05\x06" or
|
135
99
|
zip_signature == "PK\x07\x08"
|
100
|
+
rescue
|
101
|
+
false
|
136
102
|
end
|
137
103
|
|
138
104
|
##
|
139
105
|
# Return a parser that can handle a particular extension
|
140
106
|
|
141
|
-
def self.can_parse
|
142
|
-
parser =
|
107
|
+
def self.can_parse file_name
|
108
|
+
parser = can_parse_by_name file_name
|
143
109
|
|
144
110
|
# HACK Selenium hides a jar file using a .txt extension
|
145
111
|
return if parser == RDoc::Parser::Simple and zip? file_name
|
146
112
|
|
113
|
+
parser
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Returns a parser that can handle the extension for +file_name+. This does
|
118
|
+
# not depend upon the file being readable.
|
119
|
+
|
120
|
+
def self.can_parse_by_name file_name
|
121
|
+
_, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }
|
122
|
+
|
147
123
|
# The default parser must not parse binary files
|
148
124
|
ext_name = File.extname file_name
|
149
125
|
return parser if ext_name.empty?
|
150
|
-
|
126
|
+
|
127
|
+
if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then
|
128
|
+
case check_modeline file_name
|
129
|
+
when nil, 'rdoc' then # continue
|
130
|
+
else return nil
|
131
|
+
end
|
132
|
+
end
|
151
133
|
|
152
134
|
parser
|
135
|
+
rescue Errno::EACCES
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Returns the file type from the modeline in +file_name+
|
140
|
+
|
141
|
+
def self.check_modeline file_name
|
142
|
+
line = File.open file_name do |io|
|
143
|
+
io.gets
|
144
|
+
end
|
145
|
+
|
146
|
+
/-\*-\s*(.*?\S)\s*-\*-/ =~ line
|
147
|
+
|
148
|
+
return nil unless type = $1
|
149
|
+
|
150
|
+
if /;/ =~ type then
|
151
|
+
return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type
|
152
|
+
type = $1
|
153
|
+
end
|
154
|
+
|
155
|
+
return nil if /coding:/i =~ type
|
156
|
+
|
157
|
+
type.downcase
|
158
|
+
rescue ArgumentError
|
159
|
+
rescue Encoding::InvalidByteSequenceError # invalid byte sequence
|
160
|
+
|
153
161
|
end
|
154
162
|
|
155
163
|
##
|
156
|
-
#
|
157
|
-
#
|
164
|
+
# Finds and instantiates the correct parser for the given +file_name+ and
|
165
|
+
# +content+.
|
158
166
|
|
159
|
-
def self.for
|
167
|
+
def self.for top_level, file_name, content, options, stats
|
160
168
|
return if binary? file_name
|
161
169
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
170
|
+
parser = use_markup content
|
171
|
+
|
172
|
+
unless parser then
|
173
|
+
parse_name = file_name
|
174
|
+
|
175
|
+
# If no extension, look for shebang
|
176
|
+
if file_name !~ /\.\w+$/ && content =~ %r{\A#!(.+)} then
|
177
|
+
shebang = $1
|
178
|
+
case shebang
|
179
|
+
when %r{env\s+ruby}, %r{/ruby}
|
180
|
+
parse_name = 'dummy.rb'
|
181
|
+
end
|
168
182
|
end
|
169
|
-
end
|
170
183
|
|
171
|
-
|
184
|
+
parser = can_parse parse_name
|
185
|
+
end
|
172
186
|
|
173
187
|
return unless parser
|
174
188
|
|
175
|
-
|
189
|
+
content = remove_modeline content
|
190
|
+
|
191
|
+
parser.new top_level, file_name, content, options, stats
|
192
|
+
rescue SystemCallError
|
193
|
+
nil
|
176
194
|
end
|
177
195
|
|
178
196
|
##
|
@@ -185,20 +203,75 @@ class RDoc::Parser
|
|
185
203
|
end
|
186
204
|
|
187
205
|
##
|
188
|
-
#
|
189
|
-
|
206
|
+
# Removes an emacs-style modeline from the first line of the document
|
207
|
+
|
208
|
+
def self.remove_modeline content
|
209
|
+
content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
|
210
|
+
end
|
211
|
+
|
212
|
+
##
|
213
|
+
# If there is a <tt>markup: parser_name</tt> comment at the front of the
|
214
|
+
# file, use it to determine the parser. For example:
|
215
|
+
#
|
216
|
+
# # markup: rdoc
|
217
|
+
# # Class comment can go here
|
218
|
+
#
|
219
|
+
# class C
|
220
|
+
# end
|
190
221
|
#
|
191
|
-
#
|
222
|
+
# The comment should appear as the first line of the +content+.
|
223
|
+
#
|
224
|
+
# If the content contains a shebang or editor modeline the comment may
|
225
|
+
# appear on the second or third line.
|
226
|
+
#
|
227
|
+
# Any comment style may be used to hide the markup comment.
|
228
|
+
|
229
|
+
def self.use_markup content
|
230
|
+
markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
|
231
|
+
|
232
|
+
return unless markup
|
233
|
+
|
234
|
+
# TODO Ruby should be returned only when the filename is correct
|
235
|
+
return RDoc::Parser::Ruby if %w[tomdoc markdown].include? markup
|
236
|
+
|
237
|
+
markup = Regexp.escape markup
|
238
|
+
|
239
|
+
_, selected = RDoc::Parser.parsers.find do |_, parser|
|
240
|
+
/^#{markup}$/i =~ parser.name.sub(/.*:/, '')
|
241
|
+
end
|
192
242
|
|
193
|
-
|
243
|
+
selected
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# Creates a new Parser storing +top_level+, +file_name+, +content+,
|
248
|
+
# +options+ and +stats+ in instance variables. In +@preprocess+ an
|
249
|
+
# RDoc::Markup::PreProcess object is created which allows processing of
|
250
|
+
# directives.
|
251
|
+
|
252
|
+
def initialize top_level, file_name, content, options, stats
|
194
253
|
@top_level = top_level
|
254
|
+
@top_level.parser = self.class
|
255
|
+
@store = @top_level.store
|
256
|
+
|
195
257
|
@file_name = file_name
|
196
258
|
@content = content
|
197
259
|
@options = options
|
198
260
|
@stats = stats
|
261
|
+
|
262
|
+
@preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
263
|
+
@preprocess.options = @options
|
199
264
|
end
|
200
265
|
|
201
|
-
|
266
|
+
autoload :RubyTools, 'rdoc/parser/ruby_tools'
|
267
|
+
autoload :Text, 'rdoc/parser/text'
|
202
268
|
|
203
|
-
|
269
|
+
end
|
204
270
|
|
271
|
+
# simple must come first in order to show up last in the parsers list
|
272
|
+
require_relative 'parser/simple'
|
273
|
+
require_relative 'parser/c'
|
274
|
+
require_relative 'parser/changelog'
|
275
|
+
require_relative 'parser/markdown'
|
276
|
+
require_relative 'parser/rd'
|
277
|
+
require_relative 'parser/ruby'
|