forked from saetre/busstuc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlparser.pl
119 lines (67 loc) · 1.98 KB
/
xmlparser.pl
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
%% FILE xmlparser.pl
%% SYSTEM TELETUC ("Buster")
%% CREATED TA-020617
%% REVISED TA-020624
:-module( xmlparser, [ xmlrowparse/2, xmltaggerparse/2 ] ).
:-use_module( sicstus4compatibility, [ output/1 ] ). %% Compatible with sicstus4, get0/1 etc.
%:-use_module( 'utility/writeout', [ output/1 ] ).
:-use_module( main, [ scanfile/2 ] ).
xmltaggerparse(F,Struct):-
output('scan'),output(F),
scanfile(F,List),
output(List),
skipstart(List,List1),
xmltaggerparse1(Struct,List1,[]),
!. %% TA-020624
xmlrowparse(F,Struct):-
scanfile(F,List),
skipstart(List,List1),
xmlrowparse1(Struct,List1,[]),
!. %% TA-020624
skipstart(['<'|Z],['<'|Z]):-!.
skipstart([_X|Y],K):-
skipstart(Y,K).
%%% Parser rules
%% Tagger Parse
xmltaggerparse1(FH) --> xmlbolks(FH).
xmlbolks([F|H]) --> xmlbolk(F),xmlbolks(H).
xmlbolks([]) --> [].
xmlbolk(K) --> xmlresultbolk(K).
xmlrowparse1(Struct) -->
xmlquerybolk(query),
xmlresrowsbolk(Struct).
xmlquerybolk(query) -->
xmltag(query),
skip(query).
xmlresrowsbolk([result=RB]) -->
xmltag(result),
xmlrowsbolk(RB),
xmluntag(result).
xmlrowsbolk([H|T]) -->
xmlrowbolk(H),
xmlrowsbolk(T).
xmlrowsbolk([]) --> [].
xmlrowbolk(K) -->
xmltag(row),
xmlreslist(K),
xmluntag(row).
%% Common Rules
skip(Query) --> ['<','/',Query,'>'],!.
skip(Query) --> [_],skip(Query).
xmlresultbolk([result=K]) -->
xmltag(result),
xmlreslist(K),
xmluntag(result).
xmlreslist([F|H]) -->
xmltagitem(F),
xmlreslist(H).
xmlreslist([]) --> [].
xmltagitem([A=H]) -->
xmltag(A),
firstonly(H), %% HELEN BEATE JOHANNE -> helen %% TA-020624
xmluntag(A).
firstonly(H) --> [H], skiprestlist. %% TA-020624
skiprestlist --> [X],{X \== ('<')},skiprestlist.
skiprestlist --> [].
xmltag(Result) --> ['<',Result,'>'].
xmluntag(Result) --> ['<','/',Result,'>'].