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.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -3
  3. data/RI.md +75 -75
  4. data/exe/rdoc +2 -2
  5. data/lib/rdoc/code_object/alias.rb +71 -69
  6. data/lib/rdoc/code_object/any_method.rb +305 -303
  7. data/lib/rdoc/code_object/attr.rb +150 -148
  8. data/lib/rdoc/code_object/class_module.rb +798 -792
  9. data/lib/rdoc/code_object/constant.rb +175 -173
  10. data/lib/rdoc/code_object/context/section.rb +142 -138
  11. data/lib/rdoc/code_object/context.rb +926 -958
  12. data/lib/rdoc/code_object/extend.rb +7 -5
  13. data/lib/rdoc/code_object/include.rb +7 -5
  14. data/lib/rdoc/code_object/method_attr.rb +326 -319
  15. data/lib/rdoc/code_object/mixin.rb +97 -95
  16. data/lib/rdoc/code_object/normal_class.rb +77 -78
  17. data/lib/rdoc/code_object/normal_module.rb +61 -59
  18. data/lib/rdoc/code_object/require.rb +23 -39
  19. data/lib/rdoc/code_object/single_class.rb +21 -19
  20. data/lib/rdoc/code_object/top_level.rb +212 -219
  21. data/lib/rdoc/code_object.rb +305 -303
  22. data/lib/rdoc/comment.rb +275 -273
  23. data/lib/rdoc/cross_reference.rb +192 -190
  24. data/lib/rdoc/encoding.rb +105 -103
  25. data/lib/rdoc/erb_partial.rb +13 -11
  26. data/lib/rdoc/erbio.rb +29 -27
  27. data/lib/rdoc/generator/aliki.rb +161 -153
  28. data/lib/rdoc/generator/darkfish.rb +645 -635
  29. data/lib/rdoc/generator/json_index.rb +233 -229
  30. data/lib/rdoc/generator/markup.rb +164 -146
  31. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  32. data/lib/rdoc/generator/pot/po.rb +52 -51
  33. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  34. data/lib/rdoc/generator/pot.rb +85 -81
  35. data/lib/rdoc/generator/ri.rb +23 -19
  36. data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
  37. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  38. data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
  39. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  40. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  41. data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
  42. data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  44. data/lib/rdoc/generator.rb +48 -46
  45. data/lib/rdoc/i18n/locale.rb +99 -95
  46. data/lib/rdoc/i18n/text.rb +109 -105
  47. data/lib/rdoc/i18n.rb +7 -5
  48. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  49. data/lib/rdoc/markdown.kpeg +15 -11
  50. data/lib/rdoc/markdown.rb +40 -47
  51. data/lib/rdoc/markup/block_quote.rb +12 -8
  52. data/lib/rdoc/markup/document.rb +127 -123
  53. data/lib/rdoc/markup/formatter.rb +219 -215
  54. data/lib/rdoc/markup/include.rb +33 -29
  55. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  56. data/lib/rdoc/markup/inline_parser.rb +281 -277
  57. data/lib/rdoc/markup/list.rb +80 -88
  58. data/lib/rdoc/markup/list_item.rb +73 -85
  59. data/lib/rdoc/markup/paragraph.rb +23 -19
  60. data/lib/rdoc/markup/parser.rb +501 -497
  61. data/lib/rdoc/markup/pre_process.rb +283 -279
  62. data/lib/rdoc/markup/raw.rb +2 -2
  63. data/lib/rdoc/markup/rule.rb +16 -12
  64. data/lib/rdoc/markup/to_ansi.rb +143 -139
  65. data/lib/rdoc/markup/to_bs.rb +72 -68
  66. data/lib/rdoc/markup/to_html.rb +594 -565
  67. data/lib/rdoc/markup/to_html_crossref.rb +234 -230
  68. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  69. data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
  70. data/lib/rdoc/markup/to_label.rb +63 -59
  71. data/lib/rdoc/markup/to_markdown.rb +212 -208
  72. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  73. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  74. data/lib/rdoc/markup/to_test.rb +60 -56
  75. data/lib/rdoc/markup/to_tt_only.rb +84 -80
  76. data/lib/rdoc/markup/verbatim.rb +62 -58
  77. data/lib/rdoc/markup.rb +198 -196
  78. data/lib/rdoc/options.rb +1063 -1061
  79. data/lib/rdoc/parser/c.rb +1039 -1037
  80. data/lib/rdoc/parser/changelog.rb +319 -315
  81. data/lib/rdoc/parser/markdown.rb +17 -13
  82. data/lib/rdoc/parser/rbs.rb +239 -235
  83. data/lib/rdoc/parser/rd.rb +17 -13
  84. data/lib/rdoc/parser/ruby.rb +1245 -1124
  85. data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
  86. data/lib/rdoc/parser/simple.rb +31 -27
  87. data/lib/rdoc/parser/text.rb +12 -8
  88. data/lib/rdoc/parser.rb +228 -220
  89. data/lib/rdoc/rbs_helper.rb +1 -1
  90. data/lib/rdoc/rd/inline.rb +57 -53
  91. data/lib/rdoc/rd.rb +90 -88
  92. data/lib/rdoc/rdoc.rb +500 -491
  93. data/lib/rdoc/ri/driver.rb +1140 -1135
  94. data/lib/rdoc/ri/formatter.rb +7 -3
  95. data/lib/rdoc/ri/paths.rb +140 -136
  96. data/lib/rdoc/ri/servlet.rb +354 -350
  97. data/lib/rdoc/ri/store.rb +4 -2
  98. data/lib/rdoc/ri/task.rb +55 -51
  99. data/lib/rdoc/ri.rb +14 -12
  100. data/lib/rdoc/rubygems_hook.rb +183 -181
  101. data/lib/rdoc/server.rb +349 -347
  102. data/lib/rdoc/stats/normal.rb +46 -42
  103. data/lib/rdoc/stats/quiet.rb +39 -35
  104. data/lib/rdoc/stats/verbose.rb +35 -31
  105. data/lib/rdoc/stats.rb +365 -363
  106. data/lib/rdoc/store.rb +888 -902
  107. data/lib/rdoc/task.rb +260 -256
  108. data/lib/rdoc/text.rb +135 -133
  109. data/lib/rdoc/token_stream.rb +101 -93
  110. data/lib/rdoc/tom_doc.rb +203 -201
  111. data/lib/rdoc/version.rb +1 -1
  112. metadata +4 -5
  113. data/lib/rdoc/markdown/literals.kpeg +0 -21
  114. data/lib/rdoc/markdown/literals.rb +0 -454
@@ -3,251 +3,301 @@
3
3
  require 'prism'
4
4
  require 'set'
5
5
 
6
- # Ruby code syntax highlighter.
7
- # Colorize result is an array of +RDoc::Parser::RubyColorizer::ColoredToken+
8
- # Actual color for each token kind is determined elsewhere (e.g., HTML generator)
9
- module RDoc::Parser::RubyColorizer
10
-
11
- ColoredToken = Struct.new(:kind, :text)
12
-
13
- # Prism operator token types except assignment '='
14
- OP_TOKENS = %i[
15
- AMPERSAND AMPERSAND_AMPERSAND
16
- BANG BANG_EQUAL BANG_TILDE CARET COLON COLON_COLON
17
- EQUAL_EQUAL EQUAL_GREATER EQUAL_TILDE
18
- GREATER GREATER_GREATER
19
- LESS LESS_EQUAL LESS_EQUAL_GREATER LESS_LESS
20
- MINUS MINUS_GREATER PERCENT PIPE PIPE_PIPE PLUS
21
- QUESTION_MARK SLASH STAR STAR_STAR TILDE
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
- # Colorize partial +node+ in +whole_code+ and returns colored token stream.
61
- def partial_colorize(whole_code, node, prism_tokens, start_offset = nil, end_offset = nil)
62
- start_offset ||= node.location.start_offset
63
- end_offset ||= node.location.end_offset
64
- visitor = NodeColorizeVisitor.new
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
- private
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
- def slice_by_location(items, start_offset, end_offset)
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
- # Unify prior tokens and normal tokens into a single token stream.
82
- # Prior tokens have higher priority than normal tokens.
83
- # Also adds missing text (spaces, newlines, etc.) as :plain tokens
84
- # so that the entire range is covered.
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
- # Add missing text such as spaces and newlines as a separate :plain token
90
- flush = -> next_offset {
91
- return if offset == next_offset
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
- whole_code.byteslice(offset...next_offset).scan(/\n|\s+|[^\s]+/) do |text|
94
- tokens << ColoredToken.new(:plain, text)
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
- until prior_tokens.empty? && normal_tokens.empty?
99
- ptok = prior_tokens.first
100
- ntok = normal_tokens.first
101
- if ntok && (!ptok || ntok[2] <= ptok[1])
102
- token = normal_tokens.shift
103
- else
104
- token = prior_tokens.shift
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
- flush.call(start_pos)
110
- tokens << ColoredToken.new(kind, whole_code.byteslice(start_pos...end_pos))
111
- offset = end_pos
112
- end
113
- flush.call(end_offset)
114
- tokens
115
- end
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
- # Convert normal Prism tokens to [kind, start_offset, end_offset]
118
- def normal_tokens(tokens)
119
- tokens.map do |token,|
120
- kind =
121
- if token.type.start_with?('KEYWORD_')
122
- :keyword
123
- elsif OP_TOKENS.include?(token.type.to_sym)
124
- :operator
125
- else
126
- TOKEN_TYPE_MAP[token.type] || :plain
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
- [kind, token.location.start_offset, token.location.end_offset]
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
- # Visitor to determine node colorizing which can't be determined by tokens.
134
- # STRING_CONTENT/EMBEXPR_BEGIN/EMBEXPR_END in string/regexp/symbol have different colorizing
135
- class NodeColorizeVisitor < Prism::Visitor # :nodoc:
136
- attr_reader :tokens
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
- def initialize
139
- @tokens = []
140
- end
186
+ def initialize
187
+ @tokens = []
188
+ end
141
189
 
142
- def visit_symbol_node(node)
143
- # SymbolNode#location may contain heredoc content and closing
144
- # e.g., `<<A; :\\\nA\nsymbol`
145
- # So we need to colorize opening, content and closing separately.
146
- push_location(:symbol, node.opening_loc)
147
- push_location(:symbol, node.value_loc)
148
- push_location(:symbol, node.closing_loc)
149
- end
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
- def visit_interpolated_symbol_node(node)
152
- push_location(:symbol, node.opening_loc)
153
- handle_interpolated_parts(:symbol, node.parts)
154
- push_location(:symbol, node.closing_loc)
155
- end
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
- def visit_regular_expression_node(node)
158
- push_location(:regexp, node.location)
159
- end
205
+ def visit_regular_expression_node(node)
206
+ push_location(:regexp, node.location)
207
+ end
160
208
 
161
- def visit_interpolated_regular_expression_node(node)
162
- push_location(:regexp, node.opening_loc)
163
- handle_interpolated_parts(:regexp, node.parts)
164
- push_location(:regexp, node.closing_loc)
165
- end
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
- alias visit_match_last_line_node visit_regular_expression_node
168
- alias visit_interpolated_match_last_line_node visit_interpolated_regular_expression_node
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
- def visit_string_node(node)
171
- # Node's location may not cover the entire string literal.
172
- # For example, in a heredoc string, the node's location covers only the heredoc opening.
173
- # We need to colorize opening, content and closing separately.
174
- push_location(:string, node.opening_loc)
175
- push_location(:string, node.content_loc)
176
- push_location(:string, node.closing_loc)
177
- end
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
- def visit_interpolated_string_node(node)
180
- push_location(:string, node.opening_loc)
181
- handle_interpolated_parts(:string, node.parts)
182
- push_location(:string, node.closing_loc)
183
- end
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
- def visit_x_string_node(node)
186
- # Same as visit_string_node, node.location of <<`X` only covers opening,
187
- # so we need to colorize opening, content and closing separately.
188
- push_location(:x_string, node.opening_loc)
189
- push_location(:x_string, node.content_loc)
190
- push_location(:x_string, node.closing_loc)
191
- end
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
- def visit_interpolated_x_string_node(node)
194
- push_location(:x_string, node.opening_loc)
195
- handle_interpolated_parts(:x_string, node.parts)
196
- push_location(:x_string, node.closing_loc)
197
- end
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
- def visit_array_node(node)
200
- super
201
- # Colorize %w[...] array literal like string literals, and %i[...] like symbol literals
202
- case node.opening
203
- when /\A%[wW].\z/
204
- push_location(:string, node.opening_loc)
205
- push_location(:string, node.closing_loc)
206
- when /\A%[iI].\z/
207
- push_location(:symbol, node.opening_loc)
208
- push_location(:symbol, node.closing_loc)
209
- end
210
- end
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
- def visit_def_node(node)
213
- # For special colorizing of method name in def node
214
- # e.g., `def <=>; end`
215
- push_location(:identifier, node.name_loc)
216
- super
217
- end
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
- private
267
+ private
220
268
 
221
- def push_location(kind, location)
222
- # Only push tokens that have a non-zero length
223
- if location && location.start_offset < location.end_offset
224
- @tokens << [kind, location.start_offset, location.end_offset]
225
- end
226
- end
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
- def handle_interpolated_parts(kind, parts)
229
- # StringNode, EmbeddedStatementsNode brackets, and EmbeddedVariableNode hash in
230
- # interpolated regexp/symbol/string parts should be colored as regexp/symbol/string respectively.
231
- parts.each do |part|
232
- case part
233
- when Prism::StringNode
234
- # InterpolatedStringNode#parts may have its own opening/closing. e.g., `'a' "b"`
235
- push_location(kind, part.opening_loc)
236
- push_location(kind, part.content_loc)
237
- push_location(kind, part.closing_loc)
238
- when Prism::InterpolatedStringNode
239
- # InterpolatedStringNode#parts may contain InterpolatedStringNode. e.g., `'a' "#{}"`
240
- part.accept(self)
241
- when Prism::EmbeddedStatementsNode
242
- push_location(kind, part.opening_loc)
243
- push_location(kind, part.closing_loc)
244
- part.accept(self)
245
- when Prism::EmbeddedVariableNode
246
- push_location(kind, part.operator_loc)
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
@@ -1,44 +1,48 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Parse a non-source file. We basically take the whole thing as one big
4
- # comment.
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 RDoc::Parser::Simple < RDoc::Parser
8
+ class Simple < Parser
7
9
 
8
- include RDoc::Parser::Text
10
+ include Parser::Text
9
11
 
10
- parse_files_matching(//)
12
+ parse_files_matching(//)
11
13
 
12
- attr_reader :content # :nodoc:
14
+ attr_reader :content # :nodoc:
13
15
 
14
- ##
15
- # Prepare to parse a plain file
16
+ ##
17
+ # Prepare to parse a plain file
16
18
 
17
- def initialize(top_level, content, options, stats)
18
- super
19
+ def initialize(top_level, content, options, stats)
20
+ super
19
21
 
20
- preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
22
+ preprocess = Markup::PreProcess.new @file_name, @options.rdoc_include
21
23
 
22
- content = RDoc::Text.expand_tabs(@content)
23
- @content, = preprocess.run_pre_processes(content, @top_level, 1, :simple)
24
- end
24
+ content = ::RDoc::Text.expand_tabs(@content)
25
+ @content, = preprocess.run_pre_processes(content, @top_level, 1, :simple)
26
+ end
25
27
 
26
- ##
27
- # Extract the file contents and attach them to the TopLevel as a comment
28
+ ##
29
+ # Extract the file contents and attach them to the TopLevel as a comment
28
30
 
29
- def scan
30
- content = remove_coding_comment @content
31
+ def scan
32
+ content = remove_coding_comment @content
31
33
 
32
- comment = RDoc::Comment.new content, @top_level
34
+ comment = Comment.new content, @top_level
33
35
 
34
- @top_level.comment = comment
35
- @top_level
36
- end
36
+ @top_level.comment = comment
37
+ @top_level
38
+ end
37
39
 
38
- ##
39
- # Removes the encoding magic comment from +text+
40
+ ##
41
+ # Removes the encoding magic comment from +text+
40
42
 
41
- def remove_coding_comment(text)
42
- text.sub(/\A# .*coding[=:].*$/, '')
43
+ def remove_coding_comment(text)
44
+ text.sub(/\A# .*coding[=:].*$/, '')
45
+ end
46
+ end
43
47
  end
44
48
  end
@@ -1,11 +1,15 @@
1
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
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 RDoc::Parser::Text
12
+ module Text
13
+ end
14
+ end
11
15
  end