ebnf 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # EBNF
1
+ # EBNF [![Build Status](https://secure.travis-ci.org/gkellogg/ebnf.png?branch=master)](http://travis-ci.org/gkellogg/ebnf)
2
+
2
3
 
3
4
  [EBNF][] parser and generic parser generator.
4
5
 
@@ -46,16 +47,20 @@ to each `terminal` and `production`. A trivial parser loop can be described as f
46
47
  class Parser
47
48
  include Meta
48
49
 
49
- terminal(:SYMBOL, /([a-z]|[A-Z]|[0-9]|_)+/) do |parser, prod, token, input|
50
+ terminal(:SYMBOL, /([a-z]|[A-Z]|[0-9]|_)+/) do |prod, token, input|
50
51
  # Add data based on scanned token to input
51
52
  input[:symbol] = token.value
52
53
  end
53
54
 
54
- production(:rule) do |parser, phase, input, current, callback|
55
- # Process on start of production when phase == :start
55
+ start_production(:rule) do |input, current, callback|
56
+ # Process on start of production
56
57
  # Set state for entry into recursed rules through current
57
58
 
58
- # Process on end of production when phase == :finish
59
+ # Callback to parser loop with callback
60
+ end
61
+
62
+ production(:rule) do |input, current, callback|
63
+ # Process on end of production
59
64
  # return results in input, retrieve results from recursed rules in current
60
65
 
61
66
  # Callback to parser loop with callback
@@ -134,7 +139,7 @@ The [EBNF][] variant used here is based on [W3C][] [EBNF][] as defined in the
134
139
  |
135
140
  )+
136
141
 
137
- # # Acknowledgements
142
+ ## Acknowledgements
138
143
  Much of this work, particularly the generic parser, is inspired by work originally done by
139
144
  Tim Berners-Lee's Python [predictive parser](http://www.w3.org/2000/10/swap/grammar/predictiveParser.py).
140
145
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/etc/ebnf.ll1 CHANGED
@@ -1,189 +1,36 @@
1
- ((rule
2
- _empty
3
- "0"
4
- (first _eps)
5
- (follow
6
- "("
7
- ")"
8
- "-"
9
- "@pass"
10
- "@terminals"
11
- ENUM
12
- HEX
13
- O_ENUM
14
- O_RANGE
15
- RANGE
16
- STRING1
17
- STRING2
18
- "["
19
- _eof
20
- "|"
21
- )
22
- (seq)
23
- )
1
+ ((rule _empty "0" (first _eps)
2
+ (follow "(" ")" "-" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2 "[" _eof "|")
3
+ (seq))
24
4
  (pass @pass "0" (seq ()))
25
- (rule
26
- ebnf
27
- "1"
28
- (start #t)
29
- (first
30
- "("
31
- "@pass"
32
- "@terminals"
33
- ENUM
34
- HEX
35
- O_ENUM
36
- O_RANGE
37
- RANGE
38
- STRING1
39
- STRING2
40
- "["
41
- _eps
42
- )
43
- (follow _eof)
44
- (alt _empty _ebnf_star)
45
- )
46
- (rule
47
- _ebnf_star
48
- "1*"
49
- (first
50
- "("
51
- "@pass"
52
- "@terminals"
53
- ENUM
54
- HEX
55
- O_ENUM
56
- O_RANGE
57
- RANGE
58
- STRING1
59
- STRING2
60
- "["
61
- )
62
- (follow _eof)
63
- (seq _ebnf_1 ebnf)
64
- )
65
- (rule
66
- __ebnf_star_comp
67
- "1*.comp"
68
- (first
69
- "("
70
- "@pass"
71
- "@terminals"
72
- ENUM
73
- HEX
74
- O_ENUM
75
- O_RANGE
76
- RANGE
77
- STRING1
78
- STRING2
79
- "["
80
- _eps
81
- )
82
- (follow _eof)
83
- (seq ebnf)
84
- )
85
- (rule
86
- _ebnf_1
87
- "1.1"
88
- (first
89
- "("
90
- "@pass"
91
- "@terminals"
92
- ENUM
93
- HEX
94
- O_ENUM
95
- O_RANGE
96
- RANGE
97
- STRING1
98
- STRING2
99
- "["
100
- )
101
- (follow
102
- "("
103
- "@pass"
104
- "@terminals"
105
- ENUM
106
- HEX
107
- O_ENUM
108
- O_RANGE
109
- RANGE
110
- STRING1
111
- STRING2
112
- "["
113
- )
114
- (alt declaration rule)
115
- )
116
- (rule
117
- declaration
118
- "2"
119
- (first
120
- "("
121
- "@pass"
122
- "@terminals"
123
- ENUM
124
- HEX
125
- O_ENUM
126
- O_RANGE
127
- RANGE
128
- STRING1
129
- STRING2
130
- )
131
- (follow
132
- "("
133
- "@pass"
134
- "@terminals"
135
- ENUM
136
- HEX
137
- O_ENUM
138
- O_RANGE
139
- RANGE
140
- STRING1
141
- STRING2
142
- "["
143
- )
144
- (alt "@terminals" "@pass")
145
- )
146
- (rule
147
- rule
148
- "3"
149
- (first "[")
150
- (follow
151
- "("
152
- "@pass"
153
- "@terminals"
154
- ENUM
155
- HEX
156
- O_ENUM
157
- O_RANGE
158
- RANGE
159
- STRING1
160
- STRING2
161
- "["
162
- )
163
- (seq lhs "::=" expression)
164
- )
165
- (rule
166
- _rule_comp
167
- "3.comp"
168
- (first "::=")
169
- (follow
170
- "("
171
- "@pass"
172
- "@terminals"
173
- ENUM
174
- HEX
175
- O_ENUM
176
- O_RANGE
177
- RANGE
178
- STRING1
179
- STRING2
180
- "["
181
- )
182
- (seq "::=" expression)
183
- )
184
- (rule
185
- __rule_comp_comp
186
- "3.comp.comp"
5
+ (rule ebnf "1" (start #t)
6
+ (first "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1STRING2 "[" _eps)
7
+ (follow _eof) (alt _empty _ebnf_2))
8
+ (rule _ebnf_1 "1.1"
9
+ (first "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2 "[")
10
+ (follow "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2 "[")
11
+ (alt declaration rule))
12
+ (rule _ebnf_2 "1.2"
13
+ (first "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2 "[")
14
+ (follow _eof) (seq _ebnf_1 ebnf))
15
+ (rule _ebnf_3 "1.3"
16
+ (first "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2 "[" _eps)
17
+ (follow _eof) (seq ebnf))
18
+ (rule declaration "2"
19
+ (first "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2 )
20
+ (follow "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2
21
+ "[" )
22
+ (alt "@terminals" "@pass"))
23
+ (rule rule "3" (first "[")
24
+ (follow "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2
25
+ "[" )
26
+ (seq lhs "::=" expression))
27
+ (rule _rule_1 "3.1" (first "::=")
28
+ (follow "(" "@pass" "@terminals" ENUM HEX O_ENUM O_RANGE RANGE STRING1 STRING2
29
+ "[" )
30
+ (seq "::=" expression))
31
+ (rule
32
+ _rule_2
33
+ "3.2"
187
34
  (first
188
35
  "("
189
36
  ENUM
@@ -217,22 +64,22 @@
217
64
  (seq "[" SYMBOL "]" SYMBOL)
218
65
  )
219
66
  (rule
220
- _lhs_comp
221
- "4.comp"
67
+ _lhs_1
68
+ "4.1"
222
69
  (first SYMBOL)
223
70
  (follow "::=")
224
71
  (seq SYMBOL "]" SYMBOL)
225
72
  )
226
73
  (rule
227
- __lhs_comp_comp
228
- "4.comp.comp"
74
+ _lhs_2
75
+ "4.2"
229
76
  (first "]")
230
77
  (follow "::=")
231
78
  (seq "]" SYMBOL)
232
79
  )
233
80
  (rule
234
- ___lhs_comp_comp_comp
235
- "4.comp.comp.comp"
81
+ _lhs_3
82
+ "4.3"
236
83
  (first SYMBOL)
237
84
  (follow "::=")
238
85
  (seq SYMBOL)
@@ -324,11 +171,28 @@
324
171
  STRING2
325
172
  "["
326
173
  )
327
- (alt _empty __alt_1_star)
174
+ (alt _empty _alt_3)
328
175
  )
329
176
  (rule
330
- __alt_1_star
331
- "6.1*"
177
+ _alt_2
178
+ "6.2"
179
+ (first "|")
180
+ (follow
181
+ "("
182
+ ENUM
183
+ HEX
184
+ O_ENUM
185
+ O_RANGE
186
+ RANGE
187
+ STRING1
188
+ STRING2
189
+ "|"
190
+ )
191
+ (seq "|" seq)
192
+ )
193
+ (rule
194
+ _alt_3
195
+ "6.3"
332
196
  (first "|")
333
197
  (follow
334
198
  "("
@@ -344,11 +208,11 @@
344
208
  STRING2
345
209
  "["
346
210
  )
347
- (seq __alt_1_1 _alt_1)
211
+ (seq _alt_2 _alt_1)
348
212
  )
349
213
  (rule
350
- ___alt_1_star_comp
351
- "6.1*.comp"
214
+ _alt_4
215
+ "6.4"
352
216
  (first
353
217
  "("
354
218
  ENUM
@@ -378,25 +242,8 @@
378
242
  (seq _alt_1)
379
243
  )
380
244
  (rule
381
- __alt_1_1
382
- "6.1.1"
383
- (first "|")
384
- (follow
385
- "("
386
- ENUM
387
- HEX
388
- O_ENUM
389
- O_RANGE
390
- RANGE
391
- STRING1
392
- STRING2
393
- "|"
394
- )
395
- (seq "|" seq)
396
- )
397
- (rule
398
- ___alt_1_1_comp
399
- "6.1.1.comp"
245
+ _alt_5
246
+ "6.5"
400
247
  (first
401
248
  "("
402
249
  ENUM
@@ -406,9 +253,14 @@
406
253
  RANGE
407
254
  STRING1
408
255
  STRING2
256
+ _eps
257
+ "|"
409
258
  )
410
259
  (follow
411
260
  "("
261
+ ")"
262
+ "@pass"
263
+ "@terminals"
412
264
  ENUM
413
265
  HEX
414
266
  O_ENUM
@@ -416,13 +268,13 @@
416
268
  RANGE
417
269
  STRING1
418
270
  STRING2
419
- "|"
271
+ "["
420
272
  )
421
- (seq seq)
273
+ (seq _alt_1)
422
274
  )
423
275
  (rule
424
- _alt_comp
425
- "6.comp"
276
+ _alt_6
277
+ "6.6"
426
278
  (first
427
279
  "("
428
280
  ENUM
@@ -432,14 +284,9 @@
432
284
  RANGE
433
285
  STRING1
434
286
  STRING2
435
- _eps
436
- "|"
437
287
  )
438
288
  (follow
439
289
  "("
440
- ")"
441
- "@pass"
442
- "@terminals"
443
290
  ENUM
444
291
  HEX
445
292
  O_ENUM
@@ -447,9 +294,9 @@
447
294
  RANGE
448
295
  STRING1
449
296
  STRING2
450
- "["
297
+ "|"
451
298
  )
452
- (seq _alt_1)
299
+ (seq seq)
453
300
  )
454
301
  (rule
455
302
  seq
@@ -514,11 +361,11 @@
514
361
  _eof
515
362
  "|"
516
363
  )
517
- (alt _empty __seq_1_star)
364
+ (alt _empty _seq_2)
518
365
  )
519
366
  (rule
520
- __seq_1_star
521
- "7.1*"
367
+ _seq_2
368
+ "7.2"
522
369
  (first
523
370
  "("
524
371
  ENUM
@@ -549,8 +396,8 @@
549
396
  (seq diff _seq_1)
550
397
  )
551
398
  (rule
552
- ___seq_1_star_comp
553
- "7.1*.comp"
399
+ _seq_3
400
+ "7.3"
554
401
  (first
555
402
  "("
556
403
  ENUM
@@ -582,8 +429,8 @@
582
429
  (seq _seq_1)
583
430
  )
584
431
  (rule
585
- _seq_comp
586
- "7.comp"
432
+ _seq_4
433
+ "7.4"
587
434
  (first
588
435
  "("
589
436
  ENUM
@@ -664,14 +511,15 @@
664
511
  STRING1
665
512
  STRING2
666
513
  )
667
- (alt _empty __diff_1_star)
514
+ (alt _empty _diff_3)
668
515
  )
669
516
  (rule
670
- __diff_1_star
671
- "8.1*"
517
+ _diff_2
518
+ "8.2"
672
519
  (first "-")
673
520
  (follow
674
521
  "("
522
+ "-"
675
523
  ENUM
676
524
  HEX
677
525
  O_ENUM
@@ -680,14 +528,14 @@
680
528
  STRING1
681
529
  STRING2
682
530
  )
683
- (seq __diff_1_1 _diff_1)
531
+ (seq "-" postfix)
684
532
  )
685
533
  (rule
686
- ___diff_1_star_comp
687
- "8.1*.comp"
688
- (first
534
+ _diff_3
535
+ "8.3"
536
+ (first "-")
537
+ (follow
689
538
  "("
690
- "-"
691
539
  ENUM
692
540
  HEX
693
541
  O_ENUM
@@ -695,10 +543,15 @@
695
543
  RANGE
696
544
  STRING1
697
545
  STRING2
698
- _eps
699
546
  )
700
- (follow
547
+ (seq _diff_2 _diff_1)
548
+ )
549
+ (rule
550
+ _diff_4
551
+ "8.4"
552
+ (first
701
553
  "("
554
+ "-"
702
555
  ENUM
703
556
  HEX
704
557
  O_ENUM
@@ -706,16 +559,10 @@
706
559
  RANGE
707
560
  STRING1
708
561
  STRING2
562
+ _eps
709
563
  )
710
- (seq _diff_1)
711
- )
712
- (rule
713
- __diff_1_1
714
- "8.1.1"
715
- (first "-")
716
564
  (follow
717
565
  "("
718
- "-"
719
566
  ENUM
720
567
  HEX
721
568
  O_ENUM
@@ -724,13 +571,14 @@
724
571
  STRING1
725
572
  STRING2
726
573
  )
727
- (seq "-" postfix)
574
+ (seq _diff_1)
728
575
  )
729
576
  (rule
730
- ___diff_1_1_comp
731
- "8.1.1.comp"
577
+ _diff_5
578
+ "8.5"
732
579
  (first
733
580
  "("
581
+ "-"
734
582
  ENUM
735
583
  HEX
736
584
  O_ENUM
@@ -738,10 +586,10 @@
738
586
  RANGE
739
587
  STRING1
740
588
  STRING2
589
+ _eps
741
590
  )
742
591
  (follow
743
592
  "("
744
- "-"
745
593
  ENUM
746
594
  HEX
747
595
  O_ENUM
@@ -750,14 +598,13 @@
750
598
  STRING1
751
599
  STRING2
752
600
  )
753
- (seq postfix)
601
+ (seq _diff_1)
754
602
  )
755
603
  (rule
756
- _diff_comp
757
- "8.comp"
604
+ _diff_6
605
+ "8.6"
758
606
  (first
759
607
  "("
760
- "-"
761
608
  ENUM
762
609
  HEX
763
610
  O_ENUM
@@ -765,10 +612,10 @@
765
612
  RANGE
766
613
  STRING1
767
614
  STRING2
768
- _eps
769
615
  )
770
616
  (follow
771
617
  "("
618
+ "-"
772
619
  ENUM
773
620
  HEX
774
621
  O_ENUM
@@ -777,7 +624,7 @@
777
624
  STRING1
778
625
  STRING2
779
626
  )
780
- (seq _diff_1)
627
+ (seq postfix)
781
628
  )
782
629
  (rule
783
630
  postfix
@@ -818,6 +665,7 @@
818
665
  STRING1
819
666
  STRING2
820
667
  _eps
668
+ _postfix_2
821
669
  )
822
670
  (follow
823
671
  "("
@@ -830,11 +678,12 @@
830
678
  STRING1
831
679
  STRING2
832
680
  )
833
- (alt _empty (range "?*+"))
681
+ (alt _empty _postfix_2)
834
682
  )
683
+ (terminal _postfix_2 "9.2" (range "?*+"))
835
684
  (rule
836
- _postfix_comp
837
- "9.comp"
685
+ _postfix_3
686
+ "9.3"
838
687
  (first
839
688
  "("
840
689
  ENUM
@@ -845,6 +694,7 @@
845
694
  STRING1
846
695
  STRING2
847
696
  _eps
697
+ _postfix_2
848
698
  )
849
699
  (follow
850
700
  "("
@@ -881,6 +731,7 @@
881
731
  RANGE
882
732
  STRING1
883
733
  STRING2
734
+ _postfix_2
884
735
  )
885
736
  (alt
886
737
  HEX
@@ -906,12 +757,13 @@
906
757
  RANGE
907
758
  STRING1
908
759
  STRING2
760
+ _postfix_2
909
761
  )
910
762
  (seq "(" expression ")")
911
763
  )
912
764
  (rule
913
- __primary_1_comp
914
- "10.1.comp"
765
+ _primary_2
766
+ "10.2"
915
767
  (first
916
768
  "("
917
769
  ENUM
@@ -931,12 +783,13 @@
931
783
  RANGE
932
784
  STRING1
933
785
  STRING2
786
+ _postfix_2
934
787
  )
935
788
  (seq expression ")")
936
789
  )
937
790
  (rule
938
- ___primary_1_comp_comp
939
- "10.1.comp.comp"
791
+ _primary_3
792
+ "10.3"
940
793
  (first ")")
941
794
  (follow
942
795
  "("
@@ -947,6 +800,7 @@
947
800
  RANGE
948
801
  STRING1
949
802
  STRING2
803
+ _postfix_2
950
804
  )
951
805
  (seq ")")
952
806
  )