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.
- checksums.yaml +7 -0
- data/rdoc-8.0.0/CONTRIBUTING.md +195 -0
- data/rdoc-8.0.0/CVE-2013-0256.rdoc +49 -0
- data/rdoc-8.0.0/History.rdoc +1668 -0
- data/rdoc-8.0.0/LEGAL.rdoc +56 -0
- data/rdoc-8.0.0/LICENSE.rdoc +63 -0
- data/rdoc-8.0.0/README.md +236 -0
- data/rdoc-8.0.0/RI.md +842 -0
- data/rdoc-8.0.0/TODO.rdoc +60 -0
- data/rdoc-8.0.0/doc/markup_reference/markdown.md +659 -0
- data/rdoc-8.0.0/doc/markup_reference/rdoc.rdoc +1169 -0
- data/rdoc-8.0.0/exe/rdoc +43 -0
- data/rdoc-8.0.0/exe/ri +12 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/alias.rb +98 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/any_method.rb +387 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/attr.rb +178 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/class_module.rb +969 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/constant.rb +221 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/context/section.rb +182 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/context.rb +1238 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/extend.rb +9 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/include.rb +9 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/method_attr.rb +417 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/mixin.rb +123 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/normal_class.rb +92 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/normal_module.rb +73 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/require.rb +51 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/single_class.rb +30 -0
- data/rdoc-8.0.0/lib/rdoc/code_object/top_level.rb +286 -0
- data/rdoc-8.0.0/lib/rdoc/code_object.rb +393 -0
- data/rdoc-8.0.0/lib/rdoc/code_objects.rb +5 -0
- data/rdoc-8.0.0/lib/rdoc/comment.rb +353 -0
- data/rdoc-8.0.0/lib/rdoc/cross_reference.rb +215 -0
- data/rdoc-8.0.0/lib/rdoc/encoding.rb +120 -0
- data/rdoc-8.0.0/lib/rdoc/erb_partial.rb +18 -0
- data/rdoc-8.0.0/lib/rdoc/erbio.rb +37 -0
- data/rdoc-8.0.0/lib/rdoc/generator/aliki.rb +200 -0
- data/rdoc-8.0.0/lib/rdoc/generator/darkfish.rb +824 -0
- data/rdoc-8.0.0/lib/rdoc/generator/json_index.rb +284 -0
- data/rdoc-8.0.0/lib/rdoc/generator/markup.rb +196 -0
- data/rdoc-8.0.0/lib/rdoc/generator/pot/message_extractor.rb +68 -0
- data/rdoc-8.0.0/lib/rdoc/generator/pot/po.rb +84 -0
- data/rdoc-8.0.0/lib/rdoc/generator/pot/po_entry.rb +141 -0
- data/rdoc-8.0.0/lib/rdoc/generator/pot.rb +94 -0
- data/rdoc-8.0.0/lib/rdoc/generator/ri.rb +30 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_head.rhtml +43 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +5 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +17 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +17 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +16 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +21 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +32 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +6 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +15 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +39 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/class.rhtml +220 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/css/rdoc.css +701 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/index.rhtml +24 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/js/darkfish.js +140 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/js/search.js +120 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/page.rhtml +19 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +21 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +65 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +72 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
- data/rdoc-8.0.0/lib/rdoc/generator/template/json_index/js/searcher.js +271 -0
- data/rdoc-8.0.0/lib/rdoc/generator.rb +52 -0
- data/rdoc-8.0.0/lib/rdoc/i18n/locale.rb +102 -0
- data/rdoc-8.0.0/lib/rdoc/i18n/text.rb +126 -0
- data/rdoc-8.0.0/lib/rdoc/i18n.rb +10 -0
- data/rdoc-8.0.0/lib/rdoc/known_classes.rb +74 -0
- data/rdoc-8.0.0/lib/rdoc/markdown/entities.rb +2131 -0
- data/rdoc-8.0.0/lib/rdoc/markdown/literals.kpeg +21 -0
- data/rdoc-8.0.0/lib/rdoc/markdown/literals.rb +454 -0
- data/rdoc-8.0.0/lib/rdoc/markdown.kpeg +1315 -0
- data/rdoc-8.0.0/lib/rdoc/markdown.rb +16865 -0
- data/rdoc-8.0.0/lib/rdoc/markup/blank_line.rb +29 -0
- data/rdoc-8.0.0/lib/rdoc/markup/block_quote.rb +14 -0
- data/rdoc-8.0.0/lib/rdoc/markup/document.rb +164 -0
- data/rdoc-8.0.0/lib/rdoc/markup/element.rb +21 -0
- data/rdoc-8.0.0/lib/rdoc/markup/formatter.rb +285 -0
- data/rdoc-8.0.0/lib/rdoc/markup/hard_break.rb +34 -0
- data/rdoc-8.0.0/lib/rdoc/markup/heading.rb +170 -0
- data/rdoc-8.0.0/lib/rdoc/markup/include.rb +42 -0
- data/rdoc-8.0.0/lib/rdoc/markup/indented_paragraph.rb +47 -0
- data/rdoc-8.0.0/lib/rdoc/markup/inline_parser.rb +312 -0
- data/rdoc-8.0.0/lib/rdoc/markup/list.rb +101 -0
- data/rdoc-8.0.0/lib/rdoc/markup/list_item.rb +99 -0
- data/rdoc-8.0.0/lib/rdoc/markup/paragraph.rb +28 -0
- data/rdoc-8.0.0/lib/rdoc/markup/parser.rb +585 -0
- data/rdoc-8.0.0/lib/rdoc/markup/pre_process.rb +317 -0
- data/rdoc-8.0.0/lib/rdoc/markup/raw.rb +66 -0
- data/rdoc-8.0.0/lib/rdoc/markup/rule.rb +20 -0
- data/rdoc-8.0.0/lib/rdoc/markup/table.rb +64 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_ansi.rb +144 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_bs.rb +86 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_html.rb +682 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_html_crossref.rb +261 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_html_snippet.rb +287 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_joined_paragraph.rb +41 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_label.rb +84 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_markdown.rb +215 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_rdoc.rb +421 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_table_of_contents.rb +88 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_test.rb +77 -0
- data/rdoc-8.0.0/lib/rdoc/markup/to_tt_only.rb +107 -0
- data/rdoc-8.0.0/lib/rdoc/markup/verbatim.rb +83 -0
- data/rdoc-8.0.0/lib/rdoc/markup.rb +219 -0
- data/rdoc-8.0.0/lib/rdoc/options.rb +1412 -0
- data/rdoc-8.0.0/lib/rdoc/parser/c.rb +1227 -0
- data/rdoc-8.0.0/lib/rdoc/parser/changelog.rb +379 -0
- data/rdoc-8.0.0/lib/rdoc/parser/markdown.rb +22 -0
- data/rdoc-8.0.0/lib/rdoc/parser/rbs.rb +275 -0
- data/rdoc-8.0.0/lib/rdoc/parser/rd.rb +22 -0
- data/rdoc-8.0.0/lib/rdoc/parser/ruby.rb +1266 -0
- data/rdoc-8.0.0/lib/rdoc/parser/ruby_colorizer.rb +253 -0
- data/rdoc-8.0.0/lib/rdoc/parser/simple.rb +44 -0
- data/rdoc-8.0.0/lib/rdoc/parser/text.rb +11 -0
- data/rdoc-8.0.0/lib/rdoc/parser.rb +298 -0
- data/rdoc-8.0.0/lib/rdoc/rbs_helper.rb +186 -0
- data/rdoc-8.0.0/lib/rdoc/rd/block_parser.rb +1706 -0
- data/rdoc-8.0.0/lib/rdoc/rd/block_parser.ry +643 -0
- data/rdoc-8.0.0/lib/rdoc/rd/inline.rb +71 -0
- data/rdoc-8.0.0/lib/rdoc/rd/inline_parser.rb +1854 -0
- data/rdoc-8.0.0/lib/rdoc/rd/inline_parser.ry +593 -0
- data/rdoc-8.0.0/lib/rdoc/rd.rb +99 -0
- data/rdoc-8.0.0/lib/rdoc/rdoc.rb +724 -0
- data/rdoc-8.0.0/lib/rdoc/ri/driver.rb +1572 -0
- data/rdoc-8.0.0/lib/rdoc/ri/formatter.rb +6 -0
- data/rdoc-8.0.0/lib/rdoc/ri/paths.rb +171 -0
- data/rdoc-8.0.0/lib/rdoc/ri/servlet.rb +452 -0
- data/rdoc-8.0.0/lib/rdoc/ri/store.rb +6 -0
- data/rdoc-8.0.0/lib/rdoc/ri/task.rb +71 -0
- data/rdoc-8.0.0/lib/rdoc/ri.rb +21 -0
- data/rdoc-8.0.0/lib/rdoc/rubygems_hook.rb +327 -0
- data/rdoc-8.0.0/lib/rdoc/server.rb +460 -0
- data/rdoc-8.0.0/lib/rdoc/stats/normal.rb +58 -0
- data/rdoc-8.0.0/lib/rdoc/stats/quiet.rb +59 -0
- data/rdoc-8.0.0/lib/rdoc/stats/verbose.rb +44 -0
- data/rdoc-8.0.0/lib/rdoc/stats.rb +484 -0
- data/rdoc-8.0.0/lib/rdoc/store.rb +1205 -0
- data/rdoc-8.0.0/lib/rdoc/task.rb +355 -0
- data/rdoc-8.0.0/lib/rdoc/text.rb +244 -0
- data/rdoc-8.0.0/lib/rdoc/token_stream.rb +104 -0
- data/rdoc-8.0.0/lib/rdoc/tom_doc.rb +257 -0
- data/rdoc-8.0.0/lib/rdoc/version.rb +10 -0
- data/rdoc-8.0.0/lib/rdoc.rb +239 -0
- data/rdoc-8.0.0/lib/rubygems_plugin.rb +14 -0
- data/rdoc-8.0.0/man/ri.1 +249 -0
- data/rdoc-8.0.0/rdoc-logo.svg +43 -0
- data/rdoc-8.0.0/rdoc.gemspec +74 -0
- data/super-quick-rb.gemspec +12 -0
- 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'
|