ebnf 0.2.0 → 0.2.1
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.
- data/VERSION +1 -1
- data/etc/ebnf.ebnf +19 -11
- data/etc/{ebnf.ll1 → ebnf.ll1.sxp} +460 -288
- data/etc/ebnf.rb +451 -507
- data/etc/ebnf.sxp +112 -0
- data/etc/{turtle.ll1 → turtle.ll1.sxp} +836 -66
- data/etc/turtle.rb +1030 -437
- data/etc/turtle.sxp +417 -0
- data/lib/ebnf/base.rb +5 -11
- data/lib/ebnf/bnf.rb +2 -2
- data/lib/ebnf/ll1.rb +92 -125
- data/lib/ebnf/ll1/parser.rb +12 -10
- data/lib/ebnf/parser.rb +6 -3
- data/lib/ebnf/rule.rb +61 -8
- metadata +7 -5
data/etc/turtle.sxp
ADDED
@@ -0,0 +1,417 @@
|
|
1
|
+
((rule turtleDoc "1" (star statement))
|
2
|
+
(rule
|
3
|
+
statement
|
4
|
+
"2"
|
5
|
+
(alt directive (seq triples "."))
|
6
|
+
)
|
7
|
+
(rule
|
8
|
+
directive
|
9
|
+
"3"
|
10
|
+
(alt
|
11
|
+
prefixID
|
12
|
+
base
|
13
|
+
sparqlPrefix
|
14
|
+
sparqlBase
|
15
|
+
)
|
16
|
+
)
|
17
|
+
(rule
|
18
|
+
prefixID
|
19
|
+
"4"
|
20
|
+
(seq "@prefix" PNAME_NS IRIREF ".")
|
21
|
+
)
|
22
|
+
(rule base "5" (seq "@base" IRIREF "."))
|
23
|
+
(rule
|
24
|
+
triples
|
25
|
+
"6"
|
26
|
+
(alt
|
27
|
+
(seq subject predicateObjectList)
|
28
|
+
(seq
|
29
|
+
blankNodePropertyList
|
30
|
+
(opt predicateObjectList)
|
31
|
+
)
|
32
|
+
)
|
33
|
+
)
|
34
|
+
(rule
|
35
|
+
predicateObjectList
|
36
|
+
"7"
|
37
|
+
(seq
|
38
|
+
verb
|
39
|
+
objectList
|
40
|
+
(star (seq ";" (opt (seq verb objectList))))
|
41
|
+
)
|
42
|
+
)
|
43
|
+
(rule
|
44
|
+
objectList
|
45
|
+
"8"
|
46
|
+
(seq object (star (seq "," object)))
|
47
|
+
)
|
48
|
+
(rule verb "9" (alt predicate "a"))
|
49
|
+
(rule
|
50
|
+
subject
|
51
|
+
"10"
|
52
|
+
(alt iri BlankNode collection)
|
53
|
+
)
|
54
|
+
(rule predicate "11" (seq iri))
|
55
|
+
(rule
|
56
|
+
object
|
57
|
+
"12"
|
58
|
+
(alt
|
59
|
+
iri
|
60
|
+
BlankNode
|
61
|
+
collection
|
62
|
+
blankNodePropertyList
|
63
|
+
literal
|
64
|
+
)
|
65
|
+
)
|
66
|
+
(rule
|
67
|
+
literal
|
68
|
+
"13"
|
69
|
+
(alt
|
70
|
+
RDFLiteral
|
71
|
+
NumericLiteral
|
72
|
+
BooleanLiteral
|
73
|
+
)
|
74
|
+
)
|
75
|
+
(rule
|
76
|
+
blankNodePropertyList
|
77
|
+
"14"
|
78
|
+
(seq "[" predicateObjectList "]")
|
79
|
+
)
|
80
|
+
(rule
|
81
|
+
collection
|
82
|
+
"15"
|
83
|
+
(seq "(" (star object) ")")
|
84
|
+
)
|
85
|
+
(rule
|
86
|
+
NumericLiteral
|
87
|
+
"16"
|
88
|
+
(alt INTEGER DECIMAL DOUBLE)
|
89
|
+
)
|
90
|
+
(rule
|
91
|
+
String
|
92
|
+
"17"
|
93
|
+
(alt
|
94
|
+
STRING_LITERAL_QUOTE
|
95
|
+
STRING_LITERAL_SINGLE_QUOTE
|
96
|
+
STRING_LITERAL_LONG_SINGLE_QUOTE
|
97
|
+
STRING_LITERAL_LONG_QUOTE
|
98
|
+
)
|
99
|
+
)
|
100
|
+
(terminal
|
101
|
+
IRIREF
|
102
|
+
"18"
|
103
|
+
(seq
|
104
|
+
"<"
|
105
|
+
(star
|
106
|
+
(alt (range "^#x00-#x20<>\"{}|^`\\") UCHAR)
|
107
|
+
)
|
108
|
+
">"
|
109
|
+
)
|
110
|
+
)
|
111
|
+
(terminal
|
112
|
+
INTEGER
|
113
|
+
"19"
|
114
|
+
(seq (opt (range "+-")) (plus (range "0-9")))
|
115
|
+
)
|
116
|
+
(terminal
|
117
|
+
DECIMAL
|
118
|
+
"20"
|
119
|
+
(seq
|
120
|
+
(opt (range "+-"))
|
121
|
+
(seq
|
122
|
+
(star (range "0-9"))
|
123
|
+
"."
|
124
|
+
(plus (range "0-9"))
|
125
|
+
)
|
126
|
+
)
|
127
|
+
)
|
128
|
+
(terminal
|
129
|
+
DOUBLE
|
130
|
+
"21"
|
131
|
+
(seq
|
132
|
+
(opt (range "+-"))
|
133
|
+
(alt
|
134
|
+
(seq
|
135
|
+
(plus (range "0-9"))
|
136
|
+
"."
|
137
|
+
(star (range "0-9"))
|
138
|
+
EXPONENT
|
139
|
+
)
|
140
|
+
(seq "." (plus (range "0-9")) EXPONENT)
|
141
|
+
(seq (plus (range "0-9")) EXPONENT)
|
142
|
+
)
|
143
|
+
)
|
144
|
+
)
|
145
|
+
(terminal
|
146
|
+
STRING_LITERAL_QUOTE
|
147
|
+
"22"
|
148
|
+
(seq
|
149
|
+
"\""
|
150
|
+
(star
|
151
|
+
(alt (range "^#x22#x5C#xA#xD") ECHAR UCHAR)
|
152
|
+
)
|
153
|
+
"\""
|
154
|
+
)
|
155
|
+
)
|
156
|
+
(terminal
|
157
|
+
STRING_LITERAL_SINGLE_QUOTE
|
158
|
+
"23"
|
159
|
+
(seq
|
160
|
+
"'"
|
161
|
+
(star
|
162
|
+
(alt (range "^#x27#x5C#xA#xD") ECHAR UCHAR)
|
163
|
+
)
|
164
|
+
"'"
|
165
|
+
)
|
166
|
+
)
|
167
|
+
(terminal
|
168
|
+
STRING_LITERAL_LONG_SINGLE_QUOTE
|
169
|
+
"24"
|
170
|
+
(seq
|
171
|
+
"'''"
|
172
|
+
(star
|
173
|
+
(seq
|
174
|
+
(opt (alt "'" "''"))
|
175
|
+
(alt (range "^'\\") ECHAR UCHAR)
|
176
|
+
)
|
177
|
+
)
|
178
|
+
"'''"
|
179
|
+
)
|
180
|
+
)
|
181
|
+
(terminal
|
182
|
+
STRING_LITERAL_LONG_QUOTE
|
183
|
+
"25"
|
184
|
+
(seq
|
185
|
+
"\"\"\""
|
186
|
+
(star
|
187
|
+
(seq
|
188
|
+
(opt (alt "\"" "\"\""))
|
189
|
+
(alt (range "^\"\\") ECHAR UCHAR)
|
190
|
+
)
|
191
|
+
)
|
192
|
+
"\"\"\""
|
193
|
+
)
|
194
|
+
)
|
195
|
+
(terminal
|
196
|
+
UCHAR
|
197
|
+
"26"
|
198
|
+
(alt
|
199
|
+
(seq "\\u" HEX HEX HEX HEX)
|
200
|
+
(seq
|
201
|
+
"\\U"
|
202
|
+
HEX
|
203
|
+
HEX
|
204
|
+
HEX
|
205
|
+
HEX
|
206
|
+
HEX
|
207
|
+
HEX
|
208
|
+
HEX
|
209
|
+
HEX
|
210
|
+
)
|
211
|
+
)
|
212
|
+
)
|
213
|
+
(rule
|
214
|
+
sparqlPrefix
|
215
|
+
"28s"
|
216
|
+
(seq SPARQL_PREFIX PNAME_NS IRIREF)
|
217
|
+
)
|
218
|
+
(terminal
|
219
|
+
SPARQL_PREFIX
|
220
|
+
"28t"
|
221
|
+
(seq
|
222
|
+
(range "Pp")
|
223
|
+
(range "Rr")
|
224
|
+
(range "Ee")
|
225
|
+
(range "Ff")
|
226
|
+
(range "Ii")
|
227
|
+
(range "Xx")
|
228
|
+
)
|
229
|
+
)
|
230
|
+
(rule
|
231
|
+
sparqlBase
|
232
|
+
"29s"
|
233
|
+
(seq SPARQL_BASE IRIREF)
|
234
|
+
)
|
235
|
+
(terminal
|
236
|
+
SPARQL_BASE
|
237
|
+
"29t"
|
238
|
+
(seq
|
239
|
+
(range "Bb")
|
240
|
+
(range "Aa")
|
241
|
+
(range "Ss")
|
242
|
+
(range "Ee")
|
243
|
+
)
|
244
|
+
)
|
245
|
+
(rule
|
246
|
+
RDFLiteral
|
247
|
+
"128s"
|
248
|
+
(seq String (opt (alt LANGTAG (seq "^^" iri))))
|
249
|
+
)
|
250
|
+
(rule
|
251
|
+
BooleanLiteral
|
252
|
+
"133s"
|
253
|
+
(alt "true" "false")
|
254
|
+
)
|
255
|
+
(rule iri "135s" (alt IRIREF PrefixedName))
|
256
|
+
(rule
|
257
|
+
PrefixedName
|
258
|
+
"136s"
|
259
|
+
(alt PNAME_LN PNAME_NS)
|
260
|
+
)
|
261
|
+
(rule
|
262
|
+
BlankNode
|
263
|
+
"137s"
|
264
|
+
(alt BLANK_NODE_LABEL ANON)
|
265
|
+
)
|
266
|
+
(terminal
|
267
|
+
PNAME_NS
|
268
|
+
"139s"
|
269
|
+
(seq (opt PN_PREFIX) ":")
|
270
|
+
)
|
271
|
+
(terminal
|
272
|
+
PNAME_LN
|
273
|
+
"140s"
|
274
|
+
(seq PNAME_NS PN_LOCAL)
|
275
|
+
)
|
276
|
+
(terminal
|
277
|
+
BLANK_NODE_LABEL
|
278
|
+
"141s"
|
279
|
+
(seq
|
280
|
+
"_:"
|
281
|
+
(alt PN_CHARS_U (range "0-9"))
|
282
|
+
(opt (seq (star (alt PN_CHARS ".")) PN_CHARS))
|
283
|
+
)
|
284
|
+
)
|
285
|
+
(terminal
|
286
|
+
LANGTAG
|
287
|
+
"144s"
|
288
|
+
(seq
|
289
|
+
"@"
|
290
|
+
(plus (range "a-zA-Z"))
|
291
|
+
(star (seq "-" (plus (range "a-zA-Z0-9"))))
|
292
|
+
)
|
293
|
+
)
|
294
|
+
(terminal
|
295
|
+
EXPONENT
|
296
|
+
"154s"
|
297
|
+
(seq
|
298
|
+
(range "eE")
|
299
|
+
(opt (range "+-"))
|
300
|
+
(plus (range "0-9"))
|
301
|
+
)
|
302
|
+
)
|
303
|
+
(terminal
|
304
|
+
ECHAR
|
305
|
+
"159s"
|
306
|
+
(seq "\\" (range "tbnrf\\\"'"))
|
307
|
+
)
|
308
|
+
(terminal
|
309
|
+
WS
|
310
|
+
"161s"
|
311
|
+
(alt
|
312
|
+
(hex "#x20")
|
313
|
+
(hex "#x9")
|
314
|
+
(hex "#xD")
|
315
|
+
(hex "#xA")
|
316
|
+
)
|
317
|
+
)
|
318
|
+
(terminal ANON "162s" (seq "[" (star WS) "]"))
|
319
|
+
(terminal
|
320
|
+
PN_CHARS_BASE
|
321
|
+
"163s"
|
322
|
+
(alt
|
323
|
+
(range "A-Z")
|
324
|
+
(range "a-z")
|
325
|
+
(range "#x00C0-#x00D6")
|
326
|
+
(range "#x00D8-#x00F6")
|
327
|
+
(range "#x00F8-#x02FF")
|
328
|
+
(range "#x0370-#x037D")
|
329
|
+
(range "#x037F-#x1FFF")
|
330
|
+
(range "#x200C-#x200D")
|
331
|
+
(range "#x2070-#x218F")
|
332
|
+
(range "#x2C00-#x2FEF")
|
333
|
+
(range "#x3001-#xD7FF")
|
334
|
+
(range "#xF900-#xFDCF")
|
335
|
+
(range "#xFDF0-#xFFFD")
|
336
|
+
(range "#x10000-#xEFFFF")
|
337
|
+
)
|
338
|
+
)
|
339
|
+
(terminal
|
340
|
+
PN_CHARS_U
|
341
|
+
"164s"
|
342
|
+
(alt PN_CHARS_BASE "_")
|
343
|
+
)
|
344
|
+
(terminal
|
345
|
+
PN_CHARS
|
346
|
+
"166s"
|
347
|
+
(alt
|
348
|
+
PN_CHARS_U
|
349
|
+
"-"
|
350
|
+
(range "0-9")
|
351
|
+
(hex "#x00B7")
|
352
|
+
(range "#x0300-#x036F")
|
353
|
+
(range "#x203F-#x2040")
|
354
|
+
)
|
355
|
+
)
|
356
|
+
(terminal
|
357
|
+
PN_PREFIX
|
358
|
+
"167s"
|
359
|
+
(seq
|
360
|
+
PN_CHARS_BASE
|
361
|
+
(opt (seq (star (alt PN_CHARS ".")) PN_CHARS))
|
362
|
+
)
|
363
|
+
)
|
364
|
+
(terminal
|
365
|
+
PN_LOCAL
|
366
|
+
"168s"
|
367
|
+
(seq
|
368
|
+
(alt PN_CHARS_U ":" (range "0-9") PLX)
|
369
|
+
(opt
|
370
|
+
(seq
|
371
|
+
(star (alt PN_CHARS "." ":" PLX))
|
372
|
+
(alt PN_CHARS ":" PLX)
|
373
|
+
)
|
374
|
+
)
|
375
|
+
)
|
376
|
+
)
|
377
|
+
(terminal
|
378
|
+
PLX
|
379
|
+
"169s"
|
380
|
+
(alt PERCENT PN_LOCAL_ESC)
|
381
|
+
)
|
382
|
+
(terminal PERCENT "170s" (seq "%" HEX HEX))
|
383
|
+
(terminal
|
384
|
+
HEX
|
385
|
+
"171s"
|
386
|
+
(alt (range "0-9") (range "A-F") (range "a-f"))
|
387
|
+
)
|
388
|
+
(terminal
|
389
|
+
PN_LOCAL_ESC
|
390
|
+
"172s"
|
391
|
+
(seq
|
392
|
+
"\\"
|
393
|
+
(alt
|
394
|
+
"_"
|
395
|
+
"~"
|
396
|
+
"."
|
397
|
+
"-"
|
398
|
+
"!"
|
399
|
+
"$"
|
400
|
+
"&"
|
401
|
+
"'"
|
402
|
+
"("
|
403
|
+
")"
|
404
|
+
"*"
|
405
|
+
"+"
|
406
|
+
","
|
407
|
+
";"
|
408
|
+
"="
|
409
|
+
"/"
|
410
|
+
"?"
|
411
|
+
"#"
|
412
|
+
"@"
|
413
|
+
"%"
|
414
|
+
)
|
415
|
+
)
|
416
|
+
)
|
417
|
+
)
|
data/lib/ebnf/base.rb
CHANGED
@@ -135,10 +135,7 @@ module EBNF
|
|
135
135
|
# Switch mode to parsing terminals
|
136
136
|
terminal = true
|
137
137
|
when /^@pass\s*(.*)$/m
|
138
|
-
|
139
|
-
rule.kind = :pass
|
140
|
-
rule.orig = r
|
141
|
-
@ast << rule
|
138
|
+
# Ignore, as we can't use this for processing the EBNF grammar itself
|
142
139
|
else
|
143
140
|
rule = depth {ruleParts(r)}
|
144
141
|
|
@@ -149,12 +146,12 @@ module EBNF
|
|
149
146
|
end
|
150
147
|
end
|
151
148
|
|
152
|
-
# Iterate over each rule or terminal
|
149
|
+
# Iterate over each rule or terminal, except empty
|
153
150
|
# @param [:termina, :rule] kind
|
154
151
|
# @yield rule
|
155
152
|
# @yieldparam [Rule] rule
|
156
153
|
def each(kind, &block)
|
157
|
-
ast.each {|r| block.call(r) if r.kind == kind}
|
154
|
+
ast.each {|r| block.call(r) if r.kind == kind && r.sym != :_empty}
|
158
155
|
end
|
159
156
|
|
160
157
|
##
|
@@ -204,10 +201,7 @@ module EBNF
|
|
204
201
|
]
|
205
202
|
end.join("\n") +
|
206
203
|
|
207
|
-
ast.sort.
|
208
|
-
select {|a| [:rule, :terminal].include?(a.kind)}.
|
209
|
-
map(&:to_ttl).
|
210
|
-
join("\n")
|
204
|
+
ast.sort.map(&:to_ttl).join("\n")
|
211
205
|
end
|
212
206
|
|
213
207
|
def depth
|
@@ -226,7 +220,7 @@ module EBNF
|
|
226
220
|
message = "#{args.join(': ')}"
|
227
221
|
str = "[#{@lineno}]#{' ' * depth}#{message}"
|
228
222
|
@options[:debug] << str if @options[:debug].is_a?(Array)
|
229
|
-
$stderr.puts(str)
|
223
|
+
$stderr.puts(str) if @options[:progress] || @options[:debug] == true
|
230
224
|
end
|
231
225
|
|
232
226
|
# Error output
|