rdoc 5.1.0 → 6.13.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 (179) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.rdoc +5 -6
  3. data/ExampleMarkdown.md +2 -0
  4. data/ExampleRDoc.rdoc +2 -0
  5. data/History.rdoc +68 -66
  6. data/LEGAL.rdoc +1 -1
  7. data/LICENSE.rdoc +2 -0
  8. data/README.rdoc +18 -6
  9. data/RI.md +842 -0
  10. data/TODO.rdoc +8 -7
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -12
  13. data/lib/rdoc/{anon_class.rb → code_object/anon_class.rb} +1 -2
  14. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +83 -26
  15. data/lib/rdoc/{attr.rb → code_object/attr.rb} +5 -9
  16. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +112 -24
  17. data/lib/rdoc/{constant.rb → code_object/constant.rb} +4 -5
  18. data/lib/rdoc/{context → code_object/context}/section.rb +13 -83
  19. data/lib/rdoc/{context.rb → code_object/context.rb} +69 -70
  20. data/lib/rdoc/{extend.rb → code_object/extend.rb} +1 -2
  21. data/lib/rdoc/{ghost_method.rb → code_object/ghost_method.rb} +1 -2
  22. data/lib/rdoc/{include.rb → code_object/include.rb} +1 -2
  23. data/lib/rdoc/{meta_method.rb → code_object/meta_method.rb} +1 -2
  24. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +22 -31
  25. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +1 -2
  26. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +4 -5
  27. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  28. data/lib/rdoc/{require.rb → code_object/require.rb} +2 -3
  29. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +6 -2
  30. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +22 -32
  31. data/lib/rdoc/code_object.rb +8 -41
  32. data/lib/rdoc/code_objects.rb +2 -3
  33. data/lib/rdoc/comment.rb +48 -41
  34. data/lib/rdoc/cross_reference.rb +77 -33
  35. data/lib/rdoc/encoding.rb +50 -38
  36. data/lib/rdoc/erb_partial.rb +2 -3
  37. data/lib/rdoc/erbio.rb +4 -5
  38. data/lib/rdoc/generator/darkfish.rb +178 -125
  39. data/lib/rdoc/generator/json_index.rb +9 -22
  40. data/lib/rdoc/generator/markup.rb +6 -17
  41. data/lib/rdoc/generator/pot/message_extractor.rb +4 -4
  42. data/lib/rdoc/generator/pot/po.rb +3 -3
  43. data/lib/rdoc/generator/pot/po_entry.rb +12 -12
  44. data/lib/rdoc/generator/pot.rb +4 -8
  45. data/lib/rdoc/generator/ri.rb +1 -2
  46. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  47. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -12
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +19 -10
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +26 -6
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +1 -1
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +27 -6
  58. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  59. data/lib/rdoc/generator/template/darkfish/class.rhtml +125 -78
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +430 -339
  61. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/index.rhtml +13 -13
  64. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -92
  65. data/lib/rdoc/generator/template/darkfish/js/search.js +35 -34
  66. data/lib/rdoc/generator/template/darkfish/page.rhtml +5 -5
  67. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +10 -8
  68. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +20 -18
  69. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +32 -20
  70. data/lib/rdoc/generator/template/json_index/js/navigation.js +12 -49
  71. data/lib/rdoc/generator/template/json_index/js/searcher.js +6 -6
  72. data/lib/rdoc/generator.rb +6 -6
  73. data/lib/rdoc/i18n/locale.rb +1 -1
  74. data/lib/rdoc/i18n/text.rb +5 -5
  75. data/lib/rdoc/i18n.rb +4 -4
  76. data/lib/rdoc/known_classes.rb +6 -5
  77. data/lib/rdoc/markdown/entities.rb +1 -2
  78. data/lib/rdoc/markdown/literals.kpeg +1 -2
  79. data/lib/rdoc/markdown/literals.rb +99 -50
  80. data/lib/rdoc/markdown.kpeg +115 -58
  81. data/lib/rdoc/markdown.rb +1584 -902
  82. data/lib/rdoc/markup/attr_changer.rb +1 -2
  83. data/lib/rdoc/markup/attr_span.rb +9 -4
  84. data/lib/rdoc/markup/attribute_manager.rb +118 -57
  85. data/lib/rdoc/markup/attributes.rb +7 -8
  86. data/lib/rdoc/markup/blank_line.rb +1 -2
  87. data/lib/rdoc/markup/block_quote.rb +1 -2
  88. data/lib/rdoc/markup/document.rb +1 -2
  89. data/lib/rdoc/markup/formatter.rb +44 -37
  90. data/lib/rdoc/markup/hard_break.rb +1 -2
  91. data/lib/rdoc/markup/heading.rb +11 -6
  92. data/lib/rdoc/markup/include.rb +1 -2
  93. data/lib/rdoc/markup/indented_paragraph.rb +1 -2
  94. data/lib/rdoc/markup/list.rb +1 -2
  95. data/lib/rdoc/markup/list_item.rb +1 -2
  96. data/lib/rdoc/markup/paragraph.rb +1 -2
  97. data/lib/rdoc/markup/parser.rb +90 -48
  98. data/lib/rdoc/markup/pre_process.rb +38 -11
  99. data/lib/rdoc/markup/raw.rb +1 -2
  100. data/lib/rdoc/markup/regexp_handling.rb +40 -0
  101. data/lib/rdoc/markup/rule.rb +1 -2
  102. data/lib/rdoc/markup/table.rb +56 -0
  103. data/lib/rdoc/markup/to_ansi.rb +1 -2
  104. data/lib/rdoc/markup/to_bs.rb +30 -5
  105. data/lib/rdoc/markup/to_html.rb +95 -40
  106. data/lib/rdoc/markup/to_html_crossref.rb +108 -43
  107. data/lib/rdoc/markup/to_html_snippet.rb +13 -11
  108. data/lib/rdoc/markup/to_joined_paragraph.rb +6 -32
  109. data/lib/rdoc/markup/to_label.rb +11 -12
  110. data/lib/rdoc/markup/to_markdown.rb +13 -14
  111. data/lib/rdoc/markup/to_rdoc.rb +49 -31
  112. data/lib/rdoc/markup/to_table_of_contents.rb +2 -2
  113. data/lib/rdoc/markup/to_test.rb +1 -2
  114. data/lib/rdoc/markup/to_tt_only.rb +3 -4
  115. data/lib/rdoc/markup/verbatim.rb +1 -2
  116. data/lib/rdoc/markup.rb +64 -694
  117. data/lib/rdoc/options.rb +226 -44
  118. data/lib/rdoc/parser/c.rb +231 -246
  119. data/lib/rdoc/parser/changelog.rb +169 -23
  120. data/lib/rdoc/parser/markdown.rb +1 -3
  121. data/lib/rdoc/parser/prism_ruby.rb +1092 -0
  122. data/lib/rdoc/parser/rd.rb +1 -2
  123. data/lib/rdoc/parser/ripper_state_lex.rb +302 -0
  124. data/lib/rdoc/parser/ruby.rb +695 -478
  125. data/lib/rdoc/parser/ruby_tools.rb +33 -36
  126. data/lib/rdoc/parser/simple.rb +4 -4
  127. data/lib/rdoc/parser/text.rb +1 -2
  128. data/lib/rdoc/parser.rb +37 -42
  129. data/lib/rdoc/rd/block_parser.rb +708 -57
  130. data/lib/rdoc/rd/block_parser.ry +15 -11
  131. data/lib/rdoc/rd/inline.rb +5 -6
  132. data/lib/rdoc/rd/inline_parser.rb +787 -140
  133. data/lib/rdoc/rd/inline_parser.ry +1 -1
  134. data/lib/rdoc/rd.rb +4 -5
  135. data/lib/rdoc/rdoc.rb +72 -87
  136. data/lib/rdoc/ri/driver.rb +236 -152
  137. data/lib/rdoc/ri/formatter.rb +1 -1
  138. data/lib/rdoc/ri/paths.rb +4 -18
  139. data/lib/rdoc/ri/store.rb +1 -2
  140. data/lib/rdoc/ri/task.rb +2 -2
  141. data/lib/rdoc/ri.rb +5 -6
  142. data/lib/rdoc/rubygems_hook.rb +98 -20
  143. data/lib/rdoc/servlet.rb +30 -20
  144. data/lib/rdoc/stats/normal.rb +24 -18
  145. data/lib/rdoc/stats/quiet.rb +1 -2
  146. data/lib/rdoc/stats/verbose.rb +1 -3
  147. data/lib/rdoc/stats.rb +6 -7
  148. data/lib/rdoc/store.rb +84 -55
  149. data/lib/rdoc/task.rb +35 -10
  150. data/lib/rdoc/text.rb +40 -27
  151. data/lib/rdoc/token_stream.rb +56 -34
  152. data/lib/rdoc/tom_doc.rb +18 -19
  153. data/lib/rdoc/version.rb +10 -0
  154. data/lib/rdoc.rb +80 -56
  155. data/lib/rubygems_plugin.rb +23 -0
  156. data/man/ri.1 +247 -0
  157. metadata +45 -99
  158. data/.document +0 -5
  159. data/.gitignore +0 -13
  160. data/.travis.yml +0 -24
  161. data/Gemfile +0 -3
  162. data/RI.rdoc +0 -57
  163. data/Rakefile +0 -133
  164. data/bin/console +0 -7
  165. data/bin/setup +0 -6
  166. data/lib/gauntlet_rdoc.rb +0 -82
  167. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  168. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  169. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  170. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  171. data/lib/rdoc/generator/template/json_index/.document +0 -1
  172. data/lib/rdoc/markup/formatter_test_case.rb +0 -764
  173. data/lib/rdoc/markup/inline.rb +0 -2
  174. data/lib/rdoc/markup/special.rb +0 -41
  175. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -115
  176. data/lib/rdoc/ruby_lex.rb +0 -1367
  177. data/lib/rdoc/ruby_token.rb +0 -461
  178. data/lib/rdoc/test_case.rb +0 -204
  179. data/rdoc.gemspec +0 -57
@@ -10,10 +10,8 @@ Navigation = new function() {
10
10
  this.initNavigation = function() {
11
11
  var _this = this;
12
12
 
13
- $(document).keydown(function(e) {
13
+ document.addEventListener('keydown', function(e) {
14
14
  _this.onkeydown(e);
15
- }).keyup(function(e) {
16
- _this.onkeyup(e);
17
15
  });
18
16
 
19
17
  this.navigationActive = true;
@@ -21,68 +19,33 @@ Navigation = new function() {
21
19
 
22
20
  this.setNavigationActive = function(state) {
23
21
  this.navigationActive = state;
24
- this.clearMoveTimeout();
25
- }
26
-
27
- this.onkeyup = function(e) {
28
- if (!this.navigationActive) return;
29
-
30
- switch(e.keyCode) {
31
- case 37: //Event.KEY_LEFT:
32
- case 38: //Event.KEY_UP:
33
- case 39: //Event.KEY_RIGHT:
34
- case 40: //Event.KEY_DOWN:
35
- this.clearMoveTimeout();
36
- break;
37
- }
38
22
  }
39
23
 
40
24
  this.onkeydown = function(e) {
41
25
  if (!this.navigationActive) return;
42
- switch(e.keyCode) {
43
- case 37: //Event.KEY_LEFT:
26
+ switch(e.key) {
27
+ case 'ArrowLeft':
44
28
  if (this.moveLeft()) e.preventDefault();
45
29
  break;
46
- case 38: //Event.KEY_UP:
47
- if (e.keyCode == 38 || e.ctrlKey) {
30
+ case 'ArrowUp':
31
+ if (e.key == 'ArrowUp' || e.ctrlKey) {
48
32
  if (this.moveUp()) e.preventDefault();
49
- this.startMoveTimeout(false);
50
33
  }
51
34
  break;
52
- case 39: //Event.KEY_RIGHT:
35
+ case 'ArrowRight':
53
36
  if (this.moveRight()) e.preventDefault();
54
37
  break;
55
- case 40: //Event.KEY_DOWN:
56
- if (e.keyCode == 40 || e.ctrlKey) {
38
+ case 'ArrowDown':
39
+ if (e.key == 'ArrowDown' || e.ctrlKey) {
57
40
  if (this.moveDown()) e.preventDefault();
58
- this.startMoveTimeout(true);
59
41
  }
60
42
  break;
61
- case 13: //Event.KEY_RETURN:
62
- if (this.$current)
63
- e.preventDefault();
64
- this.select(this.$current);
43
+ case 'Enter':
44
+ if (this.current) e.preventDefault();
45
+ this.select(this.current);
65
46
  break;
66
47
  }
67
- if (e.ctrlKey && e.shiftKey) this.select(this.$current);
68
- }
69
-
70
- this.clearMoveTimeout = function() {
71
- clearTimeout(this.moveTimeout);
72
- this.moveTimeout = null;
73
- }
74
-
75
- this.startMoveTimeout = function(isDown) {
76
- if (!$.browser.mozilla && !$.browser.opera) return;
77
- if (this.moveTimeout) this.clearMoveTimeout();
78
- var _this = this;
79
-
80
- var go = function() {
81
- if (!_this.moveTimeout) return;
82
- _this[isDown ? 'moveDown' : 'moveUp']();
83
- _this.moveTimout = setTimeout(go, 100);
84
- }
85
- this.moveTimeout = setTimeout(go, 200);
48
+ if (e.ctrlKey && e.shiftKey) this.select(this.current);
86
49
  }
87
50
 
88
51
  this.moveRight = function() {
@@ -51,20 +51,20 @@ Searcher.prototype = new function() {
51
51
 
52
52
  /* ----- Utilities ------ */
53
53
  function splitQuery(query) {
54
- return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
54
+ return query.split(/(\s+|::?|\(\)?)/).filter(function(string) {
55
55
  return string.match(/\S/);
56
56
  });
57
57
  }
58
58
 
59
59
  function buildRegexps(queries) {
60
- return jQuery.map(queries, function(query) {
60
+ return queries.map(function(query) {
61
61
  return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
62
62
  });
63
63
  }
64
64
 
65
65
  function buildHilighters(queries) {
66
- return jQuery.map(queries, function(query) {
67
- return jQuery.map(query.split(''), function(l, i) {
66
+ return queries.map(function(query) {
67
+ return query.split('').map(function(l, i) {
68
68
  return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
69
69
  }).join('');
70
70
  });
@@ -221,9 +221,9 @@ Searcher.prototype = new function() {
221
221
  }
222
222
 
223
223
  function triggerResults(results, isLast) {
224
- jQuery.each(this.handlers, function(i, fn) {
224
+ this.handlers.forEach(function(fn) {
225
225
  fn.call(this, results, isLast)
226
- })
226
+ });
227
227
  }
228
228
  }
229
229
 
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # RDoc uses generators to turn parsed source code in the form of an
4
4
  # RDoc::CodeObject tree into some form of output. RDoc comes with the HTML
@@ -41,11 +41,11 @@
41
41
 
42
42
  module RDoc::Generator
43
43
 
44
- autoload :Markup, 'rdoc/generator/markup'
44
+ autoload :Markup, "#{__dir__}/generator/markup"
45
45
 
46
- autoload :Darkfish, 'rdoc/generator/darkfish'
47
- autoload :JsonIndex, 'rdoc/generator/json_index'
48
- autoload :RI, 'rdoc/generator/ri'
49
- autoload :POT, 'rdoc/generator/pot'
46
+ autoload :Darkfish, "#{__dir__}/generator/darkfish"
47
+ autoload :JsonIndex, "#{__dir__}/generator/json_index"
48
+ autoload :RI, "#{__dir__}/generator/ri"
49
+ autoload :POT, "#{__dir__}/generator/pot"
50
50
 
51
51
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # A message container for a locale.
4
4
  #
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # An i18n supported text.
4
4
  #
@@ -46,9 +46,9 @@ class RDoc::I18n::Text
46
46
  parse do |part|
47
47
  case part[:type]
48
48
  when :paragraph
49
- translated_text << locale.translate(part[:paragraph])
49
+ translated_text += locale.translate(part[:paragraph])
50
50
  when :empty_line
51
- translated_text << part[:line]
51
+ translated_text += part[:line]
52
52
  else
53
53
  raise "should not reach here: unexpected type: #{type}"
54
54
  end
@@ -69,14 +69,14 @@ class RDoc::I18n::Text
69
69
  if paragraph.empty?
70
70
  emit_empty_line_event(line, line_no, &block)
71
71
  else
72
- paragraph << line
72
+ paragraph += line
73
73
  emit_paragraph_event(paragraph, paragraph_start_line, line_no,
74
74
  &block)
75
75
  paragraph = ''
76
76
  end
77
77
  else
78
78
  paragraph_start_line = line_no if paragraph.empty?
79
- paragraph << line
79
+ paragraph += line
80
80
  end
81
81
  end
82
82
 
data/lib/rdoc/i18n.rb CHANGED
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
- # This module provides i18n realated features.
3
+ # This module provides i18n related features.
4
4
 
5
5
  module RDoc::I18n
6
6
 
7
- autoload :Locale, 'rdoc/i18n/locale'
8
- autoload :Text, 'rdoc/i18n/text'
7
+ autoload :Locale, "#{__dir__}/i18n/locale"
8
+ require_relative 'i18n/text'
9
9
 
10
10
  end
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  module RDoc
3
3
 
4
4
  ##
@@ -25,6 +25,7 @@ module RDoc
25
25
  "rb_cObject" => "Object",
26
26
  "rb_cProc" => "Proc",
27
27
  "rb_cRange" => "Range",
28
+ "rb_cRefinement" => "Refinement",
28
29
  "rb_cRegexp" => "Regexp",
29
30
  "rb_cRubyVM" => "RubyVM",
30
31
  "rb_cSocket" => "Socket",
@@ -35,7 +36,7 @@ module RDoc
35
36
  "rb_cTime" => "Time",
36
37
  "rb_cTrueClass" => "TrueClass",
37
38
 
38
- "rb_eArgError" => "ArgError",
39
+ "rb_eArgError" => "ArgumentError",
39
40
  "rb_eEOFError" => "EOFError",
40
41
  "rb_eException" => "Exception",
41
42
  "rb_eFatal" => "fatal",
@@ -45,8 +46,8 @@ module RDoc
45
46
  "rb_eInterrupt" => "Interrupt",
46
47
  "rb_eLoadError" => "LoadError",
47
48
  "rb_eNameError" => "NameError",
48
- "rb_eNoMemError" => "NoMemError",
49
- "rb_eNotImpError" => "NotImpError",
49
+ "rb_eNoMemError" => "NoMemoryError",
50
+ "rb_eNotImpError" => "NotImplementedError",
50
51
  "rb_eRangeError" => "RangeError",
51
52
  "rb_eRuntimeError" => "RuntimeError",
52
53
  "rb_eScriptError" => "ScriptError",
@@ -57,7 +58,7 @@ module RDoc
57
58
  "rb_eSystemCallError" => "SystemCallError",
58
59
  "rb_eSystemExit" => "SystemExit",
59
60
  "rb_eTypeError" => "TypeError",
60
- "rb_eZeroDivError" => "ZeroDivError",
61
+ "rb_eZeroDivError" => "ZeroDivisionError",
61
62
 
62
63
  "rb_mComparable" => "Comparable",
63
64
  "rb_mEnumerable" => "Enumerable",
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  ##
3
3
  # HTML entity name map for RDoc::Markdown
4
4
 
@@ -2129,4 +2129,3 @@ RDoc::Markdown::HTML_ENTITIES = {
2129
2129
  "zwj" => [0x0200D],
2130
2130
  "zwnj" => [0x0200C],
2131
2131
  }
2132
-
@@ -2,10 +2,10 @@
2
2
 
3
3
  %% header {
4
4
  # coding: UTF-8
5
+ # frozen_string_literal: true
5
6
  # :markup: markdown
6
7
 
7
8
  ##
8
- #--
9
9
  # This set of literals is for Ruby 1.9 regular expressions and gives full
10
10
  # unicode support.
11
11
  #
@@ -19,4 +19,3 @@ BOM = "\uFEFF"
19
19
  Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
20
20
  NonAlphanumeric = /\p{^Word}/
21
21
  Spacechar = /\t|\p{Zs}/
22
-
@@ -1,9 +1,8 @@
1
1
  # coding: UTF-8
2
- # frozen_string_literal: false
2
+ # frozen_string_literal: true
3
3
  # :markup: markdown
4
4
 
5
5
  ##
6
- #--
7
6
  # This set of literals is for Ruby 1.9 regular expressions and gives full
8
7
  # unicode support.
9
8
  #
@@ -29,6 +28,7 @@ class RDoc::Markdown::Literals
29
28
  @result = nil
30
29
  @failed_rule = nil
31
30
  @failing_rule_offset = -1
31
+ @line_offsets = nil
32
32
 
33
33
  setup_foreign_grammar
34
34
  end
@@ -38,30 +38,75 @@ class RDoc::Markdown::Literals
38
38
  attr_accessor :result, :pos
39
39
 
40
40
  def current_column(target=pos)
41
- if c = string.rindex("\n", target-1)
42
- return target - c - 1
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
43
45
  end
44
46
 
45
47
  target + 1
46
48
  end
47
49
 
48
- def current_line(target=pos)
49
- cur_offset = 0
50
- cur_line = 0
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
51
78
 
52
- string.each_line do |line|
53
- cur_line += 1
54
- cur_offset += line.size
55
- return cur_line if cur_offset >= target
79
+ def current_character(target=pos)
80
+ if target < 0 || target >= string.size
81
+ raise "Target position #{target} is outside of string"
56
82
  end
83
+ string[target, 1]
84
+ end
85
+
86
+ KpegPosInfo = Struct.new(:pos, :lno, :col, :line, :char)
57
87
 
58
- -1
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)
59
94
  end
60
95
 
61
96
  def lines
62
- lines = []
63
- string.each_line { |l| lines << l }
64
- 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]
65
110
  end
66
111
 
67
112
 
@@ -75,6 +120,7 @@ class RDoc::Markdown::Literals
75
120
  @string = string
76
121
  @string_size = string ? string.size : 0
77
122
  @pos = pos
123
+ @position_line_offsets = nil
78
124
  end
79
125
 
80
126
  def show_pos
@@ -99,30 +145,22 @@ class RDoc::Markdown::Literals
99
145
  end
100
146
 
101
147
  def failure_caret
102
- l = current_line @failing_rule_offset
103
- c = current_column @failing_rule_offset
104
-
105
- line = lines[l-1]
106
- "#{line}\n#{' ' * (c - 1)}^"
148
+ p = current_pos_info @failing_rule_offset
149
+ "#{p.line.chomp}\n#{' ' * (p.col - 1)}^"
107
150
  end
108
151
 
109
152
  def failure_character
110
- l = current_line @failing_rule_offset
111
- c = current_column @failing_rule_offset
112
- lines[l-1][c-1, 1]
153
+ current_character @failing_rule_offset
113
154
  end
114
155
 
115
156
  def failure_oneline
116
- l = current_line @failing_rule_offset
117
- c = current_column @failing_rule_offset
118
-
119
- char = lines[l-1][c-1, 1]
157
+ p = current_pos_info @failing_rule_offset
120
158
 
121
159
  if @failed_rule.kind_of? Symbol
122
160
  info = self.class::Rules[@failed_rule]
123
- "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
161
+ "@#{p.lno}:#{p.col} failed rule '#{info.name}', got '#{p.char}'"
124
162
  else
125
- "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
163
+ "@#{p.lno}:#{p.col} failed rule '#{@failed_rule}', got '#{p.char}'"
126
164
  end
127
165
  end
128
166
 
@@ -135,10 +173,9 @@ class RDoc::Markdown::Literals
135
173
 
136
174
  def show_error(io=STDOUT)
137
175
  error_pos = @failing_rule_offset
138
- line_no = current_line(error_pos)
139
- col_no = current_column(error_pos)
176
+ p = current_pos_info(error_pos)
140
177
 
141
- io.puts "On line #{line_no}, column #{col_no}:"
178
+ io.puts "On line #{p.lno}, column #{p.col}:"
142
179
 
143
180
  if @failed_rule.kind_of? Symbol
144
181
  info = self.class::Rules[@failed_rule]
@@ -147,10 +184,9 @@ class RDoc::Markdown::Literals
147
184
  io.puts "Failed to match rule '#{@failed_rule}'"
148
185
  end
149
186
 
150
- io.puts "Got: #{string[error_pos,1].inspect}"
151
- line = lines[line_no-1]
152
- io.puts "=> #{line}"
153
- io.print(" " * (col_no + 3))
187
+ io.puts "Got: #{p.char.inspect}"
188
+ io.puts "=> #{p.line}"
189
+ io.print(" " * (p.col + 2))
154
190
  io.puts "^"
155
191
  end
156
192
 
@@ -174,23 +210,34 @@ class RDoc::Markdown::Literals
174
210
  end
175
211
 
176
212
  def scan(reg)
177
- if m = reg.match(@string[@pos..-1])
178
- width = m.end(0)
179
- @pos += width
213
+ if m = reg.match(@string, @pos)
214
+ @pos = m.end(0)
180
215
  return true
181
216
  end
182
217
 
183
218
  return nil
184
219
  end
185
220
 
186
- def get_byte
187
- if @pos >= @string_size
188
- return nil
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
189
230
  end
231
+ else
232
+ def get_byte
233
+ if @pos >= @string_size
234
+ return nil
235
+ end
190
236
 
191
- s = @string[@pos].ord
192
- @pos += 1
193
- s
237
+ s = @string[@pos]
238
+ @pos += 1
239
+ s
240
+ end
194
241
  end
195
242
 
196
243
  def parse(rule=nil)
@@ -248,6 +295,7 @@ class RDoc::Markdown::Literals
248
295
  end
249
296
 
250
297
  def apply_with_args(rule, *args)
298
+ @result = nil
251
299
  memo_key = [rule, args]
252
300
  if m = @memoizations[memo_key][@pos]
253
301
  @pos = m.pos
@@ -281,6 +329,7 @@ class RDoc::Markdown::Literals
281
329
  end
282
330
 
283
331
  def apply(rule)
332
+ @result = nil
284
333
  if m = @memoizations[rule][@pos]
285
334
  @pos = m.pos
286
335
  if !m.set
@@ -354,14 +403,14 @@ class RDoc::Markdown::Literals
354
403
 
355
404
  # Alphanumeric = /\p{Word}/
356
405
  def _Alphanumeric
357
- _tmp = scan(/\A(?-mix:\p{Word})/)
406
+ _tmp = scan(/\G(?-mix:\p{Word})/)
358
407
  set_failed_rule :_Alphanumeric unless _tmp
359
408
  return _tmp
360
409
  end
361
410
 
362
411
  # AlphanumericAscii = /[A-Za-z0-9]/
363
412
  def _AlphanumericAscii
364
- _tmp = scan(/\A(?-mix:[A-Za-z0-9])/)
413
+ _tmp = scan(/\G(?-mix:[A-Za-z0-9])/)
365
414
  set_failed_rule :_AlphanumericAscii unless _tmp
366
415
  return _tmp
367
416
  end
@@ -375,21 +424,21 @@ class RDoc::Markdown::Literals
375
424
 
376
425
  # Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
377
426
  def _Newline
378
- _tmp = scan(/\A(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
427
+ _tmp = scan(/\G(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
379
428
  set_failed_rule :_Newline unless _tmp
380
429
  return _tmp
381
430
  end
382
431
 
383
432
  # NonAlphanumeric = /\p{^Word}/
384
433
  def _NonAlphanumeric
385
- _tmp = scan(/\A(?-mix:\p{^Word})/)
434
+ _tmp = scan(/\G(?-mix:\p{^Word})/)
386
435
  set_failed_rule :_NonAlphanumeric unless _tmp
387
436
  return _tmp
388
437
  end
389
438
 
390
439
  # Spacechar = /\t|\p{Zs}/
391
440
  def _Spacechar
392
- _tmp = scan(/\A(?-mix:\t|\p{Zs})/)
441
+ _tmp = scan(/\G(?-mix:\t|\p{Zs})/)
393
442
  set_failed_rule :_Spacechar unless _tmp
394
443
  return _tmp
395
444
  end