rdoc 6.2.0 → 6.2.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

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