raf 0.0.3 → 0.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.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/Gemfile +3 -12
- data/Gemfile.lock +10 -13
- data/History.rdoc +12 -0
- data/README.rdoc +10 -3
- data/Rakefile +1 -53
- data/VERSION +1 -1
- data/bin/raf2html +4 -1
- data/lib/parserutility.rb +3 -0
- data/lib/raf2html.rb +28 -41
- data/lib/raf2html_element.rb +26 -23
- data/lib/rafblockparser.ry +7 -5
- data/lib/rafblockparser.tab.rb +79 -81
- data/lib/rafelement.rb +34 -24
- data/lib/rafinlineparser.ry +10 -8
- data/lib/rafinlineparser.tab.rb +175 -173
- data/raf.gemspec +16 -112
- data/test.raf +4 -0
- metadata +52 -103
- data/lib/default.css +0 -116
data/lib/rafblockparser.tab.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# DO NOT MODIFY!!!!
|
3
|
-
# This file is automatically generated by Racc 1.4.
|
3
|
+
# This file is automatically generated by Racc 1.4.10
|
4
4
|
# from Racc grammer file "".
|
5
5
|
#
|
6
6
|
|
@@ -14,7 +14,7 @@ module Raf
|
|
14
14
|
|
15
15
|
class BlockParser < Racc::Parser
|
16
16
|
|
17
|
-
module_eval(<<'...end rafblockparser.ry/module_eval...', 'rafblockparser.ry',
|
17
|
+
module_eval(<<'...end rafblockparser.ry/module_eval...', 'rafblockparser.ry', 120)
|
18
18
|
include ParserUtility
|
19
19
|
|
20
20
|
class Line
|
@@ -38,16 +38,16 @@ end
|
|
38
38
|
|
39
39
|
def initialize
|
40
40
|
@inline_parser = InlineParser.new
|
41
|
-
@
|
41
|
+
@metadata = {}
|
42
42
|
@inline_index = @inline_parser.index
|
43
43
|
@index = {}
|
44
44
|
@head_index = HeadIndex.new
|
45
45
|
end
|
46
|
-
attr_reader :
|
46
|
+
attr_reader :metadata, :inline_index, :index
|
47
47
|
|
48
48
|
def parse(src)
|
49
49
|
@no = 0
|
50
|
-
@src = src
|
50
|
+
@src = Array(src)
|
51
51
|
@line = Line.new("")
|
52
52
|
@line_pre = @line.dup
|
53
53
|
@indent_stack = []
|
@@ -233,58 +233,56 @@ end
|
|
233
233
|
##### State transition tables begin ###
|
234
234
|
|
235
235
|
racc_action_table = [
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
236
|
+
13, 12, 14, 16, 17, 46, 19, 23, 35, 25,
|
237
|
+
25, 29, 31, 13, 12, 14, 16, 17, 25, 19,
|
238
|
+
23, 47, 25, 37, 29, 31, 23, 29, 25, 37,
|
239
|
+
29, 37, 52, 29, 48, 29, 35, 51, 25, 35,
|
240
|
+
49, 25, 41, 40, 50, 38, 32, 53 ]
|
241
241
|
|
242
242
|
racc_action_check = [
|
243
|
-
0, 0, 0, 0, 0,
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
243
|
+
0, 0, 0, 0, 0, 25, 0, 0, 35, 0,
|
244
|
+
35, 0, 0, 2, 2, 2, 2, 2, 21, 2,
|
245
|
+
2, 27, 2, 8, 2, 2, 23, 8, 23, 37,
|
246
|
+
23, 44, 44, 37, 30, 44, 43, 43, 43, 7,
|
247
|
+
32, 7, 18, 17, 39, 15, 1, 45 ]
|
248
248
|
|
249
249
|
racc_action_pointer = [
|
250
|
-
-2,
|
251
|
-
nil, nil, nil,
|
252
|
-
|
253
|
-
|
254
|
-
nil,
|
250
|
+
-2, 46, 11, nil, nil, nil, nil, 30, 14, nil,
|
251
|
+
nil, nil, nil, nil, nil, 40, nil, 36, 34, nil,
|
252
|
+
nil, 7, nil, 17, nil, -7, nil, 8, nil, nil,
|
253
|
+
20, nil, 40, nil, nil, -1, nil, 20, nil, 37,
|
254
|
+
nil, nil, nil, 27, 22, 35, nil, nil, nil, nil,
|
255
255
|
nil, nil, nil, nil ]
|
256
256
|
|
257
257
|
racc_action_default = [
|
258
|
-
-46, -
|
259
|
-
-
|
260
|
-
-
|
261
|
-
-
|
262
|
-
-19, -
|
263
|
-
-20,
|
258
|
+
-46, -46, -1, -2, -4, -5, -6, -7, -8, -9,
|
259
|
+
-10, -11, -12, -13, -14, -15, -16, -21, -22, -23,
|
260
|
+
-25, -27, -28, -46, -30, -32, -36, -38, -39, -41,
|
261
|
+
-43, -44, -46, -3, -26, -46, -37, -46, -17, -18,
|
262
|
+
-19, -24, -31, -46, -46, -33, -34, -42, -45, 54,
|
263
|
+
-20, -29, -40, -35 ]
|
264
264
|
|
265
265
|
racc_goto_table = [
|
266
|
-
|
267
|
-
|
268
|
-
nil, nil, nil, nil, nil, 44, nil, nil, nil, nil,
|
266
|
+
36, 34, 44, 43, 3, 39, 33, 2, 42, 45,
|
267
|
+
1, nil, nil, nil, nil, 43, 44, nil, nil, nil,
|
269
268
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
270
|
-
36,
|
269
|
+
nil, nil, nil, nil, nil, nil, 36, 34 ]
|
271
270
|
|
272
271
|
racc_goto_check = [
|
273
|
-
|
274
|
-
|
275
|
-
nil, nil, nil, nil, nil, 3, nil, nil, nil, nil,
|
272
|
+
20, 15, 8, 7, 3, 13, 3, 2, 18, 19,
|
273
|
+
1, nil, nil, nil, nil, 7, 8, nil, nil, nil,
|
276
274
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
277
|
-
20, 15 ]
|
275
|
+
nil, nil, nil, nil, nil, nil, 20, 15 ]
|
278
276
|
|
279
277
|
racc_goto_pointer = [
|
280
|
-
nil,
|
281
|
-
nil, nil, nil, -
|
282
|
-
-
|
278
|
+
nil, 10, 7, 4, nil, nil, nil, -20, -21, nil,
|
279
|
+
nil, nil, nil, -12, nil, -6, nil, nil, -13, -16,
|
280
|
+
-8, nil, nil, nil ]
|
283
281
|
|
284
282
|
racc_goto_default = [
|
285
|
-
nil, nil, nil, nil,
|
286
|
-
|
287
|
-
|
283
|
+
nil, nil, nil, nil, 4, 5, 6, 7, 8, 9,
|
284
|
+
10, 11, 15, nil, 18, 20, 21, 22, 24, nil,
|
285
|
+
26, 27, 28, 30 ]
|
288
286
|
|
289
287
|
racc_reduce_table = [
|
290
288
|
0, 0, :racc_error,
|
@@ -424,19 +422,19 @@ Racc_debug_parser = false
|
|
424
422
|
|
425
423
|
# reduce 0 omitted
|
426
424
|
|
427
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
425
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 10)
|
428
426
|
def _reduce_1(val, _values)
|
429
427
|
val[0].compact
|
430
428
|
end
|
431
429
|
.,.,
|
432
430
|
|
433
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
431
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 12)
|
434
432
|
def _reduce_2(val, _values)
|
435
433
|
val
|
436
434
|
end
|
437
435
|
.,.,
|
438
436
|
|
439
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
437
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 13)
|
440
438
|
def _reduce_3(val, _values)
|
441
439
|
[val[0], val[1]].flatten
|
442
440
|
end
|
@@ -444,7 +442,7 @@ module_eval(<<'.,.,', 'rafblockparser.ry', 11)
|
|
444
442
|
|
445
443
|
# reduce 4 omitted
|
446
444
|
|
447
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
445
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 16)
|
448
446
|
def _reduce_5(val, _values)
|
449
447
|
val[0]
|
450
448
|
end
|
@@ -452,13 +450,13 @@ module_eval(<<'.,.,', 'rafblockparser.ry', 14)
|
|
452
450
|
|
453
451
|
# reduce 6 omitted
|
454
452
|
|
455
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
453
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 18)
|
456
454
|
def _reduce_7(val, _values)
|
457
455
|
ItemList.new(val[0].flatten)
|
458
456
|
end
|
459
457
|
.,.,
|
460
458
|
|
461
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
459
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 19)
|
462
460
|
def _reduce_8(val, _values)
|
463
461
|
NumList.new(val[0].flatten)
|
464
462
|
end
|
@@ -470,30 +468,30 @@ module_eval(<<'.,.,', 'rafblockparser.ry', 17)
|
|
470
468
|
|
471
469
|
# reduce 11 omitted
|
472
470
|
|
473
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
471
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 23)
|
474
472
|
def _reduce_12(val, _values)
|
475
473
|
WhiteLine.new
|
476
474
|
end
|
477
475
|
.,.,
|
478
476
|
|
479
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
477
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 27)
|
480
478
|
def _reduce_13(val, _values)
|
481
479
|
name, val = val[0].split(":",2)
|
482
480
|
if name.nil? or val.nil?
|
483
481
|
else
|
484
|
-
@
|
482
|
+
@metadata.update({name.strip.to_sym => val.strip })
|
485
483
|
end
|
486
484
|
nil
|
487
485
|
end
|
488
486
|
.,.,
|
489
487
|
|
490
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
488
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 35)
|
491
489
|
def _reduce_14(val, _values)
|
492
490
|
# val[0] is like [level, title, index]
|
493
491
|
title = val[0][1]
|
494
492
|
level = val[0][0]
|
495
493
|
if level == 1
|
496
|
-
@
|
494
|
+
@metadata[:subject] ||= title
|
497
495
|
else
|
498
496
|
@head_index.update(level)
|
499
497
|
end
|
@@ -504,25 +502,25 @@ module_eval(<<'.,.,', 'rafblockparser.ry', 33)
|
|
504
502
|
end
|
505
503
|
.,.,
|
506
504
|
|
507
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
505
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 48)
|
508
506
|
def _reduce_15(val, _values)
|
509
507
|
Paragraph.new @inline_parser.parse(val)
|
510
508
|
end
|
511
509
|
.,.,
|
512
510
|
|
513
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
511
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 50)
|
514
512
|
def _reduce_16(val, _values)
|
515
513
|
val[0]
|
516
514
|
end
|
517
515
|
.,.,
|
518
516
|
|
519
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
517
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 51)
|
520
518
|
def _reduce_17(val, _values)
|
521
519
|
val[0] + val[1]
|
522
520
|
end
|
523
521
|
.,.,
|
524
522
|
|
525
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
523
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 55)
|
526
524
|
def _reduce_18(val, _values)
|
527
525
|
if val[1].nil?
|
528
526
|
lines = [Plain.new("")]
|
@@ -534,13 +532,13 @@ module_eval(<<'.,.,', 'rafblockparser.ry', 53)
|
|
534
532
|
end
|
535
533
|
.,.,
|
536
534
|
|
537
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
535
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 64)
|
538
536
|
def _reduce_19(val, _values)
|
539
537
|
val[0]
|
540
538
|
end
|
541
539
|
.,.,
|
542
540
|
|
543
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
541
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 65)
|
544
542
|
def _reduce_20(val, _values)
|
545
543
|
val[0] + val[1]
|
546
544
|
end
|
@@ -548,145 +546,145 @@ module_eval(<<'.,.,', 'rafblockparser.ry', 63)
|
|
548
546
|
|
549
547
|
# reduce 21 omitted
|
550
548
|
|
551
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
549
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 70)
|
552
550
|
def _reduce_22(val, _values)
|
553
551
|
qu = val[0].strip ; Quote.new([qu]) unless qu.empty?
|
554
552
|
end
|
555
553
|
.,.,
|
556
554
|
|
557
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
555
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 72)
|
558
556
|
def _reduce_23(val, _values)
|
559
557
|
val[0]
|
560
558
|
end
|
561
559
|
.,.,
|
562
560
|
|
563
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
561
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 73)
|
564
562
|
def _reduce_24(val, _values)
|
565
563
|
val[0] + val[1]
|
566
564
|
end
|
567
565
|
.,.,
|
568
566
|
|
569
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
567
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 77)
|
570
568
|
def _reduce_25(val, _values)
|
571
569
|
val[0]
|
572
570
|
end
|
573
571
|
.,.,
|
574
572
|
|
575
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
573
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 78)
|
576
574
|
def _reduce_26(val, _values)
|
577
575
|
val[0] << val[1]
|
578
576
|
end
|
579
577
|
.,.,
|
580
578
|
|
581
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
579
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 80)
|
582
580
|
def _reduce_27(val, _values)
|
583
581
|
val[0]
|
584
582
|
end
|
585
583
|
.,.,
|
586
584
|
|
587
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
585
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 81)
|
588
586
|
def _reduce_28(val, _values)
|
589
587
|
val[0]
|
590
588
|
end
|
591
589
|
.,.,
|
592
590
|
|
593
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
591
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 83)
|
594
592
|
def _reduce_29(val, _values)
|
595
593
|
val
|
596
594
|
end
|
597
595
|
.,.,
|
598
596
|
|
599
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
597
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 85)
|
600
598
|
def _reduce_30(val, _values)
|
601
599
|
[PlainTextBlock.new(@inline_parser.parse(val[0]))]
|
602
600
|
end
|
603
601
|
.,.,
|
604
602
|
|
605
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
603
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 86)
|
606
604
|
def _reduce_31(val, _values)
|
607
605
|
val[0] << PlainTextBlock.new(@inline_parser.parse(val[1]))
|
608
606
|
end
|
609
607
|
.,.,
|
610
608
|
|
611
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
609
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 88)
|
612
610
|
def _reduce_32(val, _values)
|
613
611
|
val[0]
|
614
612
|
end
|
615
613
|
.,.,
|
616
614
|
|
617
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
615
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 89)
|
618
616
|
def _reduce_33(val, _values)
|
619
617
|
val[0] + val[1]
|
620
618
|
end
|
621
619
|
.,.,
|
622
620
|
|
623
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
621
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 91)
|
624
622
|
def _reduce_34(val, _values)
|
625
623
|
"\n" + val[0]
|
626
624
|
end
|
627
625
|
.,.,
|
628
626
|
|
629
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
627
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 92)
|
630
628
|
def _reduce_35(val, _values)
|
631
629
|
val[0] + "\n" + val[1]
|
632
630
|
end
|
633
631
|
.,.,
|
634
632
|
|
635
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
633
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 96)
|
636
634
|
def _reduce_36(val, _values)
|
637
635
|
val[0]
|
638
636
|
end
|
639
637
|
.,.,
|
640
638
|
|
641
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
639
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 97)
|
642
640
|
def _reduce_37(val, _values)
|
643
641
|
val[0] << val[1]
|
644
642
|
end
|
645
643
|
.,.,
|
646
644
|
|
647
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
645
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 99)
|
648
646
|
def _reduce_38(val, _values)
|
649
647
|
val[0]
|
650
648
|
end
|
651
649
|
.,.,
|
652
650
|
|
653
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
651
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 100)
|
654
652
|
def _reduce_39(val, _values)
|
655
653
|
val[0]
|
656
654
|
end
|
657
655
|
.,.,
|
658
656
|
|
659
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
657
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 102)
|
660
658
|
def _reduce_40(val, _values)
|
661
659
|
val
|
662
660
|
end
|
663
661
|
.,.,
|
664
662
|
|
665
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
663
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 104)
|
666
664
|
def _reduce_41(val, _values)
|
667
665
|
[PlainTextBlock.new(@inline_parser.parse(val[0]))]
|
668
666
|
end
|
669
667
|
.,.,
|
670
668
|
|
671
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
669
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 105)
|
672
670
|
def _reduce_42(val, _values)
|
673
671
|
val[0] << PlainTextBlock.new(@inline_parser.parse(val[1]))
|
674
672
|
end
|
675
673
|
.,.,
|
676
674
|
|
677
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
675
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 110)
|
678
676
|
def _reduce_43(val, _values)
|
679
677
|
Table.new(val[0])
|
680
678
|
end
|
681
679
|
.,.,
|
682
680
|
|
683
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
681
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 112)
|
684
682
|
def _reduce_44(val, _values)
|
685
683
|
val
|
686
684
|
end
|
687
685
|
.,.,
|
688
686
|
|
689
|
-
module_eval(<<'.,.,', 'rafblockparser.ry',
|
687
|
+
module_eval(<<'.,.,', 'rafblockparser.ry', 113)
|
690
688
|
def _reduce_45(val, _values)
|
691
689
|
val[0] << val[1]
|
692
690
|
end
|
data/lib/rafelement.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Copyright (C) garin <garin54@gmail.com> 2011
|
3
|
+
# See the included file COPYING for details.
|
1
4
|
# = RafObject
|
2
5
|
module Raf
|
3
6
|
class HeadIndex
|
@@ -18,7 +21,7 @@ module Raf
|
|
18
21
|
@head_index[point] += 1
|
19
22
|
@point_pre = point
|
20
23
|
end
|
21
|
-
|
24
|
+
|
22
25
|
def to_s
|
23
26
|
@head_index.map{|n|
|
24
27
|
n = 0 if n.nil?
|
@@ -33,8 +36,8 @@ module Raf
|
|
33
36
|
end
|
34
37
|
module Raf
|
35
38
|
class Element
|
36
|
-
def initialize(contents =
|
37
|
-
@contents = contents
|
39
|
+
def initialize(contents = "")
|
40
|
+
@contents = Array(contents)
|
38
41
|
end
|
39
42
|
attr_reader :contents
|
40
43
|
|
@@ -42,7 +45,7 @@ module Raf
|
|
42
45
|
@contents
|
43
46
|
end
|
44
47
|
def add=(content)
|
45
|
-
@contents.concat(content.
|
48
|
+
@contents.concat(content.lines)
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -52,20 +55,20 @@ module Raf
|
|
52
55
|
""
|
53
56
|
end
|
54
57
|
end
|
55
|
-
|
58
|
+
|
56
59
|
class PlainTextBlock < Element
|
57
60
|
def apply
|
58
61
|
@contents.map {|c| c.apply }
|
59
62
|
end
|
60
63
|
end
|
61
|
-
|
64
|
+
|
62
65
|
class HeadLine < Element
|
63
66
|
# @contents = [level, title]
|
64
67
|
def apply
|
65
68
|
"=" * @contents[0] + " #{@contents[1]}\n"
|
66
69
|
end
|
67
70
|
end
|
68
|
-
|
71
|
+
|
69
72
|
class Paragraph < Element
|
70
73
|
def apply
|
71
74
|
"#{@contents.map{|c| c.apply}}"
|
@@ -77,7 +80,7 @@ module Raf
|
|
77
80
|
"#{@contents}"
|
78
81
|
end
|
79
82
|
end
|
80
|
-
|
83
|
+
|
81
84
|
class ItemList < Element
|
82
85
|
def apply
|
83
86
|
str = "<ItemList>"
|
@@ -87,11 +90,11 @@ module Raf
|
|
87
90
|
elsif c == :DEDENT
|
88
91
|
str +="<DEDENT/>"
|
89
92
|
else
|
90
|
-
str += "<ItemListItem>#{c.apply}</ItemListItem>"
|
93
|
+
str += "<ItemListItem>#{c.apply}</ItemListItem>"
|
91
94
|
end
|
92
95
|
end
|
93
96
|
str += "</ItemList>"
|
94
|
-
str
|
97
|
+
str
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
@@ -106,11 +109,11 @@ module Raf
|
|
106
109
|
str +="<DEDENT/>"
|
107
110
|
else
|
108
111
|
str += "<NumListItem>#{num}. #{c.apply}</NumListItem>"
|
109
|
-
num += 1
|
112
|
+
num += 1
|
110
113
|
end
|
111
114
|
end
|
112
115
|
str += "</NumList>"
|
113
|
-
str
|
116
|
+
str
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
@@ -128,17 +131,17 @@ module Raf
|
|
128
131
|
if item.split(//)[0] == "*"
|
129
132
|
str += "|*#{item.sub(/^\*/, "").sub(/\*$/,"")}"
|
130
133
|
else
|
131
|
-
str += "|#{item}"
|
134
|
+
str += "|#{item}"
|
132
135
|
end
|
133
136
|
end
|
134
|
-
str += "\n"
|
137
|
+
str += "\n"
|
135
138
|
end
|
136
139
|
str
|
137
140
|
end
|
138
141
|
end
|
139
|
-
|
142
|
+
|
140
143
|
# -- Blocks end
|
141
|
-
|
144
|
+
|
142
145
|
# -- Inlines
|
143
146
|
class Plain < Element
|
144
147
|
def apply
|
@@ -153,38 +156,38 @@ module Raf
|
|
153
156
|
"#{@contents[1]}(#{@contents[0]}):#{@contents[2]}"
|
154
157
|
end
|
155
158
|
end
|
156
|
-
|
159
|
+
|
157
160
|
class Reference < Element
|
158
161
|
# @contents = [title, uri]
|
159
162
|
def apply
|
160
163
|
"#{@contents}"
|
161
164
|
end
|
162
165
|
end
|
163
|
-
|
166
|
+
|
164
167
|
class Emphasis < Element
|
165
168
|
def apply
|
166
169
|
"<Emphasis>#{@contents.map{|c| c.apply}}</Emphasis>"
|
167
170
|
end
|
168
171
|
end
|
169
|
-
|
172
|
+
|
170
173
|
class Italic < Element
|
171
174
|
def apply
|
172
175
|
"<Italic>#{@contents.map{|c| c.apply}}</Italic>"
|
173
176
|
end
|
174
177
|
end
|
175
|
-
|
178
|
+
|
176
179
|
class Strike < Element
|
177
180
|
def apply
|
178
181
|
"<Strike>#{@contents.map{|c| c.apply}}</Strike>"
|
179
182
|
end
|
180
183
|
end
|
181
|
-
|
184
|
+
|
182
185
|
class Ruby < Element
|
183
186
|
def apply
|
184
187
|
"<Ruby>Base:#{@contents[0]},Text:#{@contents[1]}</Ruby>"
|
185
188
|
end
|
186
189
|
end
|
187
|
-
|
190
|
+
|
188
191
|
class Footnote < Element
|
189
192
|
#@contents = [contents, id]
|
190
193
|
def apply
|
@@ -197,7 +200,7 @@ module Raf
|
|
197
200
|
"<Image>#{@contents}</Image>"
|
198
201
|
end
|
199
202
|
end
|
200
|
-
|
203
|
+
|
201
204
|
class Verb < Element
|
202
205
|
def apply
|
203
206
|
"<Verb>#{@contents}</Verb>"
|
@@ -214,6 +217,13 @@ end
|
|
214
217
|
|
215
218
|
class String
|
216
219
|
def to_code
|
217
|
-
self.to_a.pack('m').tr("012345679+/=\n", 'abcdefghiPSIQ').strip
|
220
|
+
self.lines.to_a.pack('m').tr("012345679+/=\n", 'abcdefghiPSIQ').strip
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# support for ruby-2.0.0
|
225
|
+
class Array
|
226
|
+
def to_s
|
227
|
+
self.join
|
218
228
|
end
|
219
229
|
end
|
data/lib/rafinlineparser.ry
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright (C) garin <garin54@gmail.com> 2011
|
2
|
+
# See the included file COPYING for details.
|
1
3
|
class InlineParser
|
2
4
|
token EM_OPEN EM_CLOSE ITALIC_OPEN ITALIC_CLOSE STRIKE_OPEN STRIKE_CLOSE LABEL_OPEN LABEL_CLOSE REFERENCE_OPEN REFERENCE_CLOSE VERB_OPEN VERB_CLOSE ERB_OPEN ERB_CLOSE FOOTNOTE_OPEN FOOTNOTE_CLOSE RUBY_OPEN RUBY_CLOSE IMAGE_OPEN IMAGE_CLOSE MANUEDO_OPEN MANUEDO_CLOSE BAR QUOTE SLASH BACK_SLASH OTHER
|
3
5
|
options no_result_var
|
@@ -63,7 +65,7 @@ class InlineParser
|
|
63
65
|
| VERB_CLOSE
|
64
66
|
| IMAGE_OPEN
|
65
67
|
|
66
|
-
image_strings : image_strings image_string { val.
|
68
|
+
image_strings : image_strings image_string { val.join }
|
67
69
|
| image_string { val[0] }
|
68
70
|
image : IMAGE_OPEN image_strings IMAGE_CLOSE { Image.new(val[1]) }
|
69
71
|
|
@@ -96,7 +98,7 @@ class InlineParser
|
|
96
98
|
| VERB_OPEN
|
97
99
|
| VERB_CLOSE
|
98
100
|
|
99
|
-
ruby_strings : ruby_strings ruby_string { val.
|
101
|
+
ruby_strings : ruby_strings ruby_string { val.join }
|
100
102
|
| ruby_string { val[0] }
|
101
103
|
|
102
104
|
ruby : RUBY_OPEN ruby_strings RUBY_CLOSE {
|
@@ -123,7 +125,7 @@ class InlineParser
|
|
123
125
|
| SLASH { val[0] }
|
124
126
|
| BACK_SLASH { val[0] }
|
125
127
|
|
126
|
-
label_strings : label_strings label_string { val.
|
128
|
+
label_strings : label_strings label_string { val.join }
|
127
129
|
| label_string { val[0] }
|
128
130
|
|
129
131
|
label : LABEL_OPEN label_strings LABEL_CLOSE {
|
@@ -142,7 +144,7 @@ class InlineParser
|
|
142
144
|
| SLASH { val[0] }
|
143
145
|
| BACK_SLASH { val[0] }
|
144
146
|
|
145
|
-
reference_strings : reference_strings reference_string { val.
|
147
|
+
reference_strings : reference_strings reference_string { val.join }
|
146
148
|
| reference_string { val[0] }
|
147
149
|
|
148
150
|
reference : REFERENCE_OPEN reference_strings REFERENCE_CLOSE {
|
@@ -262,9 +264,9 @@ MANUEDO_OPEN_RE = /\A#{Regexp.quote(MANUEDO_OPEN)}/
|
|
262
264
|
MANUEDO_CLOSE = "/))"
|
263
265
|
MANUEDO_CLOSE_RE = /\A#{Regexp.quote(MANUEDO_CLOSE)}/
|
264
266
|
|
265
|
-
ERB_OPEN = "
|
267
|
+
ERB_OPEN = "<%="
|
266
268
|
ERB_OPEN_RE = /\A#{Regexp.quote(ERB_OPEN)}/
|
267
|
-
ERB_CLOSE = "
|
269
|
+
ERB_CLOSE = "%>"
|
268
270
|
ERB_CLOSE_RE = /\A#{Regexp.quote(ERB_CLOSE)}/
|
269
271
|
|
270
272
|
BAR = "|"
|
@@ -285,9 +287,9 @@ OTHER_RE = Regexp.new(
|
|
285
287
|
|
286
288
|
|
287
289
|
def parse(src)
|
288
|
-
@src = StringScanner.new(src.
|
290
|
+
@src = StringScanner.new(Array(src).join)
|
289
291
|
@pre = ""
|
290
|
-
@@yydebug =
|
292
|
+
@@yydebug = false
|
291
293
|
@view_token_type = false
|
292
294
|
do_parse
|
293
295
|
end
|