-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzPathMachine.pl
69 lines (65 loc) · 1.99 KB
/
zPathMachine.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
:- module(zPathMachine, [zPathMachine/5]).
:- use_module(charUtils).
final(empty).
final(id44).
final(path).
delta(slash, Char, id44) :- isAlphaChar(Char), !.
delta(id44, '.', separator) :- !.
delta(id44, '(', id8Start) :- !.
delta(id44, Char, id44) :- isAlnumChar(Char), !.
delta(separator, Char, id44) :- isAlnumChar(Char), !.
delta(id8Start, Char, id8) :- isAlphaChar(Char), !.
delta(id8, Char, id8) :- isAlnumChar(Char), !.
accept([], State, '', '', [], []) :-
final(State),
!.
accept([')' | Rest], id8, '', '', [')'], Rest) :- !.
accept([? | Rest], State, '', '', [], [? | Rest]) :-
final(State),
!.
accept([# | Rest], State, '', '', [], [# | Rest]) :-
final(State),
!.
accept([Char | Chars], State, ID44, ID8, Path, Leftover) :-
delta(State, Char, id44),
!,
accept(Chars, id44, RestID44, ID8, RestPath, Leftover),
!,
atom_concat(Char, RestID44, ID44),
append([Char], RestPath, Path).
accept([Char | Chars], State, ID44, ID8, Path, Leftover) :-
delta(State, Char, separator),
!,
accept(Chars, separator, RestID44, ID8, RestPath, Leftover),
!,
atom_concat(Char, RestID44, ID44),
append([Char], RestPath, Path).
accept([Char | Chars], State, ID44, ID8, Path, Leftover) :-
delta(State, Char, id8),
!,
accept(Chars, id8, ID44, RestID8, RestPath, Leftover),
!,
atom_concat(Char, RestID8, ID8),
append([Char], RestPath, Path).
accept([/ | Rest], empty, ID44, ID8, Path, Leftover) :-
!,
accept(Rest, slash, ID44, ID8, Path, Leftover),
!.
accept([Char | Chars], State, ID44, ID8, Path, Leftover) :-
delta(State, Char, NewState),
!,
accept(Chars, NewState, ID44, ID8, RestPath, Leftover),
append([Char], RestPath, Path).
/**
* zPathMachine(
* ++Chars:atom[],
* Path:atomic,
* -Leftover:atom[]
* ) is semidet.
*
* True when the list of characters initially has a valid URI zOS specific
* path definition, but without any constraint on ID44 and ID8 length.
*/
zPathMachine(Chars, ID44, ID8, Path, Leftover) :-
accept(Chars, empty, ID44, ID8, ValueList, Leftover),
listToURIValue(ValueList, Path).