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,21 @@
1
+ %% name = RDoc::Markdown::Literals
2
+
3
+ %% header {
4
+ # coding: UTF-8
5
+ # frozen_string_literal: true
6
+ # :markup: markdown
7
+
8
+ ##
9
+ # This set of literals is for Ruby 1.9 regular expressions and gives full
10
+ # unicode support.
11
+ #
12
+ # Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
13
+ # characters, newlines and spaces.
14
+ }
15
+
16
+ Alphanumeric = /\p{Word}/
17
+ AlphanumericAscii = /[A-Za-z0-9]/
18
+ BOM = "\uFEFF"
19
+ Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
20
+ NonAlphanumeric = /\p{^Word}/
21
+ Spacechar = /\t|\p{Zs}/
@@ -0,0 +1,454 @@
1
+ # coding: UTF-8
2
+ # frozen_string_literal: true
3
+ # :markup: markdown
4
+
5
+ ##
6
+ # This set of literals is for Ruby 1.9 regular expressions and gives full
7
+ # unicode support.
8
+ #
9
+ # Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
10
+ # characters, newlines and spaces.
11
+ class RDoc::Markdown::Literals
12
+ # :stopdoc:
13
+
14
+ # This is distinct from setup_parser so that a standalone parser
15
+ # can redefine #initialize and still have access to the proper
16
+ # parser setup code.
17
+ def initialize(str, debug=false)
18
+ setup_parser(str, debug)
19
+ end
20
+
21
+
22
+
23
+ # Prepares for parsing +str+. If you define a custom initialize you must
24
+ # call this method before #parse
25
+ def setup_parser(str, debug=false)
26
+ set_string str, 0
27
+ @memoizations = Hash.new { |h,k| h[k] = {} }
28
+ @result = nil
29
+ @failed_rule = nil
30
+ @failing_rule_offset = -1
31
+ @line_offsets = nil
32
+
33
+ setup_foreign_grammar
34
+ end
35
+
36
+ attr_reader :string
37
+ attr_reader :failing_rule_offset
38
+ attr_accessor :result, :pos
39
+
40
+ def current_column(target=pos)
41
+ if string[target] == "\n" && (c = string.rindex("\n", target-1) || -1)
42
+ return target - c
43
+ elsif c = string.rindex("\n", target)
44
+ return target - c
45
+ end
46
+
47
+ target + 1
48
+ end
49
+
50
+ def position_line_offsets
51
+ unless @position_line_offsets
52
+ @position_line_offsets = []
53
+ total = 0
54
+ string.each_line do |line|
55
+ total += line.size
56
+ @position_line_offsets << total
57
+ end
58
+ end
59
+ @position_line_offsets
60
+ end
61
+
62
+ if [].respond_to? :bsearch_index
63
+ def current_line(target=pos)
64
+ if line = position_line_offsets.bsearch_index {|x| x > target }
65
+ return line + 1
66
+ end
67
+ raise "Target position #{target} is outside of string"
68
+ end
69
+ else
70
+ def current_line(target=pos)
71
+ if line = position_line_offsets.index {|x| x > target }
72
+ return line + 1
73
+ end
74
+
75
+ raise "Target position #{target} is outside of string"
76
+ end
77
+ end
78
+
79
+ def current_character(target=pos)
80
+ if target < 0 || target >= string.size
81
+ raise "Target position #{target} is outside of string"
82
+ end
83
+ string[target, 1]
84
+ end
85
+
86
+ KpegPosInfo = Struct.new(:pos, :lno, :col, :line, :char)
87
+
88
+ def current_pos_info(target=pos)
89
+ l = current_line target
90
+ c = current_column target
91
+ ln = get_line(l-1)
92
+ chr = string[target,1]
93
+ KpegPosInfo.new(target, l, c, ln, chr)
94
+ end
95
+
96
+ def lines
97
+ string.lines
98
+ end
99
+
100
+ def get_line(no)
101
+ loff = position_line_offsets
102
+ if no < 0
103
+ raise "Line No is out of range: #{no} < 0"
104
+ elsif no >= loff.size
105
+ raise "Line No is out of range: #{no} >= #{loff.size}"
106
+ end
107
+ lend = loff[no]-1
108
+ lstart = no > 0 ? loff[no-1] : 0
109
+ string[lstart..lend]
110
+ end
111
+
112
+
113
+
114
+ def get_text(start)
115
+ @string[start..@pos-1]
116
+ end
117
+
118
+ # Sets the string and current parsing position for the parser.
119
+ def set_string string, pos
120
+ @string = string
121
+ @string_size = string ? string.size : 0
122
+ @pos = pos
123
+ @position_line_offsets = nil
124
+ end
125
+
126
+ def show_pos
127
+ width = 10
128
+ if @pos < width
129
+ "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
130
+ else
131
+ "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
132
+ end
133
+ end
134
+
135
+ def failure_info
136
+ l = current_line @failing_rule_offset
137
+ c = current_column @failing_rule_offset
138
+
139
+ if @failed_rule.kind_of? Symbol
140
+ info = self.class::Rules[@failed_rule]
141
+ "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
142
+ else
143
+ "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
144
+ end
145
+ end
146
+
147
+ def failure_caret
148
+ p = current_pos_info @failing_rule_offset
149
+ "#{p.line.chomp}\n#{' ' * (p.col - 1)}^"
150
+ end
151
+
152
+ def failure_character
153
+ current_character @failing_rule_offset
154
+ end
155
+
156
+ def failure_oneline
157
+ p = current_pos_info @failing_rule_offset
158
+
159
+ if @failed_rule.kind_of? Symbol
160
+ info = self.class::Rules[@failed_rule]
161
+ "@#{p.lno}:#{p.col} failed rule '#{info.name}', got '#{p.char}'"
162
+ else
163
+ "@#{p.lno}:#{p.col} failed rule '#{@failed_rule}', got '#{p.char}'"
164
+ end
165
+ end
166
+
167
+ class ParseError < RuntimeError
168
+ end
169
+
170
+ def raise_error
171
+ raise ParseError, failure_oneline
172
+ end
173
+
174
+ def show_error(io=STDOUT)
175
+ error_pos = @failing_rule_offset
176
+ p = current_pos_info(error_pos)
177
+
178
+ io.puts "On line #{p.lno}, column #{p.col}:"
179
+
180
+ if @failed_rule.kind_of? Symbol
181
+ info = self.class::Rules[@failed_rule]
182
+ io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
183
+ else
184
+ io.puts "Failed to match rule '#{@failed_rule}'"
185
+ end
186
+
187
+ io.puts "Got: #{p.char.inspect}"
188
+ io.puts "=> #{p.line}"
189
+ io.print(" " * (p.col + 2))
190
+ io.puts "^"
191
+ end
192
+
193
+ def set_failed_rule(name)
194
+ if @pos > @failing_rule_offset
195
+ @failed_rule = name
196
+ @failing_rule_offset = @pos
197
+ end
198
+ end
199
+
200
+ attr_reader :failed_rule
201
+
202
+ def match_string(str)
203
+ len = str.size
204
+ if @string[pos,len] == str
205
+ @pos += len
206
+ return str
207
+ end
208
+
209
+ return nil
210
+ end
211
+
212
+ def scan(reg)
213
+ if m = reg.match(@string, @pos)
214
+ @pos = m.end(0)
215
+ return true
216
+ end
217
+
218
+ return nil
219
+ end
220
+
221
+ if "".respond_to? :ord
222
+ def get_byte
223
+ if @pos >= @string_size
224
+ return nil
225
+ end
226
+
227
+ s = @string[@pos].ord
228
+ @pos += 1
229
+ s
230
+ end
231
+ else
232
+ def get_byte
233
+ if @pos >= @string_size
234
+ return nil
235
+ end
236
+
237
+ s = @string[@pos]
238
+ @pos += 1
239
+ s
240
+ end
241
+ end
242
+
243
+ def parse(rule=nil)
244
+ # We invoke the rules indirectly via apply
245
+ # instead of by just calling them as methods because
246
+ # if the rules use left recursion, apply needs to
247
+ # manage that.
248
+
249
+ if !rule
250
+ apply(:_root)
251
+ else
252
+ method = rule.gsub("-","_hyphen_")
253
+ apply :"_#{method}"
254
+ end
255
+ end
256
+
257
+ class MemoEntry
258
+ def initialize(ans, pos)
259
+ @ans = ans
260
+ @pos = pos
261
+ @result = nil
262
+ @set = false
263
+ @left_rec = false
264
+ end
265
+
266
+ attr_reader :ans, :pos, :result, :set
267
+ attr_accessor :left_rec
268
+
269
+ def move!(ans, pos, result)
270
+ @ans = ans
271
+ @pos = pos
272
+ @result = result
273
+ @set = true
274
+ @left_rec = false
275
+ end
276
+ end
277
+
278
+ def external_invoke(other, rule, *args)
279
+ old_pos = @pos
280
+ old_string = @string
281
+
282
+ set_string other.string, other.pos
283
+
284
+ begin
285
+ if val = __send__(rule, *args)
286
+ other.pos = @pos
287
+ other.result = @result
288
+ else
289
+ other.set_failed_rule "#{self.class}##{rule}"
290
+ end
291
+ val
292
+ ensure
293
+ set_string old_string, old_pos
294
+ end
295
+ end
296
+
297
+ def apply_with_args(rule, *args)
298
+ @result = nil
299
+ memo_key = [rule, args]
300
+ if m = @memoizations[memo_key][@pos]
301
+ @pos = m.pos
302
+ if !m.set
303
+ m.left_rec = true
304
+ return nil
305
+ end
306
+
307
+ @result = m.result
308
+
309
+ return m.ans
310
+ else
311
+ m = MemoEntry.new(nil, @pos)
312
+ @memoizations[memo_key][@pos] = m
313
+ start_pos = @pos
314
+
315
+ ans = __send__ rule, *args
316
+
317
+ lr = m.left_rec
318
+
319
+ m.move! ans, @pos, @result
320
+
321
+ # Don't bother trying to grow the left recursion
322
+ # if it's failing straight away (thus there is no seed)
323
+ if ans and lr
324
+ return grow_lr(rule, args, start_pos, m)
325
+ else
326
+ return ans
327
+ end
328
+ end
329
+ end
330
+
331
+ def apply(rule)
332
+ @result = nil
333
+ if m = @memoizations[rule][@pos]
334
+ @pos = m.pos
335
+ if !m.set
336
+ m.left_rec = true
337
+ return nil
338
+ end
339
+
340
+ @result = m.result
341
+
342
+ return m.ans
343
+ else
344
+ m = MemoEntry.new(nil, @pos)
345
+ @memoizations[rule][@pos] = m
346
+ start_pos = @pos
347
+
348
+ ans = __send__ rule
349
+
350
+ lr = m.left_rec
351
+
352
+ m.move! ans, @pos, @result
353
+
354
+ # Don't bother trying to grow the left recursion
355
+ # if it's failing straight away (thus there is no seed)
356
+ if ans and lr
357
+ return grow_lr(rule, nil, start_pos, m)
358
+ else
359
+ return ans
360
+ end
361
+ end
362
+ end
363
+
364
+ def grow_lr(rule, args, start_pos, m)
365
+ while true
366
+ @pos = start_pos
367
+ @result = m.result
368
+
369
+ if args
370
+ ans = __send__ rule, *args
371
+ else
372
+ ans = __send__ rule
373
+ end
374
+ return nil unless ans
375
+
376
+ break if @pos <= m.pos
377
+
378
+ m.move! ans, @pos, @result
379
+ end
380
+
381
+ @result = m.result
382
+ @pos = m.pos
383
+ return m.ans
384
+ end
385
+
386
+ class RuleInfo
387
+ def initialize(name, rendered)
388
+ @name = name
389
+ @rendered = rendered
390
+ end
391
+
392
+ attr_reader :name, :rendered
393
+ end
394
+
395
+ def self.rule_info(name, rendered)
396
+ RuleInfo.new(name, rendered)
397
+ end
398
+
399
+
400
+ # :startdoc:
401
+ # :stopdoc:
402
+ def setup_foreign_grammar; end
403
+
404
+ # Alphanumeric = /\p{Word}/
405
+ def _Alphanumeric
406
+ _tmp = scan(/\G(?-mix:\p{Word})/)
407
+ set_failed_rule :_Alphanumeric unless _tmp
408
+ return _tmp
409
+ end
410
+
411
+ # AlphanumericAscii = /[A-Za-z0-9]/
412
+ def _AlphanumericAscii
413
+ _tmp = scan(/\G(?-mix:[A-Za-z0-9])/)
414
+ set_failed_rule :_AlphanumericAscii unless _tmp
415
+ return _tmp
416
+ end
417
+
418
+ # BOM = "uFEFF"
419
+ def _BOM
420
+ _tmp = match_string("uFEFF")
421
+ set_failed_rule :_BOM unless _tmp
422
+ return _tmp
423
+ end
424
+
425
+ # Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
426
+ def _Newline
427
+ _tmp = scan(/\G(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
428
+ set_failed_rule :_Newline unless _tmp
429
+ return _tmp
430
+ end
431
+
432
+ # NonAlphanumeric = /\p{^Word}/
433
+ def _NonAlphanumeric
434
+ _tmp = scan(/\G(?-mix:\p{^Word})/)
435
+ set_failed_rule :_NonAlphanumeric unless _tmp
436
+ return _tmp
437
+ end
438
+
439
+ # Spacechar = /\t|\p{Zs}/
440
+ def _Spacechar
441
+ _tmp = scan(/\G(?-mix:\t|\p{Zs})/)
442
+ set_failed_rule :_Spacechar unless _tmp
443
+ return _tmp
444
+ end
445
+
446
+ Rules = {}
447
+ Rules[:_Alphanumeric] = rule_info("Alphanumeric", "/\\p{Word}/")
448
+ Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "/[A-Za-z0-9]/")
449
+ Rules[:_BOM] = rule_info("BOM", "\"uFEFF\"")
450
+ Rules[:_Newline] = rule_info("Newline", "/\\n|\\r\\n?|\\p{Zl}|\\p{Zp}/")
451
+ Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "/\\p{^Word}/")
452
+ Rules[:_Spacechar] = rule_info("Spacechar", "/\\t|\\p{Zs}/")
453
+ # :startdoc:
454
+ end