File: test_wiki.pl

package info (click to toggle)
swi-prolog 5.10.1-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 76,436 kB
  • ctags: 45,143
  • sloc: ansic: 290,417; perl: 215,108; sh: 5,411; java: 5,136; makefile: 5,021; cpp: 2,168; yacc: 843; xml: 77; sed: 12
file content (81 lines) | stat: -rw-r--r-- 1,879 bytes parent folder | download | duplicates (5)
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
:- module(test_wiki,
	  [ test/1
	  ]).
:- use_module(pldoc).
:- use_module(doc_wiki).
:- use_module(doc_modes).
:- use_module(doc_html).
:- use_module(doc_http).
:- use_module(library('http/html_write')).

/** <module> PlDoc testing module

Just some random tests.
*/

process_comment(File, Pos-String, DOM) :-
	stream_position_data(line_count, Pos, Line),
	FilePos = File:Line,
	is_structured_comment(String, Prefixes),
	indented_lines(String, Prefixes, Lines),
	(   section_comment_header(Lines, Header, Lines1)
	->  DOM = [Header|DOM1],
	    Args = []
	;   process_modes(Lines, FilePos, Modes, Args, Lines1)
	->  DOM = [\pred_dt(Modes), dd(class=defbody, DOM1)]
	),
	wiki_lines_to_dom(Lines1, Args, DOM0),
	strip_leading_par(DOM0, DOM1).

%%	process_comment_list(+Comments, +File, -DOM) is det.
%
%	@param Mode	Enclosing environment, =body= or =dl=

process_comment_list(Comments, File, DOM) :-
	maplist(process_comment(File), Comments, DOMList),
	phrase(missing_tags(DOMList, body), DOM).

missing_tags([], _) -->
	[].
missing_tags([H|T0], Outer) -->
	{ requires(H, Tag), Tag \== Outer, !,
	  Env =.. [Tag,C],
	  phrase(in_tag([H|T0], T, Tag), C)
	},
	[Env],
	missing_tags(T, Outer).
missing_tags([H|T], Outer) -->
	H,
	missing_tags(T, Outer).

in_tag([], [], _) --> !,
	[].
in_tag(L, L, Tag) -->
	{ L = [H|_],
	  \+ requires(H,Tag)
	}, !,
	[].
in_tag([H|T0], T, Tag) -->
	H,
	in_tag(T0, T, Tag).


requires([\pred_dt(_)|_], dl).

test :-
	test('wiki_test_data').

test(Spec) :-
	absolute_file_name(Spec, File, [file_type(prolog)]),
	read_structured_comments(File, Comments),
	process_comment_list(Comments, File, DOM),
	doc_file_name(File, DocFile, [format(html)]),
	open(DocFile, write, Out),
	call_cleanup(doc_write_html(Out, File, DOM),
		     close(Out)).

doc :-
	Port = 4000,
	doc_server(Port),
	format(atom(URL), 'http://localhost:~w/', [Port]),
	www_open_url(URL).