super-quick-rb 0.0.1

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 (218) hide show
  1. checksums.yaml +7 -0
  2. data/rdoc-8.0.0/CONTRIBUTING.md +195 -0
  3. data/rdoc-8.0.0/CVE-2013-0256.rdoc +49 -0
  4. data/rdoc-8.0.0/History.rdoc +1668 -0
  5. data/rdoc-8.0.0/LEGAL.rdoc +56 -0
  6. data/rdoc-8.0.0/LICENSE.rdoc +63 -0
  7. data/rdoc-8.0.0/README.md +236 -0
  8. data/rdoc-8.0.0/RI.md +842 -0
  9. data/rdoc-8.0.0/TODO.rdoc +60 -0
  10. data/rdoc-8.0.0/doc/markup_reference/markdown.md +659 -0
  11. data/rdoc-8.0.0/doc/markup_reference/rdoc.rdoc +1169 -0
  12. data/rdoc-8.0.0/exe/rdoc +43 -0
  13. data/rdoc-8.0.0/exe/ri +12 -0
  14. data/rdoc-8.0.0/lib/rdoc/code_object/alias.rb +98 -0
  15. data/rdoc-8.0.0/lib/rdoc/code_object/any_method.rb +387 -0
  16. data/rdoc-8.0.0/lib/rdoc/code_object/attr.rb +178 -0
  17. data/rdoc-8.0.0/lib/rdoc/code_object/class_module.rb +969 -0
  18. data/rdoc-8.0.0/lib/rdoc/code_object/constant.rb +221 -0
  19. data/rdoc-8.0.0/lib/rdoc/code_object/context/section.rb +182 -0
  20. data/rdoc-8.0.0/lib/rdoc/code_object/context.rb +1238 -0
  21. data/rdoc-8.0.0/lib/rdoc/code_object/extend.rb +9 -0
  22. data/rdoc-8.0.0/lib/rdoc/code_object/include.rb +9 -0
  23. data/rdoc-8.0.0/lib/rdoc/code_object/method_attr.rb +417 -0
  24. data/rdoc-8.0.0/lib/rdoc/code_object/mixin.rb +123 -0
  25. data/rdoc-8.0.0/lib/rdoc/code_object/normal_class.rb +92 -0
  26. data/rdoc-8.0.0/lib/rdoc/code_object/normal_module.rb +73 -0
  27. data/rdoc-8.0.0/lib/rdoc/code_object/require.rb +51 -0
  28. data/rdoc-8.0.0/lib/rdoc/code_object/single_class.rb +30 -0
  29. data/rdoc-8.0.0/lib/rdoc/code_object/top_level.rb +286 -0
  30. data/rdoc-8.0.0/lib/rdoc/code_object.rb +393 -0
  31. data/rdoc-8.0.0/lib/rdoc/code_objects.rb +5 -0
  32. data/rdoc-8.0.0/lib/rdoc/comment.rb +353 -0
  33. data/rdoc-8.0.0/lib/rdoc/cross_reference.rb +215 -0
  34. data/rdoc-8.0.0/lib/rdoc/encoding.rb +120 -0
  35. data/rdoc-8.0.0/lib/rdoc/erb_partial.rb +18 -0
  36. data/rdoc-8.0.0/lib/rdoc/erbio.rb +37 -0
  37. data/rdoc-8.0.0/lib/rdoc/generator/aliki.rb +200 -0
  38. data/rdoc-8.0.0/lib/rdoc/generator/darkfish.rb +824 -0
  39. data/rdoc-8.0.0/lib/rdoc/generator/json_index.rb +284 -0
  40. data/rdoc-8.0.0/lib/rdoc/generator/markup.rb +196 -0
  41. data/rdoc-8.0.0/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  42. data/rdoc-8.0.0/lib/rdoc/generator/pot/po.rb +84 -0
  43. data/rdoc-8.0.0/lib/rdoc/generator/pot/po_entry.rb +141 -0
  44. data/rdoc-8.0.0/lib/rdoc/generator/pot.rb +94 -0
  45. data/rdoc-8.0.0/lib/rdoc/generator/ri.rb +30 -0
  46. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  47. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  48. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  49. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
  50. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  51. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  52. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  53. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  54. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
  55. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
  56. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  57. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  58. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  59. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  60. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  61. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  62. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
  63. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
  64. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  65. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
  66. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  67. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  68. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  69. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  70. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  71. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  72. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  73. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  74. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  75. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  76. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_head.rhtml +43 -0
  77. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +5 -0
  78. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +17 -0
  79. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +17 -0
  80. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +16 -0
  81. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +21 -0
  82. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  83. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +32 -0
  84. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +6 -0
  85. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +15 -0
  86. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  87. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +39 -0
  88. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  89. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/class.rhtml +220 -0
  90. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  91. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/css/rdoc.css +701 -0
  92. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  93. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  94. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  95. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  96. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  97. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  98. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  99. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  100. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  101. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  102. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  103. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  104. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  105. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  106. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  107. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  108. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  109. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  110. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  111. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  112. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  113. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  114. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  115. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  116. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  117. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  118. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  119. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  120. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  121. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  122. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  123. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/index.rhtml +24 -0
  124. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/js/darkfish.js +140 -0
  125. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/js/search.js +120 -0
  126. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/page.rhtml +19 -0
  127. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +21 -0
  128. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +65 -0
  129. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +72 -0
  130. data/rdoc-8.0.0/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  131. data/rdoc-8.0.0/lib/rdoc/generator/template/json_index/js/searcher.js +271 -0
  132. data/rdoc-8.0.0/lib/rdoc/generator.rb +52 -0
  133. data/rdoc-8.0.0/lib/rdoc/i18n/locale.rb +102 -0
  134. data/rdoc-8.0.0/lib/rdoc/i18n/text.rb +126 -0
  135. data/rdoc-8.0.0/lib/rdoc/i18n.rb +10 -0
  136. data/rdoc-8.0.0/lib/rdoc/known_classes.rb +74 -0
  137. data/rdoc-8.0.0/lib/rdoc/markdown/entities.rb +2131 -0
  138. data/rdoc-8.0.0/lib/rdoc/markdown/literals.kpeg +21 -0
  139. data/rdoc-8.0.0/lib/rdoc/markdown/literals.rb +454 -0
  140. data/rdoc-8.0.0/lib/rdoc/markdown.kpeg +1315 -0
  141. data/rdoc-8.0.0/lib/rdoc/markdown.rb +16865 -0
  142. data/rdoc-8.0.0/lib/rdoc/markup/blank_line.rb +29 -0
  143. data/rdoc-8.0.0/lib/rdoc/markup/block_quote.rb +14 -0
  144. data/rdoc-8.0.0/lib/rdoc/markup/document.rb +164 -0
  145. data/rdoc-8.0.0/lib/rdoc/markup/element.rb +21 -0
  146. data/rdoc-8.0.0/lib/rdoc/markup/formatter.rb +285 -0
  147. data/rdoc-8.0.0/lib/rdoc/markup/hard_break.rb +34 -0
  148. data/rdoc-8.0.0/lib/rdoc/markup/heading.rb +170 -0
  149. data/rdoc-8.0.0/lib/rdoc/markup/include.rb +42 -0
  150. data/rdoc-8.0.0/lib/rdoc/markup/indented_paragraph.rb +47 -0
  151. data/rdoc-8.0.0/lib/rdoc/markup/inline_parser.rb +312 -0
  152. data/rdoc-8.0.0/lib/rdoc/markup/list.rb +101 -0
  153. data/rdoc-8.0.0/lib/rdoc/markup/list_item.rb +99 -0
  154. data/rdoc-8.0.0/lib/rdoc/markup/paragraph.rb +28 -0
  155. data/rdoc-8.0.0/lib/rdoc/markup/parser.rb +585 -0
  156. data/rdoc-8.0.0/lib/rdoc/markup/pre_process.rb +317 -0
  157. data/rdoc-8.0.0/lib/rdoc/markup/raw.rb +66 -0
  158. data/rdoc-8.0.0/lib/rdoc/markup/rule.rb +20 -0
  159. data/rdoc-8.0.0/lib/rdoc/markup/table.rb +64 -0
  160. data/rdoc-8.0.0/lib/rdoc/markup/to_ansi.rb +144 -0
  161. data/rdoc-8.0.0/lib/rdoc/markup/to_bs.rb +86 -0
  162. data/rdoc-8.0.0/lib/rdoc/markup/to_html.rb +682 -0
  163. data/rdoc-8.0.0/lib/rdoc/markup/to_html_crossref.rb +261 -0
  164. data/rdoc-8.0.0/lib/rdoc/markup/to_html_snippet.rb +287 -0
  165. data/rdoc-8.0.0/lib/rdoc/markup/to_joined_paragraph.rb +41 -0
  166. data/rdoc-8.0.0/lib/rdoc/markup/to_label.rb +84 -0
  167. data/rdoc-8.0.0/lib/rdoc/markup/to_markdown.rb +215 -0
  168. data/rdoc-8.0.0/lib/rdoc/markup/to_rdoc.rb +421 -0
  169. data/rdoc-8.0.0/lib/rdoc/markup/to_table_of_contents.rb +88 -0
  170. data/rdoc-8.0.0/lib/rdoc/markup/to_test.rb +77 -0
  171. data/rdoc-8.0.0/lib/rdoc/markup/to_tt_only.rb +107 -0
  172. data/rdoc-8.0.0/lib/rdoc/markup/verbatim.rb +83 -0
  173. data/rdoc-8.0.0/lib/rdoc/markup.rb +219 -0
  174. data/rdoc-8.0.0/lib/rdoc/options.rb +1412 -0
  175. data/rdoc-8.0.0/lib/rdoc/parser/c.rb +1227 -0
  176. data/rdoc-8.0.0/lib/rdoc/parser/changelog.rb +379 -0
  177. data/rdoc-8.0.0/lib/rdoc/parser/markdown.rb +22 -0
  178. data/rdoc-8.0.0/lib/rdoc/parser/rbs.rb +275 -0
  179. data/rdoc-8.0.0/lib/rdoc/parser/rd.rb +22 -0
  180. data/rdoc-8.0.0/lib/rdoc/parser/ruby.rb +1266 -0
  181. data/rdoc-8.0.0/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  182. data/rdoc-8.0.0/lib/rdoc/parser/simple.rb +44 -0
  183. data/rdoc-8.0.0/lib/rdoc/parser/text.rb +11 -0
  184. data/rdoc-8.0.0/lib/rdoc/parser.rb +298 -0
  185. data/rdoc-8.0.0/lib/rdoc/rbs_helper.rb +186 -0
  186. data/rdoc-8.0.0/lib/rdoc/rd/block_parser.rb +1706 -0
  187. data/rdoc-8.0.0/lib/rdoc/rd/block_parser.ry +643 -0
  188. data/rdoc-8.0.0/lib/rdoc/rd/inline.rb +71 -0
  189. data/rdoc-8.0.0/lib/rdoc/rd/inline_parser.rb +1854 -0
  190. data/rdoc-8.0.0/lib/rdoc/rd/inline_parser.ry +593 -0
  191. data/rdoc-8.0.0/lib/rdoc/rd.rb +99 -0
  192. data/rdoc-8.0.0/lib/rdoc/rdoc.rb +724 -0
  193. data/rdoc-8.0.0/lib/rdoc/ri/driver.rb +1572 -0
  194. data/rdoc-8.0.0/lib/rdoc/ri/formatter.rb +6 -0
  195. data/rdoc-8.0.0/lib/rdoc/ri/paths.rb +171 -0
  196. data/rdoc-8.0.0/lib/rdoc/ri/servlet.rb +452 -0
  197. data/rdoc-8.0.0/lib/rdoc/ri/store.rb +6 -0
  198. data/rdoc-8.0.0/lib/rdoc/ri/task.rb +71 -0
  199. data/rdoc-8.0.0/lib/rdoc/ri.rb +21 -0
  200. data/rdoc-8.0.0/lib/rdoc/rubygems_hook.rb +327 -0
  201. data/rdoc-8.0.0/lib/rdoc/server.rb +460 -0
  202. data/rdoc-8.0.0/lib/rdoc/stats/normal.rb +58 -0
  203. data/rdoc-8.0.0/lib/rdoc/stats/quiet.rb +59 -0
  204. data/rdoc-8.0.0/lib/rdoc/stats/verbose.rb +44 -0
  205. data/rdoc-8.0.0/lib/rdoc/stats.rb +484 -0
  206. data/rdoc-8.0.0/lib/rdoc/store.rb +1205 -0
  207. data/rdoc-8.0.0/lib/rdoc/task.rb +355 -0
  208. data/rdoc-8.0.0/lib/rdoc/text.rb +244 -0
  209. data/rdoc-8.0.0/lib/rdoc/token_stream.rb +104 -0
  210. data/rdoc-8.0.0/lib/rdoc/tom_doc.rb +257 -0
  211. data/rdoc-8.0.0/lib/rdoc/version.rb +10 -0
  212. data/rdoc-8.0.0/lib/rdoc.rb +239 -0
  213. data/rdoc-8.0.0/lib/rubygems_plugin.rb +14 -0
  214. data/rdoc-8.0.0/man/ri.1 +249 -0
  215. data/rdoc-8.0.0/rdoc-logo.svg +43 -0
  216. data/rdoc-8.0.0/rdoc.gemspec +74 -0
  217. data/super-quick-rb.gemspec +12 -0
  218. metadata +257 -0
@@ -0,0 +1,253 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'prism'
4
+ require 'set'
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
59
+
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
72
+
73
+ private
74
+
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
80
+
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
88
+
89
+ # Add missing text such as spaces and newlines as a separate :plain token
90
+ flush = -> next_offset {
91
+ return if offset == next_offset
92
+
93
+ whole_code.byteslice(offset...next_offset).scan(/\n|\s+|[^\s]+/) do |text|
94
+ tokens << ColoredToken.new(:plain, text)
95
+ end
96
+ }
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
105
+ end
106
+ kind, start_pos, end_pos = token
107
+ next if start_pos < offset
108
+
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
116
+
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
127
+ end
128
+ [kind, token.location.start_offset, token.location.end_offset]
129
+ end
130
+ end
131
+ end
132
+
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
137
+
138
+ def initialize
139
+ @tokens = []
140
+ end
141
+
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
150
+
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
156
+
157
+ def visit_regular_expression_node(node)
158
+ push_location(:regexp, node.location)
159
+ end
160
+
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
166
+
167
+ alias visit_match_last_line_node visit_regular_expression_node
168
+ alias visit_interpolated_match_last_line_node visit_interpolated_regular_expression_node
169
+
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
178
+
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
184
+
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
192
+
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
198
+
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
211
+
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
218
+
219
+ private
220
+
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
227
+
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)
247
+ end
248
+ end
249
+ end
250
+ end
251
+
252
+ private_constant :NodeColorizeVisitor
253
+ end
@@ -0,0 +1,44 @@
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, content, options, stats)
18
+ super
19
+
20
+ preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
21
+
22
+ content = RDoc::Text.expand_tabs(@content)
23
+ @content, = preprocess.run_pre_processes(content, @top_level, 1, :simple)
24
+ end
25
+
26
+ ##
27
+ # Extract the file contents and attach them to the TopLevel as a comment
28
+
29
+ def scan
30
+ content = remove_coding_comment @content
31
+
32
+ comment = RDoc::Comment.new content, @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
+ end
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,298 @@
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 mode = check_modeline(file_name)
129
+ when nil, 'rdoc' then # continue
130
+ else
131
+ RDoc::Parser.parsers.find { |_, p| return p if mode.casecmp?(p.name[/\w+\z/]) }
132
+ return nil
133
+ end
134
+ end
135
+
136
+ parser
137
+ rescue Errno::EACCES
138
+ end
139
+
140
+ ##
141
+ # Returns the file type from the modeline in +file_name+
142
+
143
+ def self.check_modeline(file_name)
144
+ line = File.open file_name do |io|
145
+ io.gets
146
+ end
147
+
148
+ /-\*-\s*(.*?\S)\s*-\*-/ =~ line
149
+
150
+ return nil unless type = $1
151
+
152
+ if /;/ =~ type then
153
+ return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type
154
+ type = $1
155
+ end
156
+
157
+ return nil if /coding:/i =~ type
158
+
159
+ type.downcase
160
+ rescue ArgumentError
161
+ rescue Encoding::InvalidByteSequenceError # invalid byte sequence
162
+
163
+ end
164
+
165
+ ##
166
+ # Finds and instantiates the correct parser for the given +file_name+ and
167
+ # +content+.
168
+
169
+ def self.for(top_level, content, options, stats)
170
+ file_name = top_level.absolute_name
171
+ return if binary? file_name
172
+
173
+ parser = use_markup content
174
+
175
+ unless parser then
176
+ parse_name = file_name
177
+
178
+ # If no extension, look for shebang
179
+ if file_name !~ /\.\w+$/ && content =~ %r{\A#!(.+)} then
180
+ shebang = $1
181
+ case shebang
182
+ when %r{env\s+ruby}, %r{/ruby}
183
+ parse_name = 'dummy.rb'
184
+ end
185
+ end
186
+
187
+ parser = can_parse parse_name
188
+ end
189
+
190
+ return unless parser
191
+
192
+ content = remove_modeline content
193
+
194
+ parser.new top_level, content, options, stats
195
+ rescue SystemCallError
196
+ nil
197
+ end
198
+
199
+ ##
200
+ # Record which file types this parser can understand.
201
+ #
202
+ # It is ok to call this multiple times.
203
+
204
+ def self.parse_files_matching(regexp)
205
+ RDoc::Parser.parsers.unshift [regexp, self]
206
+ end
207
+
208
+ ##
209
+ # Removes an emacs-style modeline from the first line of the document
210
+
211
+ def self.remove_modeline(content)
212
+ content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
213
+ end
214
+
215
+ ##
216
+ # If there is a <tt>markup: parser_name</tt> comment at the front of the
217
+ # file, use it to determine the parser. For example:
218
+ #
219
+ # # markup: rdoc
220
+ # # Class comment can go here
221
+ #
222
+ # class C
223
+ # end
224
+ #
225
+ # The comment should appear as the first line of the +content+.
226
+ #
227
+ # If the content contains a shebang or editor modeline the comment may
228
+ # appear on the second or third line.
229
+ #
230
+ # Any comment style may be used to hide the markup comment.
231
+
232
+ def self.use_markup(content)
233
+ markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
234
+
235
+ return unless markup
236
+
237
+ # TODO Ruby should be returned only when the filename is correct
238
+ return RDoc::Parser::Ruby if %w[tomdoc markdown].include? markup
239
+
240
+ markup = Regexp.escape markup
241
+
242
+ _, selected = RDoc::Parser.parsers.find do |_, parser|
243
+ /^#{markup}$/i =~ parser.name.sub(/.*:/, '')
244
+ end
245
+
246
+ selected
247
+ end
248
+
249
+ ##
250
+ # Creates a new Parser storing +top_level+, +file_name+, +content+,
251
+ # +options+ and +stats+ in instance variables. In +@preprocess+ an
252
+ # RDoc::Markup::PreProcess object is created which allows processing of
253
+ # directives.
254
+
255
+ def initialize(top_level, content, options, stats)
256
+ @top_level = top_level
257
+ @top_level.parser = self.class
258
+ @store = @top_level.store
259
+
260
+ @file_name = top_level.absolute_name
261
+ @content = content
262
+ @options = options
263
+ @stats = stats
264
+
265
+ @preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
266
+ @preprocess.options = @options
267
+ end
268
+
269
+ autoload :Text, "#{__dir__}/parser/text"
270
+
271
+ ##
272
+ # Normalizes tabs in +body+
273
+
274
+ def handle_tab_width(body)
275
+ if /\t/ =~ body
276
+ tab_width = @options.tab_width
277
+ body.split(/\n/).map do |line|
278
+ 1 while line.gsub!(/\t+/) do
279
+ b, e = $~.offset(0)
280
+ ' ' * (tab_width * (e-b) - b % tab_width)
281
+ end
282
+ line
283
+ end.join "\n"
284
+ else
285
+ body
286
+ end
287
+ end
288
+ end
289
+
290
+ # simple must come first in order to show up last in the parsers list
291
+ require_relative 'parser/simple'
292
+ require_relative 'parser/c'
293
+ require_relative 'parser/changelog'
294
+ require_relative 'parser/markdown'
295
+ require_relative 'parser/rd'
296
+ require_relative 'parser/rbs'
297
+ require_relative 'parser/ruby'
298
+ require_relative 'parser/ruby_colorizer'