rdoc 8.0.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 +1 -3
- data/RI.md +75 -75
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +71 -69
- data/lib/rdoc/code_object/any_method.rb +305 -303
- data/lib/rdoc/code_object/attr.rb +150 -148
- data/lib/rdoc/code_object/class_module.rb +798 -792
- data/lib/rdoc/code_object/constant.rb +175 -173
- data/lib/rdoc/code_object/context/section.rb +142 -138
- data/lib/rdoc/code_object/context.rb +926 -958
- 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 +326 -319
- data/lib/rdoc/code_object/mixin.rb +97 -95
- 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 +212 -219
- data/lib/rdoc/code_object.rb +305 -303
- data/lib/rdoc/comment.rb +275 -273
- data/lib/rdoc/cross_reference.rb +192 -190
- 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 +161 -153
- data/lib/rdoc/generator/darkfish.rb +645 -635
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +164 -146
- 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 +6 -4
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
- data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- 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 +15 -11
- data/lib/rdoc/markdown.rb +40 -47
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/formatter.rb +219 -215
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +281 -277
- 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 +283 -279
- data/lib/rdoc/markup/raw.rb +2 -2
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/to_ansi.rb +143 -139
- data/lib/rdoc/markup/to_bs.rb +72 -68
- data/lib/rdoc/markup/to_html.rb +594 -565
- data/lib/rdoc/markup/to_html_crossref.rb +234 -230
- data/lib/rdoc/markup/to_html_snippet.rb +232 -227
- data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
- data/lib/rdoc/markup/to_label.rb +63 -59
- data/lib/rdoc/markup/to_markdown.rb +212 -208
- data/lib/rdoc/markup/to_rdoc.rb +336 -332
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +60 -56
- data/lib/rdoc/markup/to_tt_only.rb +84 -80
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +198 -196
- data/lib/rdoc/options.rb +1063 -1061
- data/lib/rdoc/parser/c.rb +1039 -1037
- data/lib/rdoc/parser/changelog.rb +319 -315
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +239 -235
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1245 -1124
- data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +228 -220
- data/lib/rdoc/rbs_helper.rb +1 -1
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +500 -491
- data/lib/rdoc/ri/driver.rb +1140 -1135
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +354 -350
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -12
- data/lib/rdoc/rubygems_hook.rb +183 -181
- data/lib/rdoc/server.rb +349 -347
- 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 +365 -363
- data/lib/rdoc/store.rb +888 -902
- data/lib/rdoc/task.rb +260 -256
- data/lib/rdoc/text.rb +135 -133
- data/lib/rdoc/token_stream.rb +101 -93
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- metadata +4 -5
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- data/lib/rdoc/markdown/literals.rb +0 -454
|
@@ -3,251 +3,301 @@
|
|
|
3
3
|
require 'prism'
|
|
4
4
|
require 'set'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
UAMPERSAND UMINUS UPLUS USTAR USTAR_STAR
|
|
23
|
-
].to_set
|
|
24
|
-
|
|
25
|
-
# Prism token type to ColoredToken kind map
|
|
26
|
-
TOKEN_TYPE_MAP = {
|
|
27
|
-
IDENTIFIER: :identifier,
|
|
28
|
-
METHOD_NAME: :identifier,
|
|
29
|
-
INSTANCE_VARIABLE: :ivar,
|
|
30
|
-
CLASS_VARIABLE: :identifier,
|
|
31
|
-
GLOBAL_VARIABLE: :identifier,
|
|
32
|
-
BACK_REFERENCE: :identifier,
|
|
33
|
-
NUMBERED_REFERENCE: :identifier,
|
|
34
|
-
CONSTANT: :constant,
|
|
35
|
-
LABEL: :value,
|
|
36
|
-
INTEGER: :value,
|
|
37
|
-
INTEGER_IMAGINARY: :value,
|
|
38
|
-
INTEGER_RATIONAL: :value,
|
|
39
|
-
INTEGER_RATIONAL_IMAGINARY: :value,
|
|
40
|
-
FLOAT: :value,
|
|
41
|
-
FLOAT_IMAGINARY: :value,
|
|
42
|
-
FLOAT_RATIONAL: :value,
|
|
43
|
-
FLOAT_RATIONAL_IMAGINARY: :value,
|
|
44
|
-
COMMENT: :comment,
|
|
45
|
-
EMBDOC_BEGIN: :comment,
|
|
46
|
-
EMBDOC_LINE: :comment,
|
|
47
|
-
EMBDOC_END: :comment
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class << self
|
|
51
|
-
|
|
52
|
-
# Colorize the entire +code+ and returns colored token stream.
|
|
53
|
-
def colorize(code)
|
|
54
|
-
result = Prism.parse_lex(code)
|
|
55
|
-
program_node, unordered_tokens = result.value
|
|
56
|
-
prism_tokens = unordered_tokens.map(&:first).sort_by! { |token| token.location.start_offset }
|
|
57
|
-
partial_colorize(code, program_node, prism_tokens, 0, code.bytesize)
|
|
58
|
-
end
|
|
6
|
+
module RDoc
|
|
7
|
+
class Parser
|
|
8
|
+
# Ruby code syntax highlighter.
|
|
9
|
+
# Colorize result is an array of +RDoc::Parser::RubyColorizer::ColoredToken+
|
|
10
|
+
# Actual color for each token kind is determined elsewhere (e.g., HTML generator)
|
|
11
|
+
module RubyColorizer
|
|
12
|
+
|
|
13
|
+
ColoredToken = Struct.new(:kind, :text)
|
|
14
|
+
|
|
15
|
+
# Defers colorization for all nodes in one source file until first access.
|
|
16
|
+
class DeferredContext # :nodoc:
|
|
17
|
+
#: (String) -> void
|
|
18
|
+
def initialize(source)
|
|
19
|
+
@source = source
|
|
20
|
+
@token_streams = {}
|
|
21
|
+
end
|
|
59
22
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
node.accept(visitor)
|
|
66
|
-
prior_tokens = visitor.tokens.sort_by {|_, start_offset, _| start_offset }
|
|
67
|
-
normal_tokens = normal_tokens(slice_by_location(prism_tokens, start_offset, end_offset))
|
|
68
|
-
colored_tokens = unify_tokens(whole_code, prior_tokens, normal_tokens, start_offset, end_offset)
|
|
69
|
-
colored_tokens.unshift(ColoredToken.new(:plain, ' ' * node.location.start_column)) if node.location.start_column > 0
|
|
70
|
-
colored_tokens
|
|
71
|
-
end
|
|
23
|
+
#: (Integer) -> ^() -> Array[ColoredToken]
|
|
24
|
+
def token_stream_loader(node_id)
|
|
25
|
+
@token_streams[node_id] = nil
|
|
26
|
+
-> { token_stream_for(node_id) }
|
|
27
|
+
end
|
|
72
28
|
|
|
73
|
-
|
|
29
|
+
#: (Integer) -> Array[ColoredToken]
|
|
30
|
+
def token_stream_for(node_id)
|
|
31
|
+
materialize unless materialized?
|
|
32
|
+
@token_streams.fetch(node_id)
|
|
33
|
+
end
|
|
74
34
|
|
|
75
|
-
|
|
76
|
-
start_index = items.bsearch_index { |item| item.location.end_offset > start_offset } || items.size
|
|
77
|
-
end_index = items.bsearch_index { |item| item.location.start_offset >= end_offset } || items.size
|
|
78
|
-
items[start_index...end_index]
|
|
79
|
-
end
|
|
35
|
+
private
|
|
80
36
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def unify_tokens(whole_code, prior_tokens, normal_tokens, start_offset, end_offset)
|
|
86
|
-
tokens = []
|
|
87
|
-
offset = start_offset
|
|
37
|
+
#: () -> Boolean
|
|
38
|
+
def materialized?
|
|
39
|
+
!@source
|
|
40
|
+
end
|
|
88
41
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
42
|
+
#: () -> void
|
|
43
|
+
def materialize
|
|
44
|
+
program_node, unordered_tokens = Prism.parse_lex(@source).value
|
|
45
|
+
prism_tokens = unordered_tokens.map(&:first).sort_by! { |token| token.location.start_offset }
|
|
46
|
+
staged_tokens = {}
|
|
47
|
+
nodes = [program_node]
|
|
48
|
+
until nodes.empty?
|
|
49
|
+
node = nodes.pop
|
|
50
|
+
if @token_streams.key?(node.node_id)
|
|
51
|
+
staged_tokens[node.node_id] = RubyColorizer.partial_colorize(@source, node, prism_tokens)
|
|
52
|
+
end
|
|
53
|
+
nodes.concat(node.compact_child_nodes)
|
|
54
|
+
end
|
|
92
55
|
|
|
93
|
-
|
|
94
|
-
|
|
56
|
+
@token_streams = staged_tokens
|
|
57
|
+
@source = nil
|
|
95
58
|
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Prism operator token types except assignment '='
|
|
62
|
+
OP_TOKENS = %i[
|
|
63
|
+
AMPERSAND AMPERSAND_AMPERSAND
|
|
64
|
+
BANG BANG_EQUAL BANG_TILDE CARET COLON COLON_COLON
|
|
65
|
+
EQUAL_EQUAL EQUAL_GREATER EQUAL_TILDE
|
|
66
|
+
GREATER GREATER_GREATER
|
|
67
|
+
LESS LESS_EQUAL LESS_EQUAL_GREATER LESS_LESS
|
|
68
|
+
MINUS MINUS_GREATER PERCENT PIPE PIPE_PIPE PLUS
|
|
69
|
+
QUESTION_MARK SLASH STAR STAR_STAR TILDE
|
|
70
|
+
UAMPERSAND UMINUS UPLUS USTAR USTAR_STAR
|
|
71
|
+
].to_set
|
|
72
|
+
|
|
73
|
+
# Prism token type to ColoredToken kind map
|
|
74
|
+
TOKEN_TYPE_MAP = {
|
|
75
|
+
IDENTIFIER: :identifier,
|
|
76
|
+
METHOD_NAME: :identifier,
|
|
77
|
+
INSTANCE_VARIABLE: :ivar,
|
|
78
|
+
CLASS_VARIABLE: :identifier,
|
|
79
|
+
GLOBAL_VARIABLE: :identifier,
|
|
80
|
+
BACK_REFERENCE: :identifier,
|
|
81
|
+
NUMBERED_REFERENCE: :identifier,
|
|
82
|
+
CONSTANT: :constant,
|
|
83
|
+
LABEL: :value,
|
|
84
|
+
INTEGER: :value,
|
|
85
|
+
INTEGER_IMAGINARY: :value,
|
|
86
|
+
INTEGER_RATIONAL: :value,
|
|
87
|
+
INTEGER_RATIONAL_IMAGINARY: :value,
|
|
88
|
+
FLOAT: :value,
|
|
89
|
+
FLOAT_IMAGINARY: :value,
|
|
90
|
+
FLOAT_RATIONAL: :value,
|
|
91
|
+
FLOAT_RATIONAL_IMAGINARY: :value,
|
|
92
|
+
COMMENT: :comment,
|
|
93
|
+
EMBDOC_BEGIN: :comment,
|
|
94
|
+
EMBDOC_LINE: :comment,
|
|
95
|
+
EMBDOC_END: :comment
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
class << self
|
|
99
|
+
|
|
100
|
+
# Colorize the entire +code+ and returns colored token stream.
|
|
101
|
+
def colorize(code)
|
|
102
|
+
result = Prism.parse_lex(code)
|
|
103
|
+
program_node, unordered_tokens = result.value
|
|
104
|
+
prism_tokens = unordered_tokens.map(&:first).sort_by! { |token| token.location.start_offset }
|
|
105
|
+
partial_colorize(code, program_node, prism_tokens, 0, code.bytesize)
|
|
105
106
|
end
|
|
106
|
-
kind, start_pos, end_pos = token
|
|
107
|
-
next if start_pos < offset
|
|
108
107
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
# Colorize partial +node+ in +whole_code+ and returns colored token stream.
|
|
109
|
+
def partial_colorize(whole_code, node, prism_tokens, start_offset = nil, end_offset = nil)
|
|
110
|
+
start_offset ||= node.location.start_offset
|
|
111
|
+
end_offset ||= node.location.end_offset
|
|
112
|
+
visitor = NodeColorizeVisitor.new
|
|
113
|
+
node.accept(visitor)
|
|
114
|
+
prior_tokens = visitor.tokens.sort_by {|_, start_offset, _| start_offset }
|
|
115
|
+
normal_tokens = normal_tokens(slice_by_location(prism_tokens, start_offset, end_offset))
|
|
116
|
+
colored_tokens = unify_tokens(whole_code, prior_tokens, normal_tokens, start_offset, end_offset)
|
|
117
|
+
colored_tokens.unshift(ColoredToken.new(:plain, ' ' * node.location.start_column)) if node.location.start_column > 0
|
|
118
|
+
colored_tokens
|
|
119
|
+
end
|
|
116
120
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
def slice_by_location(items, start_offset, end_offset)
|
|
124
|
+
start_index = items.bsearch_index { |item| item.location.end_offset > start_offset } || items.size
|
|
125
|
+
end_index = items.bsearch_index { |item| item.location.start_offset >= end_offset } || items.size
|
|
126
|
+
items[start_index...end_index]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Unify prior tokens and normal tokens into a single token stream.
|
|
130
|
+
# Prior tokens have higher priority than normal tokens.
|
|
131
|
+
# Also adds missing text (spaces, newlines, etc.) as :plain tokens
|
|
132
|
+
# so that the entire range is covered.
|
|
133
|
+
def unify_tokens(whole_code, prior_tokens, normal_tokens, start_offset, end_offset)
|
|
134
|
+
tokens = []
|
|
135
|
+
offset = start_offset
|
|
136
|
+
|
|
137
|
+
# Add missing text such as spaces and newlines as a separate :plain token
|
|
138
|
+
flush = -> next_offset {
|
|
139
|
+
return if offset == next_offset
|
|
140
|
+
|
|
141
|
+
whole_code.byteslice(offset...next_offset).scan(/\n|\s+|[^\s]+/) do |text|
|
|
142
|
+
tokens << ColoredToken.new(:plain, text)
|
|
143
|
+
end
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
until prior_tokens.empty? && normal_tokens.empty?
|
|
147
|
+
ptok = prior_tokens.first
|
|
148
|
+
ntok = normal_tokens.first
|
|
149
|
+
if ntok && (!ptok || ntok[2] <= ptok[1])
|
|
150
|
+
token = normal_tokens.shift
|
|
151
|
+
else
|
|
152
|
+
token = prior_tokens.shift
|
|
153
|
+
end
|
|
154
|
+
kind, start_pos, end_pos = token
|
|
155
|
+
next if start_pos < offset
|
|
156
|
+
|
|
157
|
+
flush.call(start_pos)
|
|
158
|
+
tokens << ColoredToken.new(kind, whole_code.byteslice(start_pos...end_pos))
|
|
159
|
+
offset = end_pos
|
|
127
160
|
end
|
|
128
|
-
|
|
161
|
+
flush.call(end_offset)
|
|
162
|
+
tokens
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Convert normal Prism tokens to [kind, start_offset, end_offset]
|
|
166
|
+
def normal_tokens(tokens)
|
|
167
|
+
tokens.map do |token,|
|
|
168
|
+
kind =
|
|
169
|
+
if token.type.start_with?('KEYWORD_')
|
|
170
|
+
:keyword
|
|
171
|
+
elsif OP_TOKENS.include?(token.type.to_sym)
|
|
172
|
+
:operator
|
|
173
|
+
else
|
|
174
|
+
TOKEN_TYPE_MAP[token.type] || :plain
|
|
175
|
+
end
|
|
176
|
+
[kind, token.location.start_offset, token.location.end_offset]
|
|
177
|
+
end
|
|
178
|
+
end
|
|
129
179
|
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
180
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
181
|
+
# Visitor to determine node colorizing which can't be determined by tokens.
|
|
182
|
+
# STRING_CONTENT/EMBEXPR_BEGIN/EMBEXPR_END in string/regexp/symbol have different colorizing
|
|
183
|
+
class NodeColorizeVisitor < Prism::Visitor # :nodoc:
|
|
184
|
+
attr_reader :tokens
|
|
137
185
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
186
|
+
def initialize
|
|
187
|
+
@tokens = []
|
|
188
|
+
end
|
|
141
189
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
190
|
+
def visit_symbol_node(node)
|
|
191
|
+
# SymbolNode#location may contain heredoc content and closing
|
|
192
|
+
# e.g., `<<A; :\\\nA\nsymbol`
|
|
193
|
+
# So we need to colorize opening, content and closing separately.
|
|
194
|
+
push_location(:symbol, node.opening_loc)
|
|
195
|
+
push_location(:symbol, node.value_loc)
|
|
196
|
+
push_location(:symbol, node.closing_loc)
|
|
197
|
+
end
|
|
150
198
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
199
|
+
def visit_interpolated_symbol_node(node)
|
|
200
|
+
push_location(:symbol, node.opening_loc)
|
|
201
|
+
handle_interpolated_parts(:symbol, node.parts)
|
|
202
|
+
push_location(:symbol, node.closing_loc)
|
|
203
|
+
end
|
|
156
204
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
205
|
+
def visit_regular_expression_node(node)
|
|
206
|
+
push_location(:regexp, node.location)
|
|
207
|
+
end
|
|
160
208
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
209
|
+
def visit_interpolated_regular_expression_node(node)
|
|
210
|
+
push_location(:regexp, node.opening_loc)
|
|
211
|
+
handle_interpolated_parts(:regexp, node.parts)
|
|
212
|
+
push_location(:regexp, node.closing_loc)
|
|
213
|
+
end
|
|
166
214
|
|
|
167
|
-
|
|
168
|
-
|
|
215
|
+
alias visit_match_last_line_node visit_regular_expression_node
|
|
216
|
+
alias visit_interpolated_match_last_line_node visit_interpolated_regular_expression_node
|
|
169
217
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
218
|
+
def visit_string_node(node)
|
|
219
|
+
# Node's location may not cover the entire string literal.
|
|
220
|
+
# For example, in a heredoc string, the node's location covers only the heredoc opening.
|
|
221
|
+
# We need to colorize opening, content and closing separately.
|
|
222
|
+
push_location(:string, node.opening_loc)
|
|
223
|
+
push_location(:string, node.content_loc)
|
|
224
|
+
push_location(:string, node.closing_loc)
|
|
225
|
+
end
|
|
178
226
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
227
|
+
def visit_interpolated_string_node(node)
|
|
228
|
+
push_location(:string, node.opening_loc)
|
|
229
|
+
handle_interpolated_parts(:string, node.parts)
|
|
230
|
+
push_location(:string, node.closing_loc)
|
|
231
|
+
end
|
|
184
232
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
233
|
+
def visit_x_string_node(node)
|
|
234
|
+
# Same as visit_string_node, node.location of <<`X` only covers opening,
|
|
235
|
+
# so we need to colorize opening, content and closing separately.
|
|
236
|
+
push_location(:x_string, node.opening_loc)
|
|
237
|
+
push_location(:x_string, node.content_loc)
|
|
238
|
+
push_location(:x_string, node.closing_loc)
|
|
239
|
+
end
|
|
192
240
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
241
|
+
def visit_interpolated_x_string_node(node)
|
|
242
|
+
push_location(:x_string, node.opening_loc)
|
|
243
|
+
handle_interpolated_parts(:x_string, node.parts)
|
|
244
|
+
push_location(:x_string, node.closing_loc)
|
|
245
|
+
end
|
|
198
246
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
247
|
+
def visit_array_node(node)
|
|
248
|
+
super
|
|
249
|
+
# Colorize %w[...] array literal like string literals, and %i[...] like symbol literals
|
|
250
|
+
case node.opening
|
|
251
|
+
when /\A%[wW].\z/
|
|
252
|
+
push_location(:string, node.opening_loc)
|
|
253
|
+
push_location(:string, node.closing_loc)
|
|
254
|
+
when /\A%[iI].\z/
|
|
255
|
+
push_location(:symbol, node.opening_loc)
|
|
256
|
+
push_location(:symbol, node.closing_loc)
|
|
257
|
+
end
|
|
258
|
+
end
|
|
211
259
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
260
|
+
def visit_def_node(node)
|
|
261
|
+
# For special colorizing of method name in def node
|
|
262
|
+
# e.g., `def <=>; end`
|
|
263
|
+
push_location(:identifier, node.name_loc)
|
|
264
|
+
super
|
|
265
|
+
end
|
|
218
266
|
|
|
219
|
-
|
|
267
|
+
private
|
|
220
268
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
269
|
+
def push_location(kind, location)
|
|
270
|
+
# Only push tokens that have a non-zero length
|
|
271
|
+
if location && location.start_offset < location.end_offset
|
|
272
|
+
@tokens << [kind, location.start_offset, location.end_offset]
|
|
273
|
+
end
|
|
274
|
+
end
|
|
227
275
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
276
|
+
def handle_interpolated_parts(kind, parts)
|
|
277
|
+
# StringNode, EmbeddedStatementsNode brackets, and EmbeddedVariableNode hash in
|
|
278
|
+
# interpolated regexp/symbol/string parts should be colored as regexp/symbol/string respectively.
|
|
279
|
+
parts.each do |part|
|
|
280
|
+
case part
|
|
281
|
+
when Prism::StringNode
|
|
282
|
+
# InterpolatedStringNode#parts may have its own opening/closing. e.g., `'a' "b"`
|
|
283
|
+
push_location(kind, part.opening_loc)
|
|
284
|
+
push_location(kind, part.content_loc)
|
|
285
|
+
push_location(kind, part.closing_loc)
|
|
286
|
+
when Prism::InterpolatedStringNode
|
|
287
|
+
# InterpolatedStringNode#parts may contain InterpolatedStringNode. e.g., `'a' "#{}"`
|
|
288
|
+
part.accept(self)
|
|
289
|
+
when Prism::EmbeddedStatementsNode
|
|
290
|
+
push_location(kind, part.opening_loc)
|
|
291
|
+
push_location(kind, part.closing_loc)
|
|
292
|
+
part.accept(self)
|
|
293
|
+
when Prism::EmbeddedVariableNode
|
|
294
|
+
push_location(kind, part.operator_loc)
|
|
295
|
+
end
|
|
296
|
+
end
|
|
247
297
|
end
|
|
248
298
|
end
|
|
299
|
+
|
|
300
|
+
private_constant :NodeColorizeVisitor
|
|
249
301
|
end
|
|
250
302
|
end
|
|
251
|
-
|
|
252
|
-
private_constant :NodeColorizeVisitor
|
|
253
303
|
end
|
data/lib/rdoc/parser/simple.rb
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Parser
|
|
4
|
+
##
|
|
5
|
+
# Parse a non-source file. We basically take the whole thing as one big
|
|
6
|
+
# comment.
|
|
5
7
|
|
|
6
|
-
class
|
|
8
|
+
class Simple < Parser
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
include Parser::Text
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
parse_files_matching(//)
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
attr_reader :content # :nodoc:
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
##
|
|
17
|
+
# Prepare to parse a plain file
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
def initialize(top_level, content, options, stats)
|
|
20
|
+
super
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
preprocess = Markup::PreProcess.new @file_name, @options.rdoc_include
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
content = ::RDoc::Text.expand_tabs(@content)
|
|
25
|
+
@content, = preprocess.run_pre_processes(content, @top_level, 1, :simple)
|
|
26
|
+
end
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
##
|
|
29
|
+
# Extract the file contents and attach them to the TopLevel as a comment
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
def scan
|
|
32
|
+
content = remove_coding_comment @content
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
comment = Comment.new content, @top_level
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
@top_level.comment = comment
|
|
37
|
+
@top_level
|
|
38
|
+
end
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
##
|
|
41
|
+
# Removes the encoding magic comment from +text+
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
def remove_coding_comment(text)
|
|
44
|
+
text.sub(/\A# .*coding[=:].*$/, '')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
43
47
|
end
|
|
44
48
|
end
|
data/lib/rdoc/parser/text.rb
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
#
|
|
2
|
+
module RDoc
|
|
3
|
+
class Parser
|
|
4
|
+
##
|
|
5
|
+
# Indicates this parser is text and doesn't contain code constructs.
|
|
6
|
+
#
|
|
7
|
+
# Include this module in a RDoc::Parser subclass to make it show up as a file,
|
|
8
|
+
# not as part of a class or module.
|
|
9
|
+
#--
|
|
10
|
+
# This is not named File to avoid overriding ::File
|
|
9
11
|
|
|
10
|
-
module
|
|
12
|
+
module Text
|
|
13
|
+
end
|
|
14
|
+
end
|
|
11
15
|
end
|