racc 1.4.14-java → 1.4.15-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/Manifest.txt +50 -0
  3. data/ext/racc/com/headius/racc/Cparse.java +66 -23
  4. data/ext/racc/cparse.c +1 -1
  5. data/ext/racc/depend +1 -1
  6. data/lib/racc/cparse-jruby.jar +0 -0
  7. data/lib/racc/info.rb +2 -2
  8. data/test/assets/bibtex.y +141 -0
  9. data/test/assets/cadenza.y +170 -0
  10. data/test/assets/cast.y +926 -0
  11. data/test/assets/csspool.y +729 -0
  12. data/test/assets/edtf.y +583 -0
  13. data/test/assets/huia.y +318 -0
  14. data/test/assets/journey.y +47 -0
  15. data/test/assets/liquor.y +313 -0
  16. data/test/assets/machete.y +423 -0
  17. data/test/assets/macruby.y +2197 -0
  18. data/test/assets/mediacloth.y +599 -0
  19. data/test/assets/mof.y +649 -0
  20. data/test/assets/namae.y +302 -0
  21. data/test/assets/nasl.y +626 -0
  22. data/test/assets/nokogiri-css.y +255 -0
  23. data/test/assets/opal.y +1807 -0
  24. data/test/assets/php_serialization.y +98 -0
  25. data/test/assets/rdblockparser.y +576 -0
  26. data/test/assets/rdinlineparser.y +561 -0
  27. data/test/assets/riml.y +665 -0
  28. data/test/assets/ruby18.y +1943 -0
  29. data/test/assets/ruby19.y +2174 -0
  30. data/test/assets/ruby20.y +2350 -0
  31. data/test/assets/ruby21.y +2359 -0
  32. data/test/assets/ruby22.y +2381 -0
  33. data/test/assets/tp_plus.y +622 -0
  34. data/test/assets/twowaysql.y +278 -0
  35. data/test/helper.rb +50 -34
  36. data/test/regress/bibtex +474 -0
  37. data/test/regress/cadenza +796 -0
  38. data/test/regress/cast +3425 -0
  39. data/test/regress/csspool +2318 -0
  40. data/test/regress/edtf +1794 -0
  41. data/test/regress/huia +1392 -0
  42. data/test/regress/journey +222 -0
  43. data/test/regress/liquor +885 -0
  44. data/test/regress/machete +833 -0
  45. data/test/regress/mediacloth +1463 -0
  46. data/test/regress/mof +1368 -0
  47. data/test/regress/namae +634 -0
  48. data/test/regress/nasl +2058 -0
  49. data/test/regress/nokogiri-css +836 -0
  50. data/test/regress/opal +6429 -0
  51. data/test/regress/php_serialization +336 -0
  52. data/test/regress/rdblockparser +1061 -0
  53. data/test/regress/rdinlineparser +1243 -0
  54. data/test/regress/riml +3297 -0
  55. data/test/regress/ruby18 +6351 -0
  56. data/test/regress/ruby22 +7456 -0
  57. data/test/regress/tp_plus +1933 -0
  58. data/test/regress/twowaysql +556 -0
  59. data/test/test_racc_command.rb +177 -0
  60. metadata +80 -25
  61. data/.gemtest +0 -0
@@ -0,0 +1,561 @@
1
+ # Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ # You can redistribute it and/or modify it under either the terms of the GPL
3
+ # version 2 (see https://github.com/uwabami/rdtool/blob/master/COPYING.txt),
4
+ # or the conditions below:
5
+ #
6
+ # 1. You may make and give away verbatim copies of the source form of the
7
+ # software without restriction, provided that you duplicate all of the
8
+ # original copyright notices and associated disclaimers.
9
+ #
10
+ # 2. You may modify your copy of the software in any way, provided that
11
+ # you do at least ONE of the following:
12
+ #
13
+ # a) place your modifications in the Public Domain or otherwise
14
+ # make them Freely Available, such as by posting said
15
+ # modifications to Usenet or an equivalent medium, or by allowing
16
+ # the author to include your modifications in the software.
17
+ #
18
+ # b) use the modified software only within your corporation or
19
+ # organization.
20
+ #
21
+ # c) rename any non-standard executables so the names do not conflict
22
+ # with standard executables, which must also be provided.
23
+ #
24
+ # d) make other distribution arrangements with the author.
25
+ #
26
+ # 3. You may distribute the software in object code or executable
27
+ # form, provided that you do at least ONE of the following:
28
+ #
29
+ # a) distribute the executables and library files of the software,
30
+ # together with instructions (in the manual page or equivalent)
31
+ # on where to get the original distribution.
32
+ #
33
+ # b) accompany the distribution with the machine-readable source of
34
+ # the software.
35
+ #
36
+ # c) give non-standard executables non-standard names, with
37
+ # instructions on where to get the original software distribution.
38
+ #
39
+ # d) make other distribution arrangements with the author.
40
+ #
41
+ # 4. You may modify and include the part of the software into any other
42
+ # software (possibly commercial). But some files in the distribution
43
+ # are not written by the author, so that they are not under this terms.
44
+ #
45
+ # They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
46
+ # files under the ./missing directory. See each file for the copying
47
+ # condition.
48
+ #
49
+ # 5. The scripts and library files supplied as input to or produced as
50
+ # output from the software do not automatically fall under the
51
+ # copyright of the software, but belong to whomever generated them,
52
+ # and may be sold commercially, and may be aggregated with this
53
+ # software.
54
+ #
55
+ # 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
56
+ # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
57
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58
+ # PURPOSE.
59
+
60
+ class RDInlineParser
61
+
62
+ preclow
63
+ nonassoc EX_LOW
64
+ left QUOTE BAR SLASH BACK_SLASH URL OTHER
65
+ REF_OPEN FOOTNOTE_OPEN FOOTNOTE_CLOSE
66
+ nonassoc EX_HIGH
67
+ prechigh
68
+
69
+ token EM_OPEN EM_CLOSE
70
+ CODE_OPEN CODE_CLOSE
71
+ VAR_OPEN VAR_CLOSE
72
+ KBD_OPEN KBD_CLOSE
73
+ INDEX_OPEN INDEX_CLOSE
74
+ REF_OPEN REF_CLOSE
75
+ FOOTNOTE_OPEN FOOTNOTE_CLOSE
76
+ VERB_OPEN VERB_CLOSE
77
+ BAR QUOTE SLASH BACK_SLASH URL OTHER EX_LOW EX_HIGH
78
+
79
+ rule
80
+ content : elements
81
+ ;
82
+ elements : elements element { result.push(val[1]) }
83
+ | element { result = val }
84
+ ;
85
+ element : emphasis
86
+ | code
87
+ | var
88
+ | keyboard
89
+ | index
90
+ | reference
91
+ | footnote
92
+ | verb
93
+ | normal_str_ele
94
+ ;
95
+
96
+ emphasis : EM_OPEN content EM_CLOSE {
97
+ result = Emphasis.new
98
+ add_children_to_element(result, *val[1])
99
+ }
100
+ ;
101
+ code : CODE_OPEN content CODE_CLOSE {
102
+ result = Code.new
103
+ add_children_to_element(result, *val[1])
104
+ }
105
+ ;
106
+ var : VAR_OPEN content VAR_CLOSE {
107
+ result = Var.new
108
+ add_children_to_element(result, *val[1])
109
+ }
110
+ ;
111
+ keyboard : KBD_OPEN content KBD_CLOSE {
112
+ result = Keyboard.new
113
+ add_children_to_element(result, *val[1])
114
+ }
115
+ ;
116
+ index : INDEX_OPEN content INDEX_CLOSE {
117
+ result = Index.new
118
+ add_children_to_element(result, *val[1])
119
+ }
120
+ ;
121
+
122
+ # Refernce
123
+ # ((<subst|filename/element_label>))
124
+
125
+ reference : REF_OPEN substitute ref_label REF_CLOSE
126
+ { result = Reference.new(val[2])
127
+ add_children_to_element(result, *val[1])
128
+ }
129
+ | REF_OPEN ref_label2 REF_CLOSE
130
+ {
131
+ result = make_reference_from_label(val[1])
132
+ }
133
+ ;
134
+
135
+ ref_label : URL ref_url_strings { result = Reference::URL.new(val[1]) }
136
+ | filename element_label
137
+ { result = Reference::TemporaryLabel.new(val[1],
138
+ val[0]) }
139
+ | element_label
140
+ { result = Reference::TemporaryLabel.new(val[0]) }
141
+ | filename { result = Reference::TemporaryLabel.new([], val[0]) }
142
+ ;
143
+ ref_label2 : URL ref_url_strings { result = Reference::URL.new(val[1]) }
144
+ | filename element_label2
145
+ { result = Reference::TemporaryLabel.new(val[1],
146
+ val[0]) }
147
+ | element_label2
148
+ { result = Reference::TemporaryLabel.new(val[0]) }
149
+ | filename { result = Reference::TemporaryLabel.new([],
150
+ val[0]) }
151
+ ;
152
+ substitute : ref_subst_content BAR
153
+ | QUOTE ref_subst_content_q QUOTE BAR
154
+ { result = val[1] }
155
+ | QUOTE ref_subst_strings_q QUOTE BAR
156
+ { result = [StringElement.new(val[1])] }
157
+ ;
158
+
159
+ filename : ref_subst_strings_first SLASH
160
+ | QUOTE ref_subst_strings_q QUOTE SLASH
161
+ { result = val[1] }
162
+ ;
163
+
164
+ # when substitute part exists
165
+ element_label : ref_subst_strings_first
166
+ { result = [StringElement.new(val[0])] }
167
+ | QUOTE ref_subst_strings_q QUOTE
168
+ { result = [StringElement.new(val[1])] }
169
+ ;
170
+ # when substitute part doesn't exist
171
+ # in this case, element label can contain Inlines
172
+ element_label2 : ref_subst_content
173
+ | QUOTE ref_subst_content_q QUOTE
174
+ { result = val[1] }
175
+ | QUOTE ref_subst_strings_q QUOTE
176
+ { result = [StringElement.new(val[1])] }
177
+ ;
178
+
179
+ ref_subst_content : ref_subst_ele2 ref_subst_eles
180
+ { result = val[1].unshift(val[0]) }
181
+ | ref_subst_str_ele_first ref_subst_eles
182
+ { result = val[1].unshift(val[0]) }
183
+ | ref_subst_str_ele_first
184
+ { result = val }
185
+ | ref_subst_ele2 { result = val }
186
+ ;
187
+ ref_subst_content_q : ref_subst_eles_q
188
+ ;
189
+ ref_subst_eles : ref_subst_eles ref_subst_ele
190
+ { result.push(val[1]) }
191
+ | ref_subst_ele { result = val }
192
+ ;
193
+ ref_subst_eles_q : ref_subst_eles_q ref_subst_ele_q
194
+ { result.push(val[1]) }
195
+ | ref_subst_ele_q { result = val }
196
+ ;
197
+ ref_subst_ele2 : emphasis
198
+ | code
199
+ | var
200
+ | keyboard
201
+ | index
202
+ | verb
203
+ ;
204
+ ref_subst_ele : ref_subst_ele2
205
+ | ref_subst_str_ele
206
+ ;
207
+ ref_subst_ele_q : ref_subst_ele2
208
+ | ref_subst_str_ele_q
209
+ ;
210
+
211
+ ref_subst_str_ele : ref_subst_strings = EX_LOW
212
+ { result = StringElement.new(val[0]) }
213
+ ;
214
+ ref_subst_str_ele_first : ref_subst_strings_first
215
+ { result = StringElement.new(val[0]) }
216
+ ;
217
+ ref_subst_str_ele_q : ref_subst_strings_q = EX_LOW
218
+ { result = StringElement.new(val[0]) }
219
+ ;
220
+
221
+ ref_subst_strings : ref_subst_strings ref_subst_string3
222
+ { result << val[1] }
223
+ | ref_subst_string3
224
+ ;
225
+ # if it is first element of substitute, it can't contain
226
+ # URL on head.
227
+ ref_subst_strings_first : ref_subst_string ref_subst_strings = EX_HIGH
228
+ { result << val[1] }
229
+ | ref_subst_string = EX_LOW
230
+ ;
231
+ ref_subst_strings_q : ref_subst_strings_q ref_subst_string_q
232
+ { result << val[1] }
233
+ | ref_subst_string_q
234
+ ;
235
+
236
+ ref_subst_string : OTHER
237
+ | BACK_SLASH
238
+ | REF_OPEN
239
+ | FOOTNOTE_OPEN
240
+ | FOOTNOTE_CLOSE
241
+ ;
242
+ ref_subst_string2 : ref_subst_string
243
+ | URL
244
+ ;
245
+ ref_subst_string3 : ref_subst_string2
246
+ | QUOTE
247
+ ;
248
+ ref_subst_string_q : ref_subst_string2
249
+ | BAR
250
+ | SLASH
251
+ ;
252
+ # end subst
253
+
254
+ # string in url
255
+ ref_url_strings : ref_url_strings ref_url_string { result << val[1] }
256
+ | ref_url_string
257
+ ;
258
+
259
+ ref_url_string : OTHER
260
+ | BACK_SLASH BACK_SLASH
261
+ | URL
262
+ | SLASH
263
+ | BAR
264
+ | QUOTE
265
+ | EM_OPEN
266
+ | EM_CLOSE
267
+ | CODE_OPEN
268
+ | CODE_CLOSE
269
+ | VAR_OPEN
270
+ | VAR_CLOSE
271
+ | KBD_OPEN
272
+ | KBD_CLOSE
273
+ | INDEX_OPEN
274
+ | INDEX_CLOSE
275
+ | REF_OPEN
276
+ | FOOTNOTE_OPEN
277
+ | FOOTNOTE_CLOSE
278
+ | VERB_OPEN
279
+ | VERB_CLOSE
280
+ ;
281
+
282
+ # end url
283
+ # end Reference
284
+
285
+ footnote : FOOTNOTE_OPEN content FOOTNOTE_CLOSE {
286
+ result = Footnote.new
287
+ add_children_to_element(result, *val[1])
288
+ }
289
+ ;
290
+ verb : VERB_OPEN verb_strings VERB_CLOSE {
291
+ result = Verb.new(val[1]) }
292
+ ;
293
+
294
+
295
+ # normal string
296
+ # OTHER, QUOTE, BAR, SLASH, BACK_SLASH, URL
297
+ normal_string : OTHER
298
+ | QUOTE
299
+ | BAR
300
+ | SLASH
301
+ | BACK_SLASH
302
+ | URL
303
+ ;
304
+ normal_strings : normal_strings normal_string
305
+ { result << val[1] }
306
+
307
+ | normal_string
308
+ ;
309
+ normal_str_ele : normal_strings = EX_LOW
310
+ { result = StringElement.new(val[0]) }
311
+ ;
312
+
313
+ # in verb
314
+ verb_string : verb_normal_string
315
+ | BACK_SLASH verb_normal_string { result = val[1] }
316
+ | BACK_SLASH VERB_CLOSE { result = val[1] }
317
+ | BACK_SLASH BACK_SLASH { result = val[1] }
318
+ ;
319
+
320
+ verb_normal_string : OTHER
321
+ | QUOTE
322
+ | BAR
323
+ | SLASH
324
+ | EM_OPEN
325
+ | EM_CLOSE
326
+ | CODE_OPEN
327
+ | CODE_CLOSE
328
+ | VAR_OPEN
329
+ | VAR_CLOSE
330
+ | KBD_OPEN
331
+ | KBD_CLOSE
332
+ | INDEX_OPEN
333
+ | INDEX_CLOSE
334
+ | REF_OPEN
335
+ | REF_CLOSE
336
+ | FOOTNOTE_OPEN
337
+ | FOOTNOTE_CLOSE
338
+ | VERB_OPEN
339
+ | URL
340
+ ;
341
+
342
+ verb_strings : verb_strings verb_string { result << val[1] }
343
+ | verb_string
344
+ ;
345
+ /* verb_str_ele : verb_strings
346
+ ; */
347
+ end
348
+
349
+ ---- inner
350
+ include ParserUtility
351
+ extend Forwardable
352
+
353
+ EM_OPEN = '((*'
354
+ EM_OPEN_RE = /\A#{Regexp.quote(EM_OPEN)}/
355
+ EM_CLOSE = '*))'
356
+ EM_CLOSE_RE = /\A#{Regexp.quote(EM_CLOSE)}/
357
+ CODE_OPEN = '(({'
358
+ CODE_OPEN_RE = /\A#{Regexp.quote(CODE_OPEN)}/
359
+ CODE_CLOSE = '}))'
360
+ CODE_CLOSE_RE = /\A#{Regexp.quote(CODE_CLOSE)}/
361
+ VAR_OPEN = '((|'
362
+ VAR_OPEN_RE = /\A#{Regexp.quote(VAR_OPEN)}/
363
+ VAR_CLOSE = '|))'
364
+ VAR_CLOSE_RE = /\A#{Regexp.quote(VAR_CLOSE)}/
365
+ KBD_OPEN = '((%'
366
+ KBD_OPEN_RE = /\A#{Regexp.quote(KBD_OPEN)}/
367
+ KBD_CLOSE = '%))'
368
+ KBD_CLOSE_RE = /\A#{Regexp.quote(KBD_CLOSE)}/
369
+ INDEX_OPEN = '((:'
370
+ INDEX_OPEN_RE = /\A#{Regexp.quote(INDEX_OPEN)}/
371
+ INDEX_CLOSE = ':))'
372
+ INDEX_CLOSE_RE = /\A#{Regexp.quote(INDEX_CLOSE)}/
373
+ REF_OPEN = '((<'
374
+ REF_OPEN_RE = /\A#{Regexp.quote(REF_OPEN)}/
375
+ REF_CLOSE = '>))'
376
+ REF_CLOSE_RE = /\A#{Regexp.quote(REF_CLOSE)}/
377
+ FOOTNOTE_OPEN = '((-'
378
+ FOOTNOTE_OPEN_RE = /\A#{Regexp.quote(FOOTNOTE_OPEN)}/
379
+ FOOTNOTE_CLOSE = '-))'
380
+ FOOTNOTE_CLOSE_RE = /\A#{Regexp.quote(FOOTNOTE_CLOSE)}/
381
+ VERB_OPEN = "(('"
382
+ VERB_OPEN_RE = /\A#{Regexp.quote(VERB_OPEN)}/
383
+ VERB_CLOSE = "'))"
384
+ VERB_CLOSE_RE = /\A#{Regexp.quote(VERB_CLOSE)}/
385
+
386
+ BAR = "|"
387
+ BAR_RE = /\A#{Regexp.quote(BAR)}/
388
+ QUOTE = '"'
389
+ QUOTE_RE = /\A#{Regexp.quote(QUOTE)}/
390
+ SLASH = "/"
391
+ SLASH_RE = /\A#{Regexp.quote(SLASH)}/
392
+ BACK_SLASH = "\\"
393
+ BACK_SLASH_RE = /\A#{Regexp.quote(BACK_SLASH)}/
394
+ URL = "URL:"
395
+ URL_RE = /\A#{Regexp.quote(URL)}/
396
+
397
+ # Workaround for Regexp option change of Ruby 1.5.x
398
+ other_re_mode = Regexp::EXTENDED
399
+ if RUBY_VERSION > "1.5"
400
+ other_re_mode |= Regexp::MULTILINE
401
+ else
402
+ other_re_mode |= Regexp::POSIXLINE
403
+ end
404
+
405
+ OTHER_RE = Regexp.new(
406
+ "\\A.+?(?=#{Regexp.quote(EM_OPEN)}|#{Regexp.quote(EM_CLOSE)}|
407
+ #{Regexp.quote(CODE_OPEN)}|#{Regexp.quote(CODE_CLOSE)}|
408
+ #{Regexp.quote(VAR_OPEN)}|#{Regexp.quote(VAR_CLOSE)}|
409
+ #{Regexp.quote(KBD_OPEN)}|#{Regexp.quote(KBD_CLOSE)}|
410
+ #{Regexp.quote(INDEX_OPEN)}|#{Regexp.quote(INDEX_CLOSE)}|
411
+ #{Regexp.quote(REF_OPEN)}|#{Regexp.quote(REF_CLOSE)}|
412
+ #{Regexp.quote(FOOTNOTE_OPEN)}|#{Regexp.quote(FOOTNOTE_CLOSE)}|
413
+ #{Regexp.quote(VERB_OPEN)}|#{Regexp.quote(VERB_CLOSE)}|
414
+ #{Regexp.quote(BAR)}|
415
+ #{Regexp.quote(QUOTE)}|
416
+ #{Regexp.quote(SLASH)}|
417
+ #{Regexp.quote(BACK_SLASH)}|
418
+ #{Regexp.quote(URL)})", other_re_mode)
419
+
420
+ def initialize(bp)
421
+ @blockp = bp
422
+ end
423
+
424
+ def_delegator(:@blockp, :tree)
425
+
426
+ def parse(src)
427
+ @src = StringScanner.new(src)
428
+ @pre = ""
429
+ @yydebug = true
430
+ do_parse
431
+ end
432
+
433
+ def next_token
434
+ return [false, false] if @src.eos?
435
+ # p @src.rest if @yydebug
436
+ if ret = @src.scan(EM_OPEN_RE)
437
+ @pre << ret
438
+ [:EM_OPEN, ret]
439
+ elsif ret = @src.scan(EM_CLOSE_RE)
440
+ @pre << ret
441
+ [:EM_CLOSE, ret]
442
+ elsif ret = @src.scan(CODE_OPEN_RE)
443
+ @pre << ret
444
+ [:CODE_OPEN, ret]
445
+ elsif ret = @src.scan(CODE_CLOSE_RE)
446
+ @pre << ret
447
+ [:CODE_CLOSE, ret]
448
+ elsif ret = @src.scan(VAR_OPEN_RE)
449
+ @pre << ret
450
+ [:VAR_OPEN, ret]
451
+ elsif ret = @src.scan(VAR_CLOSE_RE)
452
+ @pre << ret
453
+ [:VAR_CLOSE, ret]
454
+ elsif ret = @src.scan(KBD_OPEN_RE)
455
+ @pre << ret
456
+ [:KBD_OPEN, ret]
457
+ elsif ret = @src.scan(KBD_CLOSE_RE)
458
+ @pre << ret
459
+ [:KBD_CLOSE, ret]
460
+ elsif ret = @src.scan(INDEX_OPEN_RE)
461
+ @pre << ret
462
+ [:INDEX_OPEN, ret]
463
+ elsif ret = @src.scan(INDEX_CLOSE_RE)
464
+ @pre << ret
465
+ [:INDEX_CLOSE, ret]
466
+ elsif ret = @src.scan(REF_OPEN_RE)
467
+ @pre << ret
468
+ [:REF_OPEN, ret]
469
+ elsif ret = @src.scan(REF_CLOSE_RE)
470
+ @pre << ret
471
+ [:REF_CLOSE, ret]
472
+ elsif ret = @src.scan(FOOTNOTE_OPEN_RE)
473
+ @pre << ret
474
+ [:FOOTNOTE_OPEN, ret]
475
+ elsif ret = @src.scan(FOOTNOTE_CLOSE_RE)
476
+ @pre << ret
477
+ [:FOOTNOTE_CLOSE, ret]
478
+ elsif ret = @src.scan(VERB_OPEN_RE)
479
+ @pre << ret
480
+ [:VERB_OPEN, ret]
481
+ elsif ret = @src.scan(VERB_CLOSE_RE)
482
+ @pre << ret
483
+ [:VERB_CLOSE, ret]
484
+ elsif ret = @src.scan(BAR_RE)
485
+ @pre << ret
486
+ [:BAR, ret]
487
+ elsif ret = @src.scan(QUOTE_RE)
488
+ @pre << ret
489
+ [:QUOTE, ret]
490
+ elsif ret = @src.scan(SLASH_RE)
491
+ @pre << ret
492
+ [:SLASH, ret]
493
+ elsif ret = @src.scan(BACK_SLASH_RE)
494
+ @pre << ret
495
+ [:BACK_SLASH, ret]
496
+ elsif ret = @src.scan(URL_RE)
497
+ @pre << ret
498
+ [:URL, ret]
499
+ elsif ret = @src.scan(OTHER_RE)
500
+ @pre << ret
501
+ [:OTHER, ret]
502
+ else
503
+ ret = @src.rest
504
+ @pre << ret
505
+ @src.terminate
506
+ [:OTHER, ret]
507
+ end
508
+ end
509
+
510
+ def make_reference_from_label(label)
511
+ # Reference.new_from_label_under_document_struct(label, tree.document_struct)
512
+ Reference.new_from_label_without_document_struct(label)
513
+ end
514
+
515
+ def on_error(et, ev, values)
516
+ lines_of_rest = (RUBY_VERSION >= '1.9.0' ? @src.rest.lines.to_a.length : @src.rest.to_a.length )
517
+ prev_words = prev_words_on_error(ev)
518
+ at = 4 + prev_words.length
519
+ message = <<-MSG
520
+ RD syntax error: line #{@blockp.line_index - lines_of_rest}:
521
+ ...#{prev_words} #{(ev||'')} #{next_words_on_error()} ...
522
+ MSG
523
+ message << " " * at + "^" * (ev ? ev.length : 0) + "\n"
524
+ raise ParseError, message
525
+ end
526
+
527
+ def prev_words_on_error(ev)
528
+ pre = @pre
529
+ if ev and /#{Regexp.quote(ev)}$/ =~ pre
530
+ pre = $`
531
+ end
532
+ last_line(pre)
533
+ end
534
+
535
+ def last_line(src)
536
+ if n = src.rindex("\n")
537
+ src[(n+1) .. -1]
538
+ else
539
+ src
540
+ end
541
+ end
542
+ private :last_line
543
+
544
+ def next_words_on_error
545
+ if n = @src.rest.index("\n")
546
+ @src.rest[0 .. (n-1)]
547
+ else
548
+ @src.rest
549
+ end
550
+ end
551
+
552
+ ---- header
553
+
554
+ require "rd/parser-util"
555
+ require "forwardable"
556
+ require "strscan"
557
+
558
+ module RD
559
+ ---- footer
560
+ end # end of module RD
561
+