rdoc 7.2.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -7
  3. data/LICENSE.rdoc +4 -0
  4. data/README.md +43 -2
  5. data/RI.md +75 -75
  6. data/doc/markup_reference/markdown.md +104 -3
  7. data/exe/rdoc +2 -2
  8. data/lib/rdoc/code_object/alias.rb +70 -74
  9. data/lib/rdoc/code_object/any_method.rb +305 -298
  10. data/lib/rdoc/code_object/attr.rb +150 -143
  11. data/lib/rdoc/code_object/class_module.rb +801 -765
  12. data/lib/rdoc/code_object/constant.rb +178 -150
  13. data/lib/rdoc/code_object/context/section.rb +133 -160
  14. data/lib/rdoc/code_object/context.rb +925 -952
  15. data/lib/rdoc/code_object/extend.rb +7 -5
  16. data/lib/rdoc/code_object/include.rb +7 -5
  17. data/lib/rdoc/code_object/method_attr.rb +325 -324
  18. data/lib/rdoc/code_object/mixin.rb +97 -95
  19. data/lib/rdoc/code_object/normal_class.rb +77 -78
  20. data/lib/rdoc/code_object/normal_module.rb +61 -59
  21. data/lib/rdoc/code_object/require.rb +23 -39
  22. data/lib/rdoc/code_object/single_class.rb +21 -19
  23. data/lib/rdoc/code_object/top_level.rb +212 -213
  24. data/lib/rdoc/code_object.rb +305 -305
  25. data/lib/rdoc/comment.rb +274 -337
  26. data/lib/rdoc/cross_reference.rb +194 -212
  27. data/lib/rdoc/encoding.rb +105 -103
  28. data/lib/rdoc/erb_partial.rb +13 -11
  29. data/lib/rdoc/erbio.rb +29 -27
  30. data/lib/rdoc/generator/aliki.rb +165 -140
  31. data/lib/rdoc/generator/darkfish.rb +647 -631
  32. data/lib/rdoc/generator/json_index.rb +233 -229
  33. data/lib/rdoc/generator/markup.rb +165 -122
  34. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  35. data/lib/rdoc/generator/pot/po.rb +52 -51
  36. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  37. data/lib/rdoc/generator/pot.rb +85 -81
  38. data/lib/rdoc/generator/ri.rb +23 -19
  39. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  40. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  41. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  42. data/lib/rdoc/generator/template/aliki/_head.rhtml +11 -11
  43. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  44. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  45. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  46. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  47. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
  48. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  49. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  50. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  51. data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
  52. data/lib/rdoc/generator/template/aliki/css/rdoc.css +538 -283
  53. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  54. data/lib/rdoc/generator/template/aliki/js/aliki.js +80 -102
  55. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  57. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  58. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  59. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  60. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  61. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  62. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  63. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  64. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  65. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  66. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  67. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  68. data/lib/rdoc/generator.rb +48 -46
  69. data/lib/rdoc/i18n/locale.rb +99 -95
  70. data/lib/rdoc/i18n/text.rb +109 -105
  71. data/lib/rdoc/i18n.rb +7 -5
  72. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  73. data/lib/rdoc/markdown.kpeg +30 -21
  74. data/lib/rdoc/markdown.rb +329 -151
  75. data/lib/rdoc/markup/block_quote.rb +12 -8
  76. data/lib/rdoc/markup/document.rb +127 -123
  77. data/lib/rdoc/markup/formatter.rb +215 -221
  78. data/lib/rdoc/markup/heading.rb +1 -4
  79. data/lib/rdoc/markup/include.rb +33 -29
  80. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  81. data/lib/rdoc/markup/inline_parser.rb +281 -277
  82. data/lib/rdoc/markup/list.rb +80 -88
  83. data/lib/rdoc/markup/list_item.rb +73 -85
  84. data/lib/rdoc/markup/paragraph.rb +23 -19
  85. data/lib/rdoc/markup/parser.rb +501 -497
  86. data/lib/rdoc/markup/pre_process.rb +284 -305
  87. data/lib/rdoc/markup/raw.rb +2 -2
  88. data/lib/rdoc/markup/rule.rb +16 -12
  89. data/lib/rdoc/markup/to_ansi.rb +143 -139
  90. data/lib/rdoc/markup/to_bs.rb +72 -68
  91. data/lib/rdoc/markup/to_html.rb +600 -493
  92. data/lib/rdoc/markup/to_html_crossref.rb +221 -191
  93. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  94. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  95. data/lib/rdoc/markup/to_label.rb +63 -59
  96. data/lib/rdoc/markup/to_markdown.rb +212 -208
  97. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  98. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  99. data/lib/rdoc/markup/to_test.rb +60 -56
  100. data/lib/rdoc/markup/to_tt_only.rb +83 -86
  101. data/lib/rdoc/markup/verbatim.rb +62 -58
  102. data/lib/rdoc/markup.rb +198 -196
  103. data/lib/rdoc/options.rb +1063 -1076
  104. data/lib/rdoc/parser/c.rb +1039 -1036
  105. data/lib/rdoc/parser/changelog.rb +319 -315
  106. data/lib/rdoc/parser/markdown.rb +17 -13
  107. data/lib/rdoc/parser/rbs.rb +279 -0
  108. data/lib/rdoc/parser/rd.rb +17 -13
  109. data/lib/rdoc/parser/ruby.rb +1231 -2222
  110. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  111. data/lib/rdoc/parser/simple.rb +31 -27
  112. data/lib/rdoc/parser/text.rb +12 -8
  113. data/lib/rdoc/parser.rb +230 -221
  114. data/lib/rdoc/rbs_helper.rb +186 -0
  115. data/lib/rdoc/rd/inline.rb +57 -53
  116. data/lib/rdoc/rd.rb +90 -88
  117. data/lib/rdoc/rdoc.rb +547 -366
  118. data/lib/rdoc/ri/driver.rb +1141 -1130
  119. data/lib/rdoc/ri/formatter.rb +7 -3
  120. data/lib/rdoc/ri/paths.rb +140 -136
  121. data/lib/rdoc/ri/servlet.rb +456 -0
  122. data/lib/rdoc/ri/store.rb +4 -2
  123. data/lib/rdoc/ri/task.rb +55 -51
  124. data/lib/rdoc/ri.rb +14 -11
  125. data/lib/rdoc/rubygems_hook.rb +194 -192
  126. data/lib/rdoc/server.rb +462 -0
  127. data/lib/rdoc/stats/normal.rb +46 -42
  128. data/lib/rdoc/stats/quiet.rb +39 -35
  129. data/lib/rdoc/stats/verbose.rb +35 -31
  130. data/lib/rdoc/stats.rb +363 -338
  131. data/lib/rdoc/store.rb +919 -725
  132. data/lib/rdoc/task.rb +260 -255
  133. data/lib/rdoc/text.rb +130 -245
  134. data/lib/rdoc/token_stream.rb +101 -115
  135. data/lib/rdoc/tom_doc.rb +203 -201
  136. data/lib/rdoc/version.rb +1 -1
  137. data/lib/rdoc.rb +35 -7
  138. data/lib/rubygems_plugin.rb +2 -11
  139. data/rdoc-logo.svg +43 -0
  140. data/rdoc.gemspec +6 -4
  141. metadata +36 -20
  142. data/lib/rdoc/code_object/anon_class.rb +0 -10
  143. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  144. data/lib/rdoc/code_object/meta_method.rb +0 -6
  145. data/lib/rdoc/markdown/literals.kpeg +0 -21
  146. data/lib/rdoc/markdown/literals.rb +0 -454
  147. data/lib/rdoc/parser/prism_ruby.rb +0 -1112
  148. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  149. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  150. data/lib/rdoc/servlet.rb +0 -452
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -13,24 +13,24 @@ authors:
13
13
  - ITOYANAGI Sakura
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2026-02-09 00:00:00.000000000 Z
16
+ date: 2026-09-28 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
- name: psych
19
+ name: erb
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 4.0.0
24
+ version: '0'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 4.0.0
31
+ version: '0'
32
32
  - !ruby/object:Gem::Dependency
33
- name: erb
33
+ name: tsort
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ">="
@@ -44,19 +44,33 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: tsort
47
+ name: prism
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: '0'
52
+ version: 1.6.0
53
53
  type: :runtime
54
54
  prerelease: false
55
55
  version_requirements: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '0'
59
+ version: 1.6.0
60
+ - !ruby/object:Gem::Dependency
61
+ name: rbs
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 4.0.0
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 4.0.0
60
74
  description: |
61
75
  RDoc produces HTML and command-line documentation for Ruby projects.
62
76
  RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentation from the command-line.
@@ -97,7 +111,6 @@ files:
97
111
  - lib/rdoc.rb
98
112
  - lib/rdoc/code_object.rb
99
113
  - lib/rdoc/code_object/alias.rb
100
- - lib/rdoc/code_object/anon_class.rb
101
114
  - lib/rdoc/code_object/any_method.rb
102
115
  - lib/rdoc/code_object/attr.rb
103
116
  - lib/rdoc/code_object/class_module.rb
@@ -105,9 +118,7 @@ files:
105
118
  - lib/rdoc/code_object/context.rb
106
119
  - lib/rdoc/code_object/context/section.rb
107
120
  - lib/rdoc/code_object/extend.rb
108
- - lib/rdoc/code_object/ghost_method.rb
109
121
  - lib/rdoc/code_object/include.rb
110
- - lib/rdoc/code_object/meta_method.rb
111
122
  - lib/rdoc/code_object/method_attr.rb
112
123
  - lib/rdoc/code_object/mixin.rb
113
124
  - lib/rdoc/code_object/normal_class.rb
@@ -131,6 +142,7 @@ files:
131
142
  - lib/rdoc/generator/pot/po.rb
132
143
  - lib/rdoc/generator/pot/po_entry.rb
133
144
  - lib/rdoc/generator/ri.rb
145
+ - lib/rdoc/generator/template/aliki/DESIGN.md
134
146
  - lib/rdoc/generator/template/aliki/_aside_toc.rhtml
135
147
  - lib/rdoc/generator/template/aliki/_footer.rhtml
136
148
  - lib/rdoc/generator/template/aliki/_head.rhtml
@@ -222,9 +234,8 @@ files:
222
234
  - lib/rdoc/known_classes.rb
223
235
  - lib/rdoc/markdown.kpeg
224
236
  - lib/rdoc/markdown.rb
237
+ - lib/rdoc/markdown/byte_runtime.rb
225
238
  - lib/rdoc/markdown/entities.rb
226
- - lib/rdoc/markdown/literals.kpeg
227
- - lib/rdoc/markdown/literals.rb
228
239
  - lib/rdoc/markup.rb
229
240
  - lib/rdoc/markup/blank_line.rb
230
241
  - lib/rdoc/markup/block_quote.rb
@@ -262,13 +273,13 @@ files:
262
273
  - lib/rdoc/parser/c.rb
263
274
  - lib/rdoc/parser/changelog.rb
264
275
  - lib/rdoc/parser/markdown.rb
265
- - lib/rdoc/parser/prism_ruby.rb
276
+ - lib/rdoc/parser/rbs.rb
266
277
  - lib/rdoc/parser/rd.rb
267
- - lib/rdoc/parser/ripper_state_lex.rb
268
278
  - lib/rdoc/parser/ruby.rb
269
- - lib/rdoc/parser/ruby_tools.rb
279
+ - lib/rdoc/parser/ruby_colorizer.rb
270
280
  - lib/rdoc/parser/simple.rb
271
281
  - lib/rdoc/parser/text.rb
282
+ - lib/rdoc/rbs_helper.rb
272
283
  - lib/rdoc/rd.rb
273
284
  - lib/rdoc/rd/block_parser.rb
274
285
  - lib/rdoc/rd/block_parser.ry
@@ -280,10 +291,11 @@ files:
280
291
  - lib/rdoc/ri/driver.rb
281
292
  - lib/rdoc/ri/formatter.rb
282
293
  - lib/rdoc/ri/paths.rb
294
+ - lib/rdoc/ri/servlet.rb
283
295
  - lib/rdoc/ri/store.rb
284
296
  - lib/rdoc/ri/task.rb
285
297
  - lib/rdoc/rubygems_hook.rb
286
- - lib/rdoc/servlet.rb
298
+ - lib/rdoc/server.rb
287
299
  - lib/rdoc/stats.rb
288
300
  - lib/rdoc/stats/normal.rb
289
301
  - lib/rdoc/stats/quiet.rb
@@ -296,10 +308,12 @@ files:
296
308
  - lib/rdoc/version.rb
297
309
  - lib/rubygems_plugin.rb
298
310
  - man/ri.1
311
+ - rdoc-logo.svg
299
312
  - rdoc.gemspec
300
313
  homepage: https://ruby.github.io/rdoc
301
314
  licenses:
302
315
  - Ruby
316
+ - GPL-2.0-only
303
317
  metadata:
304
318
  homepage_uri: https://ruby.github.io/rdoc
305
319
  source_code_uri: https://github.com/ruby/rdoc
@@ -307,20 +321,22 @@ metadata:
307
321
  rdoc_options:
308
322
  - "--main"
309
323
  - README.md
324
+ - "--copy-files"
325
+ - rdoc-logo.svg
310
326
  require_paths:
311
327
  - lib
312
328
  required_ruby_version: !ruby/object:Gem::Requirement
313
329
  requirements:
314
330
  - - ">="
315
331
  - !ruby/object:Gem::Version
316
- version: 2.6.0
332
+ version: 3.2.0
317
333
  required_rubygems_version: !ruby/object:Gem::Requirement
318
334
  requirements:
319
335
  - - ">="
320
336
  - !ruby/object:Gem::Version
321
337
  version: '2.2'
322
338
  requirements: []
323
- rubygems_version: 4.0.3
339
+ rubygems_version: 4.0.20
324
340
  specification_version: 4
325
341
  summary: RDoc produces HTML and command-line documentation for Ruby projects
326
342
  test_files: []
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
- ##
3
- # An anonymous class like:
4
- #
5
- # c = Class.new do end
6
- #
7
- # AnonClass is currently not used.
8
-
9
- class RDoc::AnonClass < RDoc::ClassModule
10
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- ##
3
- # GhostMethod represents a method referenced only by a comment
4
-
5
- class RDoc::GhostMethod < RDoc::AnyMethod
6
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- ##
3
- # MetaMethod represents a meta-programmed method
4
-
5
- class RDoc::MetaMethod < RDoc::AnyMethod
6
- end
@@ -1,21 +0,0 @@
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}/
@@ -1,454 +0,0 @@
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