File: url.lgt

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (67 lines) | stat: -rw-r--r-- 1,871 bytes parent folder | download
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
:- object(url).


	:- info([
		version is 1.0,
		date is 2003/7/7,
		author is 'Paulo Moura',
		comment is 'Simple example of URL parsing.']).


	:- public(parse/2).

	:- mode(parse(@list, -list), zero_or_one).

	:- info(parse/2, [
		comment is 'Parses a URL into its components.',
		argnames is ['URL', 'Components']]).


	parse(URL, [protocol(Protocol), address(Address), path(Path), file(File)]) :-
		phrase(url(Protocol, Address, Path, File), URL).


	url(Protocol, Address, Path, File) --> protocol(Protocol), "://", address(Address), path(Path), file(File).


	protocol(ftp) --> "ftp".
	protocol(http) --> "http".
	protocol(https) --> "https".
	protocol(rtsp) --> "rtsp".


	address(Address) --> ip_number(Address).
	address([Identifier| Identifiers]) --> identifier(Identifier), dot_identifiers(Identifiers).


	ip_number([N1, N2, N3, N4]) --> ip_subnumber(N1), ".", ip_subnumber(N2), ".", ip_subnumber(N3), ".", ip_subnumber(N4).

	ip_subnumber(N) --> [N1, N2, N3], {N is N3 - 0'0 + 10*(N2 - 0'0) + 100*(N1 - 0'0), N >= 0, N =< 255}.
	ip_subnumber(N) --> [N1, N2], {N is N2 - 0'0 + 10*(N1 - 0'0), N >= 0, N =< 255}.
	ip_subnumber(N) --> [N1], {N is N1 - 0'0, N >= 0, N =< 255}.


	identifier(Identifier) --> characters(Codes), {atom_codes(Identifier, Codes)}.


	characters([]) --> [].
	characters([Code| Codes]) --> [Code], {character(Code)}, characters(Codes).


	character(Code) :- Code @>= 0'a, Code @=< 0'z, !.
	character(Code) :- Code @>= 0'A, Code @=< 0'Z.


	dot_identifiers([]) --> [].
	dot_identifiers([Identifier| Identifiers]) --> ".", identifier(Identifier), dot_identifiers(Identifiers).


	path([]) --> [].
	path([Identifier| Path]) --> "/", identifier(Identifier), path(Path).


	file('') --> [].
	file(File) --> "/", identifier(Name), ".", identifier(Extension), {atom_concat(Name, '.', Aux), atom_concat(Aux, Extension, File)}.


:- end_object.