-
Notifications
You must be signed in to change notification settings - Fork 15
/
readBtf.pro
118 lines (103 loc) · 2.05 KB
/
readBtf.pro
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Map XML-based BTF representation to Prolog representation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% wiki: ReadBTF
xmlToRoot(X1,r(G2,T2))
:-
self(name(btf:root),X1),
child(name(bgf:grammar),X1,G1),
child(name(btf:tree),X1,T1),
xmlToG(G1,G2),
xmlToTree(T1,T2),
!.
xmlToTree(X1,T)
:-
self(name(btf:tree),X1),
child(element,X1,X2),
xmlToT(X2,T),
!.
xmlToT(X1,true)
:-
self(name(epsilon),X1),
!.
xmlToT(X1,t(V))
:-
self(name(terminal),X1),
content(X1,V),
!.
xmlToT(X1,n(P2,T2))
:-
self(name(nonterminal),X1),
child(name(bgf:production),X1,P1),
child(name(btf:tree),X1,T1),
xmlToP(P1,P2),
xmlToTree(T1,T2),
!.
xmlToT(X1,v(string(V)))
:-
self(name(value),X1),
child(name(string),X1,X2),
!,
content(X2,V),
!.
xmlToT(X1,v(int(V3)))
:-
self(name(value),X1),
child(name(int),X1,X2),
!,
content(X2,V1),
name(V1,V2),
number_chars(V3,V2),
!.
xmlToT(X1,a(Ns))
:-
self(name(any),X1),
children(any,X1,Ns),
!.
xmlToT(X1,s(S,T))
:-
self(name(selectable),X1),
child(name(selector),X1,X2),
child(name(btf:tree),X1,X3),
content(X2,S),
xmlToTree(X3,T),
!.
xmlToT(X1,'*'(Ts))
:-
self(name(star),X1),
children(name(btf:tree),X1,Xs),
maplist(xmlToTree,Xs,Ts),
!.
xmlToT(X1,'+'(Ts))
:-
self(name(plus),X1),
children(name(btf:tree),X1,Xs),
maplist(xmlToTree,Xs,Ts),
!.
xmlToT(X1,'?'(Ts))
:-
self(name(optional),X1),
children(name(btf:tree),X1,Xs),
maplist(xmlToTree,Xs,Ts),
!.
xmlToT(X1,','(Ts))
:-
self(name(sequence),X1),
children(name(btf:tree),X1,Xs),
maplist(xmlToTree,Xs,Ts),
!.
xmlToT(X1,';'(X,T))
:-
self(name(choice),X1),
child(name(bgf:expression),X1,X2),
child(name(btf:tree),X1,X3),
xmlToExpression(X2,X),
xmlToTree(X3,T),
!.
xmlToT(Q,_)
:-
Q = element(F,_,_),
require(
fail,
'~q(...) is not valid BTF.',
[F]).