gitlab-rdoc 6.3.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +133 -0
- data/RI.rdoc +57 -0
- data/Rakefile +101 -0
- data/TODO.rdoc +59 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/exe/rdoc +44 -0
- data/exe/ri +12 -0
- data/lib/rdoc/alias.rb +112 -0
- data/lib/rdoc/anon_class.rb +11 -0
- data/lib/rdoc/any_method.rb +361 -0
- data/lib/rdoc/attr.rb +176 -0
- data/lib/rdoc/class_module.rb +802 -0
- data/lib/rdoc/code_object.rb +421 -0
- data/lib/rdoc/code_objects.rb +6 -0
- data/lib/rdoc/comment.rb +250 -0
- data/lib/rdoc/constant.rb +187 -0
- data/lib/rdoc/context/section.rb +232 -0
- data/lib/rdoc/context.rb +1266 -0
- data/lib/rdoc/cross_reference.rb +202 -0
- data/lib/rdoc/encoding.rb +136 -0
- data/lib/rdoc/erb_partial.rb +19 -0
- data/lib/rdoc/erbio.rb +42 -0
- data/lib/rdoc/extend.rb +10 -0
- data/lib/rdoc/generator/darkfish.rb +790 -0
- data/lib/rdoc/generator/json_index.rb +300 -0
- data/lib/rdoc/generator/markup.rb +160 -0
- 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 +31 -0
- data/lib/rdoc/generator/template/darkfish/.document +0 -0
- 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/brick.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
- data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
- 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 +51 -0
- data/lib/rdoc/ghost_method.rb +7 -0
- 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 +10 -0
- data/lib/rdoc/known_classes.rb +73 -0
- data/lib/rdoc/markdown/entities.rb +2132 -0
- data/lib/rdoc/markdown/literals.kpeg +23 -0
- data/lib/rdoc/markdown/literals.rb +417 -0
- data/lib/rdoc/markdown.kpeg +1237 -0
- data/lib/rdoc/markdown.rb +16685 -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 +409 -0
- data/lib/rdoc/markup/attributes.rb +71 -0
- data/lib/rdoc/markup/blank_line.rb +28 -0
- data/lib/rdoc/markup/block_quote.rb +15 -0
- data/lib/rdoc/markup/document.rb +165 -0
- data/lib/rdoc/markup/formatter.rb +266 -0
- data/lib/rdoc/markup/hard_break.rb +32 -0
- data/lib/rdoc/markup/heading.rb +79 -0
- data/lib/rdoc/markup/include.rb +43 -0
- data/lib/rdoc/markup/indented_paragraph.rb +48 -0
- data/lib/rdoc/markup/list.rb +102 -0
- data/lib/rdoc/markup/list_item.rb +100 -0
- data/lib/rdoc/markup/paragraph.rb +29 -0
- data/lib/rdoc/markup/parser.rb +575 -0
- data/lib/rdoc/markup/pre_process.rb +296 -0
- data/lib/rdoc/markup/raw.rb +70 -0
- data/lib/rdoc/markup/regexp_handling.rb +41 -0
- data/lib/rdoc/markup/rule.rb +21 -0
- data/lib/rdoc/markup/table.rb +47 -0
- data/lib/rdoc/markup/to_ansi.rb +94 -0
- data/lib/rdoc/markup/to_bs.rb +77 -0
- data/lib/rdoc/markup/to_html.rb +444 -0
- data/lib/rdoc/markup/to_html_crossref.rb +176 -0
- 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 +362 -0
- data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
- data/lib/rdoc/markup/to_test.rb +70 -0
- data/lib/rdoc/markup/to_tt_only.rb +121 -0
- data/lib/rdoc/markup/verbatim.rb +84 -0
- data/lib/rdoc/markup.rb +867 -0
- data/lib/rdoc/meta_method.rb +7 -0
- data/lib/rdoc/method_attr.rb +419 -0
- data/lib/rdoc/mixin.rb +121 -0
- data/lib/rdoc/normal_class.rb +93 -0
- data/lib/rdoc/normal_module.rb +74 -0
- data/lib/rdoc/options.rb +1285 -0
- data/lib/rdoc/parser/c.rb +1225 -0
- 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 +2327 -0
- data/lib/rdoc/parser/ruby_tools.rb +167 -0
- data/lib/rdoc/parser/simple.rb +61 -0
- data/lib/rdoc/parser/text.rb +12 -0
- data/lib/rdoc/parser.rb +277 -0
- 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 +579 -0
- data/lib/rdoc/require.rb +52 -0
- data/lib/rdoc/ri/driver.rb +1572 -0
- data/lib/rdoc/ri/formatter.rb +6 -0
- data/lib/rdoc/ri/paths.rb +171 -0
- data/lib/rdoc/ri/store.rb +7 -0
- data/lib/rdoc/ri/task.rb +71 -0
- data/lib/rdoc/ri.rb +21 -0
- data/lib/rdoc/rubygems_hook.rb +246 -0
- data/lib/rdoc/servlet.rb +451 -0
- data/lib/rdoc/single_class.rb +26 -0
- data/lib/rdoc/stats/normal.rb +58 -0
- data/lib/rdoc/stats/quiet.rb +60 -0
- data/lib/rdoc/stats/verbose.rb +46 -0
- data/lib/rdoc/stats.rb +462 -0
- data/lib/rdoc/store.rb +979 -0
- data/lib/rdoc/task.rb +329 -0
- data/lib/rdoc/text.rb +304 -0
- data/lib/rdoc/token_stream.rb +119 -0
- data/lib/rdoc/tom_doc.rb +263 -0
- data/lib/rdoc/top_level.rb +289 -0
- data/lib/rdoc/version.rb +8 -0
- data/lib/rdoc.rb +201 -0
- data/man/ri.1 +247 -0
- data/rdoc.gemspec +249 -0
- metadata +279 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Collection of methods for writing parsers
|
4
|
+
|
5
|
+
module RDoc::Parser::RubyTools
|
6
|
+
|
7
|
+
##
|
8
|
+
# Adds a token listener +obj+, but you should probably use token_listener
|
9
|
+
|
10
|
+
def add_token_listener(obj)
|
11
|
+
@token_listeners ||= []
|
12
|
+
@token_listeners << obj
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Fetches the next token from the scanner
|
17
|
+
|
18
|
+
def get_tk
|
19
|
+
tk = nil
|
20
|
+
|
21
|
+
if @tokens.empty? then
|
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
|
29
|
+
else
|
30
|
+
@read.push @unget_read.shift
|
31
|
+
tk = @tokens.shift
|
32
|
+
end
|
33
|
+
|
34
|
+
if tk == nil || :on___end__ == tk[:kind]
|
35
|
+
tk = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
return nil unless tk
|
39
|
+
|
40
|
+
# inform any listeners of our shiny new token
|
41
|
+
@token_listeners.each do |obj|
|
42
|
+
obj.add_token(tk)
|
43
|
+
end if @token_listeners
|
44
|
+
|
45
|
+
tk
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Reads and returns all tokens up to one of +tokens+. Leaves the matched
|
50
|
+
# token in the token list.
|
51
|
+
|
52
|
+
def get_tk_until(*tokens)
|
53
|
+
read = []
|
54
|
+
|
55
|
+
loop do
|
56
|
+
tk = get_tk
|
57
|
+
|
58
|
+
case tk
|
59
|
+
when *tokens then
|
60
|
+
unget_tk tk
|
61
|
+
break
|
62
|
+
end
|
63
|
+
|
64
|
+
read << tk
|
65
|
+
end
|
66
|
+
|
67
|
+
read
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Retrieves a String representation of the read tokens
|
72
|
+
|
73
|
+
def get_tkread
|
74
|
+
read = @read.join("")
|
75
|
+
@read = []
|
76
|
+
read
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Peek equivalent for get_tkread
|
81
|
+
|
82
|
+
def peek_read
|
83
|
+
@read.join('')
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Peek at the next token, but don't remove it from the stream
|
88
|
+
|
89
|
+
def peek_tk
|
90
|
+
unget_tk(tk = get_tk)
|
91
|
+
tk
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Removes the token listener +obj+
|
96
|
+
|
97
|
+
def remove_token_listener(obj)
|
98
|
+
@token_listeners.delete(obj)
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Resets the tools
|
103
|
+
|
104
|
+
def reset
|
105
|
+
@read = []
|
106
|
+
@tokens = []
|
107
|
+
@unget_read = []
|
108
|
+
@nest = 0
|
109
|
+
@scanner_point = 0
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Skips whitespace tokens including newlines
|
114
|
+
|
115
|
+
def skip_tkspace
|
116
|
+
tokens = []
|
117
|
+
|
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)
|
120
|
+
end
|
121
|
+
|
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)
|
137
|
+
tokens
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Has +obj+ listen to tokens
|
142
|
+
|
143
|
+
def token_listener(obj)
|
144
|
+
add_token_listener obj
|
145
|
+
yield
|
146
|
+
ensure
|
147
|
+
remove_token_listener obj
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Returns +tk+ to the scanner
|
152
|
+
|
153
|
+
def unget_tk(tk)
|
154
|
+
@tokens.unshift tk
|
155
|
+
@unget_read.unshift @read.pop
|
156
|
+
|
157
|
+
# Remove this token from any listeners
|
158
|
+
@token_listeners.each do |obj|
|
159
|
+
obj.pop_token
|
160
|
+
end if @token_listeners
|
161
|
+
|
162
|
+
nil
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Parse a non-source file. We basically take the whole thing as one big
|
4
|
+
# comment.
|
5
|
+
|
6
|
+
class RDoc::Parser::Simple < RDoc::Parser
|
7
|
+
|
8
|
+
include RDoc::Parser::Text
|
9
|
+
|
10
|
+
parse_files_matching(//)
|
11
|
+
|
12
|
+
attr_reader :content # :nodoc:
|
13
|
+
|
14
|
+
##
|
15
|
+
# Prepare to parse a plain file
|
16
|
+
|
17
|
+
def initialize(top_level, file_name, content, options, stats)
|
18
|
+
super
|
19
|
+
|
20
|
+
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
21
|
+
|
22
|
+
@content = preprocess.handle @content, @top_level
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Extract the file contents and attach them to the TopLevel as a comment
|
27
|
+
|
28
|
+
def scan
|
29
|
+
comment = remove_coding_comment @content
|
30
|
+
comment = remove_private_comment comment
|
31
|
+
|
32
|
+
comment = RDoc::Comment.new comment, @top_level
|
33
|
+
|
34
|
+
@top_level.comment = comment
|
35
|
+
@top_level
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Removes the encoding magic comment from +text+
|
40
|
+
|
41
|
+
def remove_coding_comment text
|
42
|
+
text.sub(/\A# .*coding[=:].*$/, '')
|
43
|
+
end
|
44
|
+
|
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
|
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
ADDED
@@ -0,0 +1,277 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
##
|
5
|
+
# A parser is simple a class that subclasses RDoc::Parser and implements #scan
|
6
|
+
# to fill in an RDoc::TopLevel with parsed data.
|
7
|
+
#
|
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.
|
13
|
+
#
|
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.
|
16
|
+
#
|
17
|
+
# require 'rdoc'
|
18
|
+
#
|
19
|
+
# class RDoc::Parser::Xyz < RDoc::Parser
|
20
|
+
# parse_files_matching /\.xyz$/
|
21
|
+
#
|
22
|
+
# def initialize top_level, file_name, content, options, stats
|
23
|
+
# super
|
24
|
+
#
|
25
|
+
# # extra initialization if needed
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# def scan
|
29
|
+
# # parse file and fill in @top_level
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
class RDoc::Parser
|
34
|
+
|
35
|
+
@parsers = []
|
36
|
+
|
37
|
+
class << self
|
38
|
+
|
39
|
+
##
|
40
|
+
# An Array of arrays that maps file extension (or name) regular
|
41
|
+
# expressions to parser classes that will parse matching filenames.
|
42
|
+
#
|
43
|
+
# Use parse_files_matching to register a parser's file extensions.
|
44
|
+
|
45
|
+
attr_reader :parsers
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# The name of the file being parsed
|
51
|
+
|
52
|
+
attr_reader :file_name
|
53
|
+
|
54
|
+
##
|
55
|
+
# Alias an extension to another extension. After this call, files ending
|
56
|
+
# "new_ext" will be parsed using the same parser as "old_ext"
|
57
|
+
|
58
|
+
def self.alias_extension(old_ext, new_ext)
|
59
|
+
old_ext = old_ext.sub(/^\.(.*)/, '\1')
|
60
|
+
new_ext = new_ext.sub(/^\.(.*)/, '\1')
|
61
|
+
|
62
|
+
parser = can_parse_by_name "xxx.#{old_ext}"
|
63
|
+
return false unless parser
|
64
|
+
|
65
|
+
RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser]
|
66
|
+
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Determines if the file is a "binary" file which basically means it has
|
72
|
+
# content that an RDoc parser shouldn't try to consume.
|
73
|
+
|
74
|
+
def self.binary?(file)
|
75
|
+
return false if file =~ /\.(rdoc|txt)$/
|
76
|
+
|
77
|
+
s = File.read(file, 1024) or return false
|
78
|
+
|
79
|
+
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
|
80
|
+
|
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)}
|
86
|
+
|
87
|
+
not s.valid_encoding?
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Checks if +file+ is a zip file in disguise. Signatures from
|
92
|
+
# http://www.garykessler.net/library/file_sigs.html
|
93
|
+
|
94
|
+
def self.zip? file
|
95
|
+
zip_signature = File.read file, 4
|
96
|
+
|
97
|
+
zip_signature == "PK\x03\x04" or
|
98
|
+
zip_signature == "PK\x05\x06" or
|
99
|
+
zip_signature == "PK\x07\x08"
|
100
|
+
rescue
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Return a parser that can handle a particular extension
|
106
|
+
|
107
|
+
def self.can_parse file_name
|
108
|
+
parser = can_parse_by_name file_name
|
109
|
+
|
110
|
+
# HACK Selenium hides a jar file using a .txt extension
|
111
|
+
return if parser == RDoc::Parser::Simple and zip? file_name
|
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
|
+
|
123
|
+
# The default parser must not parse binary files
|
124
|
+
ext_name = File.extname file_name
|
125
|
+
return parser if ext_name.empty?
|
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
|
133
|
+
|
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
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Finds and instantiates the correct parser for the given +file_name+ and
|
165
|
+
# +content+.
|
166
|
+
|
167
|
+
def self.for top_level, file_name, content, options, stats
|
168
|
+
return if binary? file_name
|
169
|
+
|
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
|
182
|
+
end
|
183
|
+
|
184
|
+
parser = can_parse parse_name
|
185
|
+
end
|
186
|
+
|
187
|
+
return unless parser
|
188
|
+
|
189
|
+
content = remove_modeline content
|
190
|
+
|
191
|
+
parser.new top_level, file_name, content, options, stats
|
192
|
+
rescue SystemCallError
|
193
|
+
nil
|
194
|
+
end
|
195
|
+
|
196
|
+
##
|
197
|
+
# Record which file types this parser can understand.
|
198
|
+
#
|
199
|
+
# It is ok to call this multiple times.
|
200
|
+
|
201
|
+
def self.parse_files_matching(regexp)
|
202
|
+
RDoc::Parser.parsers.unshift [regexp, self]
|
203
|
+
end
|
204
|
+
|
205
|
+
##
|
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
|
221
|
+
#
|
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
|
242
|
+
|
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
|
253
|
+
@top_level = top_level
|
254
|
+
@top_level.parser = self.class
|
255
|
+
@store = @top_level.store
|
256
|
+
|
257
|
+
@file_name = file_name
|
258
|
+
@content = content
|
259
|
+
@options = options
|
260
|
+
@stats = stats
|
261
|
+
|
262
|
+
@preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
263
|
+
@preprocess.options = @options
|
264
|
+
end
|
265
|
+
|
266
|
+
autoload :RubyTools, 'rdoc/parser/ruby_tools'
|
267
|
+
autoload :Text, 'rdoc/parser/text'
|
268
|
+
|
269
|
+
end
|
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'
|