forked from linkeddata/swap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbnf2ietf.n3
94 lines (66 loc) · 2.3 KB
/
bnf2ietf.n3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Convert BNF in RDF to IETF XBNF standard used in XML for example
# See http://www.w3.org/TR/xml11/#sec-notation
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix bnf: <http://www.w3.org/2000/10/swap/grammar/bnf#>.
@prefix rul: <http://www.w3.org/2000/10/swap/grammar/bnf-rules#>.
@prefix : <http://www.w3.org/2000/10/swap/grammar/bnf2html#>.
@prefix h: <http://www.w3.org/2000/10/swap/grammar/bnf2html#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@keywords a, is, of.
# Find all possible sequences for each term
#
{ ?x bnf:mustBeOneSequence ?y} => { ?x optionTail ?y; a Production}.
{ ?x bnf:matches [] } => { ?x a Production}.
{?x optionTail [rdf:first ?y; rdf:rest ?z]} => {
?x bnf:canBeSequence ?y;
optionTail ?z.
?y a Sequence}.
# Label every trailing subseqeunce
{ ?seq a Sequence } => { ?seq a SequenceTail }.
{ ?seq a SequenceTail; rdf:rest ?s2 } => { ?s2 a SequenceTail }.
################
# Literal are referenced but no labels for LHS @@ escaped
{ ?seq a SequenceTail; rdf:first ?x.
?x log:rawType log:Literal.
( " \"" ?x "\" " ) string:concatenation ?ref.
} => { ?x reference ?ref }.
############
{ ?x a Production.
?x log:uri ?u.
(?u ".*#(.*)") string:scrape ?lab.
} => {
?x bnf:label ?lab.
}.
{ ?x a Production; bnf:label ?lab.
( ?lab " ::=" ) string:concatenation ?start.
} => {
?x reference ?lab.
(?lab 0) log:outputString ?start.
}.
############
() seqlabel "void".
bnf:eof reference "EOF".
# Start it, skipping use of the seqlabel of ():
{ ?seq a SequenceTail; rdf:first ?x; rdf:rest ().
?x reference ?lab1.
} => { ?seq seqlabel ?lab1 }.
# This one takes forever:
{ ?seq a SequenceTail; rdf:first ?x; rdf:rest ?tail.
?x reference ?lab1.
?tail seqlabel ?lab2; rdf:rest []. # Non-null
(?lab1 " " ?lab2) string:concatenation ?str
} => { ?seq seqlabel ?str }.
{?x bnf:label ?lab; bnf:canBeSequence [seqlabel ?seqlab].
("\t\t|\t" ?seqlab "\n" ) string:concatenation ?para
} => {(?lab 5) log:outputString ?para}.
########################## Regular expressions
{ [] a Production;
bnf:label ?lab;
bnf:matches ?regexp.
( "\t" ?regexp "\n") string:concatenation ?regpara.
}=>{
(?lab 6) log:outputString ?regpara.
}.
#end