ebnf 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/ebnf +2 -1
- data/etc/ebnf.ebnf +19 -19
- data/etc/ebnf.html +214 -0
- data/etc/ebnf.ll1.sxp +57 -58
- data/etc/ebnf.rb +0 -76
- data/etc/ebnf.sxp +18 -19
- data/lib/ebnf/base.rb +7 -0
- data/lib/ebnf/ll1/scanner.rb +17 -1
- data/lib/ebnf/parser.rb +10 -7
- data/lib/ebnf/rule.rb +5 -2
- data/lib/ebnf/writer.rb +120 -23
- metadata +56 -35
data/etc/ebnf.rb
CHANGED
@@ -6,9 +6,7 @@ module Branch
|
|
6
6
|
BRANCH = {
|
7
7
|
:alt => {
|
8
8
|
"(" => [:seq, :_alt_1],
|
9
|
-
:ENUM => [:seq, :_alt_1],
|
10
9
|
:HEX => [:seq, :_alt_1],
|
11
|
-
:O_ENUM => [:seq, :_alt_1],
|
12
10
|
:O_RANGE => [:seq, :_alt_1],
|
13
11
|
:RANGE => [:seq, :_alt_1],
|
14
12
|
:STRING1 => [:seq, :_alt_1],
|
@@ -34,9 +32,7 @@ module Branch
|
|
34
32
|
},
|
35
33
|
:diff => {
|
36
34
|
"(" => [:postfix, :_diff_1],
|
37
|
-
:ENUM => [:postfix, :_diff_1],
|
38
35
|
:HEX => [:postfix, :_diff_1],
|
39
|
-
:O_ENUM => [:postfix, :_diff_1],
|
40
36
|
:O_RANGE => [:postfix, :_diff_1],
|
41
37
|
:RANGE => [:postfix, :_diff_1],
|
42
38
|
:STRING1 => [:postfix, :_diff_1],
|
@@ -49,10 +45,8 @@ module Branch
|
|
49
45
|
"-" => [:_diff_2],
|
50
46
|
"@pass" => [],
|
51
47
|
"@terminals" => [],
|
52
|
-
:ENUM => [],
|
53
48
|
:HEX => [],
|
54
49
|
:LHS => [],
|
55
|
-
:O_ENUM => [],
|
56
50
|
:O_RANGE => [],
|
57
51
|
:RANGE => [],
|
58
52
|
:STRING1 => [],
|
@@ -80,9 +74,7 @@ module Branch
|
|
80
74
|
},
|
81
75
|
:expression => {
|
82
76
|
"(" => [:alt],
|
83
|
-
:ENUM => [:alt],
|
84
77
|
:HEX => [:alt],
|
85
|
-
:O_ENUM => [:alt],
|
86
78
|
:O_RANGE => [:alt],
|
87
79
|
:RANGE => [:alt],
|
88
80
|
:STRING1 => [:alt],
|
@@ -94,9 +86,7 @@ module Branch
|
|
94
86
|
},
|
95
87
|
:postfix => {
|
96
88
|
"(" => [:primary, :_postfix_1],
|
97
|
-
:ENUM => [:primary, :_postfix_1],
|
98
89
|
:HEX => [:primary, :_postfix_1],
|
99
|
-
:O_ENUM => [:primary, :_postfix_1],
|
100
90
|
:O_RANGE => [:primary, :_postfix_1],
|
101
91
|
:RANGE => [:primary, :_postfix_1],
|
102
92
|
:STRING1 => [:primary, :_postfix_1],
|
@@ -109,10 +99,8 @@ module Branch
|
|
109
99
|
"-" => [],
|
110
100
|
"@pass" => [],
|
111
101
|
"@terminals" => [],
|
112
|
-
:ENUM => [],
|
113
102
|
:HEX => [],
|
114
103
|
:LHS => [],
|
115
|
-
:O_ENUM => [],
|
116
104
|
:O_RANGE => [],
|
117
105
|
:POSTFIX => [:POSTFIX],
|
118
106
|
:RANGE => [],
|
@@ -123,9 +111,7 @@ module Branch
|
|
123
111
|
},
|
124
112
|
:primary => {
|
125
113
|
"(" => [:_primary_1],
|
126
|
-
:ENUM => [:ENUM],
|
127
114
|
:HEX => [:HEX],
|
128
|
-
:O_ENUM => [:O_ENUM],
|
129
115
|
:O_RANGE => [:O_RANGE],
|
130
116
|
:RANGE => [:RANGE],
|
131
117
|
:STRING1 => [:STRING1],
|
@@ -140,9 +126,7 @@ module Branch
|
|
140
126
|
},
|
141
127
|
:seq => {
|
142
128
|
"(" => [:diff, :_seq_1],
|
143
|
-
:ENUM => [:diff, :_seq_1],
|
144
129
|
:HEX => [:diff, :_seq_1],
|
145
|
-
:O_ENUM => [:diff, :_seq_1],
|
146
130
|
:O_RANGE => [:diff, :_seq_1],
|
147
131
|
:RANGE => [:diff, :_seq_1],
|
148
132
|
:STRING1 => [:diff, :_seq_1],
|
@@ -154,10 +138,8 @@ module Branch
|
|
154
138
|
")" => [],
|
155
139
|
"@pass" => [],
|
156
140
|
"@terminals" => [],
|
157
|
-
:ENUM => [:_seq_2],
|
158
141
|
:HEX => [:_seq_2],
|
159
142
|
:LHS => [],
|
160
|
-
:O_ENUM => [:_seq_2],
|
161
143
|
:O_RANGE => [:_seq_2],
|
162
144
|
:RANGE => [:_seq_2],
|
163
145
|
:STRING1 => [:_seq_2],
|
@@ -167,9 +149,7 @@ module Branch
|
|
167
149
|
},
|
168
150
|
:_seq_2 => {
|
169
151
|
"(" => [:diff, :_seq_1],
|
170
|
-
:ENUM => [:diff, :_seq_1],
|
171
152
|
:HEX => [:diff, :_seq_1],
|
172
|
-
:O_ENUM => [:diff, :_seq_1],
|
173
153
|
:O_RANGE => [:diff, :_seq_1],
|
174
154
|
:RANGE => [:diff, :_seq_1],
|
175
155
|
:STRING1 => [:diff, :_seq_1],
|
@@ -183,10 +163,8 @@ module Branch
|
|
183
163
|
"-",
|
184
164
|
"@pass",
|
185
165
|
"@terminals",
|
186
|
-
:ENUM,
|
187
166
|
:HEX,
|
188
167
|
:LHS,
|
189
|
-
:O_ENUM,
|
190
168
|
:O_RANGE,
|
191
169
|
:POSTFIX,
|
192
170
|
:RANGE,
|
@@ -200,9 +178,7 @@ module Branch
|
|
200
178
|
:HEX,
|
201
179
|
:SYMBOL,
|
202
180
|
:RANGE,
|
203
|
-
:ENUM,
|
204
181
|
:O_RANGE,
|
205
|
-
:O_ENUM,
|
206
182
|
:STRING1,
|
207
183
|
:STRING2,
|
208
184
|
"("],
|
@@ -223,9 +199,7 @@ module Branch
|
|
223
199
|
:HEX,
|
224
200
|
:SYMBOL,
|
225
201
|
:RANGE,
|
226
|
-
:ENUM,
|
227
202
|
:O_RANGE,
|
228
|
-
:O_ENUM,
|
229
203
|
:STRING1,
|
230
204
|
:STRING2,
|
231
205
|
"("],
|
@@ -236,9 +210,7 @@ module Branch
|
|
236
210
|
:HEX,
|
237
211
|
:SYMBOL,
|
238
212
|
:RANGE,
|
239
|
-
:ENUM,
|
240
213
|
:O_RANGE,
|
241
|
-
:O_ENUM,
|
242
214
|
:STRING1,
|
243
215
|
:STRING2,
|
244
216
|
"("],
|
@@ -254,9 +226,7 @@ module Branch
|
|
254
226
|
:HEX,
|
255
227
|
:SYMBOL,
|
256
228
|
:RANGE,
|
257
|
-
:ENUM,
|
258
229
|
:O_RANGE,
|
259
|
-
:O_ENUM,
|
260
230
|
:STRING1,
|
261
231
|
:STRING2,
|
262
232
|
"("],
|
@@ -284,9 +254,7 @@ module Branch
|
|
284
254
|
:HEX,
|
285
255
|
:SYMBOL,
|
286
256
|
:RANGE,
|
287
|
-
:ENUM,
|
288
257
|
:O_RANGE,
|
289
|
-
:O_ENUM,
|
290
258
|
:STRING1,
|
291
259
|
:STRING2,
|
292
260
|
"("],
|
@@ -296,9 +264,7 @@ module Branch
|
|
296
264
|
:HEX,
|
297
265
|
:SYMBOL,
|
298
266
|
:RANGE,
|
299
|
-
:ENUM,
|
300
267
|
:O_RANGE,
|
301
|
-
:O_ENUM,
|
302
268
|
:STRING1,
|
303
269
|
:STRING2,
|
304
270
|
"("],
|
@@ -306,9 +272,7 @@ module Branch
|
|
306
272
|
:HEX,
|
307
273
|
:SYMBOL,
|
308
274
|
:RANGE,
|
309
|
-
:ENUM,
|
310
275
|
:O_RANGE,
|
311
|
-
:O_ENUM,
|
312
276
|
:STRING1,
|
313
277
|
:STRING2,
|
314
278
|
"("],
|
@@ -322,9 +286,7 @@ module Branch
|
|
322
286
|
:HEX,
|
323
287
|
:SYMBOL,
|
324
288
|
:RANGE,
|
325
|
-
:ENUM,
|
326
289
|
:O_RANGE,
|
327
|
-
:O_ENUM,
|
328
290
|
:STRING1,
|
329
291
|
:STRING2,
|
330
292
|
"("],
|
@@ -334,9 +296,7 @@ module Branch
|
|
334
296
|
:HEX,
|
335
297
|
:SYMBOL,
|
336
298
|
:RANGE,
|
337
|
-
:ENUM,
|
338
299
|
:O_RANGE,
|
339
|
-
:O_ENUM,
|
340
300
|
:STRING1,
|
341
301
|
:STRING2,
|
342
302
|
"("],
|
@@ -348,9 +308,7 @@ module Branch
|
|
348
308
|
:HEX,
|
349
309
|
:SYMBOL,
|
350
310
|
:RANGE,
|
351
|
-
:ENUM,
|
352
311
|
:O_RANGE,
|
353
|
-
:O_ENUM,
|
354
312
|
:STRING1,
|
355
313
|
:STRING2,
|
356
314
|
"("],
|
@@ -358,9 +316,7 @@ module Branch
|
|
358
316
|
:HEX,
|
359
317
|
:SYMBOL,
|
360
318
|
:RANGE,
|
361
|
-
:ENUM,
|
362
319
|
:O_RANGE,
|
363
|
-
:O_ENUM,
|
364
320
|
:STRING1,
|
365
321
|
:STRING2,
|
366
322
|
"("],
|
@@ -369,9 +325,7 @@ module Branch
|
|
369
325
|
:HEX,
|
370
326
|
:SYMBOL,
|
371
327
|
:RANGE,
|
372
|
-
:ENUM,
|
373
328
|
:O_RANGE,
|
374
|
-
:O_ENUM,
|
375
329
|
:STRING1,
|
376
330
|
:STRING2,
|
377
331
|
"("],
|
@@ -379,9 +333,7 @@ module Branch
|
|
379
333
|
:HEX,
|
380
334
|
:SYMBOL,
|
381
335
|
:RANGE,
|
382
|
-
:ENUM,
|
383
336
|
:O_RANGE,
|
384
|
-
:O_ENUM,
|
385
337
|
:STRING1,
|
386
338
|
:STRING2,
|
387
339
|
"("],
|
@@ -390,9 +342,7 @@ module Branch
|
|
390
342
|
:HEX,
|
391
343
|
:SYMBOL,
|
392
344
|
:RANGE,
|
393
|
-
:ENUM,
|
394
345
|
:O_RANGE,
|
395
|
-
:O_ENUM,
|
396
346
|
:STRING1,
|
397
347
|
:STRING2,
|
398
348
|
"("],
|
@@ -401,9 +351,7 @@ module Branch
|
|
401
351
|
:HEX,
|
402
352
|
:SYMBOL,
|
403
353
|
:RANGE,
|
404
|
-
:ENUM,
|
405
354
|
:O_RANGE,
|
406
|
-
:O_ENUM,
|
407
355
|
:STRING1,
|
408
356
|
:STRING2,
|
409
357
|
"("],
|
@@ -465,9 +413,7 @@ module Branch
|
|
465
413
|
:HEX,
|
466
414
|
:SYMBOL,
|
467
415
|
:RANGE,
|
468
|
-
:ENUM,
|
469
416
|
:O_RANGE,
|
470
|
-
:O_ENUM,
|
471
417
|
:STRING1,
|
472
418
|
:STRING2,
|
473
419
|
"@terminals",
|
@@ -481,9 +427,7 @@ module Branch
|
|
481
427
|
:HEX,
|
482
428
|
:SYMBOL,
|
483
429
|
:RANGE,
|
484
|
-
:ENUM,
|
485
430
|
:O_RANGE,
|
486
|
-
:O_ENUM,
|
487
431
|
:STRING1,
|
488
432
|
:STRING2,
|
489
433
|
"@terminals",
|
@@ -497,9 +441,7 @@ module Branch
|
|
497
441
|
:HEX,
|
498
442
|
:SYMBOL,
|
499
443
|
:RANGE,
|
500
|
-
:ENUM,
|
501
444
|
:O_RANGE,
|
502
|
-
:O_ENUM,
|
503
445
|
:STRING1,
|
504
446
|
:STRING2,
|
505
447
|
"@terminals",
|
@@ -513,9 +455,7 @@ module Branch
|
|
513
455
|
:HEX,
|
514
456
|
:SYMBOL,
|
515
457
|
:RANGE,
|
516
|
-
:ENUM,
|
517
458
|
:O_RANGE,
|
518
|
-
:O_ENUM,
|
519
459
|
:STRING1,
|
520
460
|
:STRING2,
|
521
461
|
"@terminals",
|
@@ -529,9 +469,7 @@ module Branch
|
|
529
469
|
:HEX,
|
530
470
|
:SYMBOL,
|
531
471
|
:RANGE,
|
532
|
-
:ENUM,
|
533
472
|
:O_RANGE,
|
534
|
-
:O_ENUM,
|
535
473
|
:STRING1,
|
536
474
|
:STRING2,
|
537
475
|
"@terminals",
|
@@ -573,9 +511,7 @@ module Branch
|
|
573
511
|
:HEX,
|
574
512
|
:SYMBOL,
|
575
513
|
:RANGE,
|
576
|
-
:ENUM,
|
577
514
|
:O_RANGE,
|
578
|
-
:O_ENUM,
|
579
515
|
:STRING1,
|
580
516
|
:STRING2,
|
581
517
|
"@terminals",
|
@@ -590,9 +526,7 @@ module Branch
|
|
590
526
|
:HEX,
|
591
527
|
:SYMBOL,
|
592
528
|
:RANGE,
|
593
|
-
:ENUM,
|
594
529
|
:O_RANGE,
|
595
|
-
:O_ENUM,
|
596
530
|
:STRING1,
|
597
531
|
:STRING2,
|
598
532
|
"@terminals",
|
@@ -607,9 +541,7 @@ module Branch
|
|
607
541
|
:HEX,
|
608
542
|
:SYMBOL,
|
609
543
|
:RANGE,
|
610
|
-
:ENUM,
|
611
544
|
:O_RANGE,
|
612
|
-
:O_ENUM,
|
613
545
|
:STRING1,
|
614
546
|
:STRING2,
|
615
547
|
"@terminals",
|
@@ -625,9 +557,7 @@ module Branch
|
|
625
557
|
:HEX,
|
626
558
|
:SYMBOL,
|
627
559
|
:RANGE,
|
628
|
-
:ENUM,
|
629
560
|
:O_RANGE,
|
630
|
-
:O_ENUM,
|
631
561
|
:STRING1,
|
632
562
|
:STRING2,
|
633
563
|
"@terminals",
|
@@ -643,9 +573,7 @@ module Branch
|
|
643
573
|
:HEX,
|
644
574
|
:SYMBOL,
|
645
575
|
:RANGE,
|
646
|
-
:ENUM,
|
647
576
|
:O_RANGE,
|
648
|
-
:O_ENUM,
|
649
577
|
:STRING1,
|
650
578
|
:STRING2,
|
651
579
|
"@terminals",
|
@@ -661,9 +589,7 @@ module Branch
|
|
661
589
|
:HEX,
|
662
590
|
:SYMBOL,
|
663
591
|
:RANGE,
|
664
|
-
:ENUM,
|
665
592
|
:O_RANGE,
|
666
|
-
:O_ENUM,
|
667
593
|
:STRING1,
|
668
594
|
:STRING2,
|
669
595
|
"@terminals",
|
@@ -679,9 +605,7 @@ module Branch
|
|
679
605
|
:HEX,
|
680
606
|
:SYMBOL,
|
681
607
|
:RANGE,
|
682
|
-
:ENUM,
|
683
608
|
:O_RANGE,
|
684
|
-
:O_ENUM,
|
685
609
|
:STRING1,
|
686
610
|
:STRING2,
|
687
611
|
"@terminals",
|
data/etc/ebnf.sxp
CHANGED
@@ -9,26 +9,25 @@
|
|
9
9
|
(rule diff "7" (seq postfix (opt (seq "-" postfix))))
|
10
10
|
(rule postfix "8" (seq primary (opt POSTFIX)))
|
11
11
|
(rule primary "9"
|
12
|
-
(alt HEX SYMBOL RANGE
|
12
|
+
(alt HEX SYMBOL RANGE O_RANGE STRING1 STRING2 (seq "(" expression ")")))
|
13
13
|
(rule pass "10" (seq "@pass" expression))
|
14
|
-
(terminal LHS "11" (seq (opt
|
14
|
+
(terminal LHS "11" (seq (opt (seq "[" (plus SYMBOL) "]")) SYMBOL "::="))
|
15
15
|
(terminal SYMBOL "12" (plus (alt (range "a-z") (range "A-Z") (range "0-9") "_" ".")))
|
16
|
-
(terminal HEX "13"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
(terminal
|
22
|
-
(terminal
|
23
|
-
(terminal
|
24
|
-
(terminal
|
25
|
-
(terminal
|
26
|
-
(terminal
|
27
|
-
(terminal
|
28
|
-
(terminal POSTFIX "22" (range "?*+"))
|
29
|
-
(terminal PASS "23"
|
16
|
+
(terminal HEX "13" (seq "#x" (plus (alt (range "0-9") (range "a-f") (range "A-F")))))
|
17
|
+
(terminal RANGE "14"
|
18
|
+
(seq "[" (plus (alt (seq R_BEGIN (alt HEX R_CHAR)) (alt HEX R_CHAR))) "]"))
|
19
|
+
(terminal O_RANGE "15"
|
20
|
+
(seq "[^" (plus (alt (seq R_BEGIN (alt HEX R_CHAR)) (alt HEX R_CHAR))) "]"))
|
21
|
+
(terminal STRING1 "16" (seq "\"" (star (diff CHAR "\"")) "\""))
|
22
|
+
(terminal STRING2 "17" (seq "'" (diff CHAR "'")))
|
23
|
+
(terminal CHAR "18" (alt HEX (range "#x20#x21#x22") (range "#x24-#x00FFFFFF")))
|
24
|
+
(terminal R_CHAR "19" (diff CHAR "]"))
|
25
|
+
(terminal R_BEGIN "20" (seq (alt HEX R_CHAR) "-"))
|
26
|
+
(terminal POSTFIX "21" (range "?*+"))
|
27
|
+
(terminal PASS "22"
|
30
28
|
(plus
|
31
29
|
(alt
|
32
|
-
(range "#x20
|
33
|
-
(seq (alt "#" "//") (star (range "
|
34
|
-
(seq "/*" (star (alt (opt (seq "*" (range "^/"))) (range "^*"))) "*/")
|
30
|
+
(range "#x00-#x20")
|
31
|
+
(seq (alt "#" "//") (star (range "^#x0A#x0D")))
|
32
|
+
(seq "/*" (star (alt (opt (seq "*" (range "^/"))) (range "^*"))) "*/")
|
33
|
+
(seq "(*" (star (alt (opt (seq "*" (range "^)"))) (range "^*"))) "*)")) )) )
|
data/lib/ebnf/base.rb
CHANGED
@@ -183,6 +183,13 @@ module EBNF
|
|
183
183
|
Writer.string(*ast)
|
184
184
|
end
|
185
185
|
|
186
|
+
##
|
187
|
+
# Output formatted EBNF as HTML
|
188
|
+
# @return [String]
|
189
|
+
def to_html
|
190
|
+
Writer.html(*ast)
|
191
|
+
end
|
192
|
+
|
186
193
|
def dup
|
187
194
|
new_obj = super
|
188
195
|
new_obj.instance_variable_set(:@ast, @ast.dup)
|
data/lib/ebnf/ll1/scanner.rb
CHANGED
@@ -57,7 +57,23 @@ module EBNF::LL1
|
|
57
57
|
feed_me
|
58
58
|
super
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
|
+
##
|
62
|
+
# Returns true if the scan pointer is at the end of the string
|
63
|
+
#
|
64
|
+
# @return [Boolean]
|
65
|
+
def eos?
|
66
|
+
feed_me
|
67
|
+
super
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Set the scan pointer to the end of the string and clear matching data
|
72
|
+
def terminate
|
73
|
+
feed_me
|
74
|
+
super
|
75
|
+
end
|
76
|
+
|
61
77
|
##
|
62
78
|
# Tries to match with `pattern` at the current position.
|
63
79
|
#
|