35
36:- module(doc_util,
37 [ insert_alias/2, 38 expand_alias/2, 39 ensure_slash_end/2, 40 atom_pi/2, 41 atom_to_object/2, 42 normalise_white_space//1 43 ]). 44:- use_module(library(dcg/basics)).
51
61insert_alias(Path0, Path) :-
62 path_alias(Alias, Prefix),
63 atom_concat(Prefix, PostFix, Path0),
64 !,
65 atom_concat(Alias, PostFix, Path).
66insert_alias(Path, Path).
73expand_alias(Path0, Path) :-
74 path_alias(Alias, Prefix),
75 atom_concat(Alias, Postfix, Path0),
76 !,
77 atom_concat(Prefix, Postfix, Path).
78expand_alias(Path, Path).
87path_alias('/_SWI_/', Dir) :-
88 current_prolog_flag(home, Dir0),
89 ensure_slash_end(Dir0, Dir).
90path_alias('/_CWD_/', Dir) :-
91 working_directory(Dir0, Dir0),
92 ensure_slash_end(Dir0, Dir).
93
94
95
103ensure_slash_end(Dir, Dir) :-
104 sub_atom(Dir, _, _, 0, /),
105 !.
106ensure_slash_end(Dir0, Dir) :-
107 atom_concat(Dir0, /, Dir).
108
109
121atom_pi(Atom, Module:PI) :-
122 atomic_list_concat([Module, PIAtom], :, Atom),
123 Module \== '',
124 forall(sub_atom(Module, _,1,_,C), char_type(C,alnum)),
125 !,
126 atom_pi2(PIAtom, PI).
127atom_pi(Atom, PI) :-
128 atom_pi2(Atom, PI).
129
130atom_pi2(Atom, Name//Arity) :-
131 sub_atom(Atom, B, _, A, //),
132 sub_atom(Atom, _, A, 0, ArityA),
133 atom_number(ArityA, Arity),
134 sub_atom(Atom, 0, B, _, Name),
135 Name \== '',
136 !.
137atom_pi2(Atom, Name/Arity) :-
138 sub_atom(Atom, B, _, A, /),
139 sub_atom(Atom, _, A, 0, ArityA),
140 atom_number(ArityA, Arity),
141 !,
142 sub_atom(Atom, 0, B, _, Name).
143atom_pi2(Name, Name/_).
149atom_to_object(Atom, xpce(Class, Kind, Name)) :-
150 atom(Atom),
151 sub_atom(Atom, 0, _, _, 'xpce('),
152 sub_atom(Atom, _, 1, 0, ')'),
153 catch(term_to_atom(Term, Atom), _, fail),
154 Term = xpce(Class, Kind, Name),
155 atom(Class), atom(Name),
156 xpce_kind(Kind),
157 !.
158atom_to_object(Atom, Object) :-
159 atom(Atom),
160 atom_concat('f-', Atom0, Atom),
161 !,
162 PI = _/_, 163 atom_pi(Atom0, PI),
164 Object = f(PI).
165atom_to_object(Atom, Object) :-
166 atom(Atom),
167 atom_pi(Atom, PI),
168 ground(PI),
169 !,
170 ( PI = Name/Arity,
171 integer(Arity),
172 atom_concat('f-', FuncName, Name)
173 -> Object = f(FuncName/Arity)
174 ; Object = PI
175 ).
176atom_to_object(Atom, c(Function)) :-
177 atom(Atom),
178 ( sub_atom(Atom, 0, _, _, 'PL_')
179 -> true
180 ; sub_atom(Atom, 0, _, _, 'S')
181 ),
182 sub_atom(Atom, B, _, _, '('),
183 !,
184 sub_atom(Atom, 0, B, _, Function).
185
186xpce_kind(send).
187xpce_kind(get).
188xpce_kind(both).
189xpce_kind(ivar).
190xpce_kind(classvar).
191xpce_kind(class).
198normalise_white_space(Text) -->
199 blanks,
200 normalise_white_space2(Text).
201
202normalise_white_space2(Text) -->
203 non_ws(Text, Tail),
204 blanks,
205 ( eos
206 -> { Tail = [] }
207 ; { Tail = [0'\s|T2] },
208 normalise_white_space2(T2)
209 ).
216non_ws([H|T0], T) -->
217 [H],
218 { \+ code_type(H, space) },
219 !,
220 non_ws(T0, T).
221non_ws(T, T) -->
222 []
PlDoc utilities