forked from SWI-Prolog/swish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswish.pl
208 lines (170 loc) · 6.78 KB
/
swish.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org
Copyright (C): 2014, VU University Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:- module(swish_app,
[
]).
:- use_module(library(pengines)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_path)).
:- use_module(library(option)).
:- use_module(library(settings)).
:- use_module(lib/config, []).
:- use_module(lib/page, []).
:- use_module(lib/storage).
:- use_module(lib/include).
:- use_module(lib/swish_csv).
:- use_module(lib/examples).
:- use_module(lib/profiles).
:- use_module(lib/highlight).
:- use_module(lib/markdown).
:- use_module(lib/template_hint, []).
:- use_module(lib/tutorial).
/*******************************
* PATHS *
*******************************/
user:file_search_path(swish_web, swish(web)).
user:file_search_path(js, swish_web(js)).
user:file_search_path(css, swish_web(css)).
user:file_search_path(icons, swish_web(icons)).
set_swish_path :-
absolute_file_name(swish('swish.pl'), _,
[file_errors(fail), access(read)]), !.
set_swish_path :-
prolog_load_context(directory, Dir),
asserta(user:file_search_path(swish, Dir)).
:- set_swish_path.
http:location(swish, root(.), [priority(-100)]).
/*******************************
* CORS *
*******************************/
% By default, enable CORS
:- set_setting_default(http:cors, [*]).
/*******************************
* CONFIG *
*******************************/
:- multifile
swish_config:config/2,
swish_config:source_alias/2.
%% swish_config:config(?Config, ?Value) is nondet.
%
% All solutions of this predicate are available in the JavaScript
% object config.swish.config. Config must be an atom that is also
% a valid JavaScript identifier. Value must be a value that is
% valid for json_write_dict/2. Most configurations are also saved
% in the application preferences. These are marked [P]. Defined
% config parameters:
%
% - show_beware
% [P] If `true`, show the *Beware* modal dialog on startup
% - tabled_results
% [P] If `true`, check the _table results_ checkbox by default.
% - application
% Name of the Pengine application.
% - csv_formats
% [P] CSV output formats offered. For example, ClioPatria
% defines this as [rdf,prolog]. The first element is default.
% - community_examples
% Allow marking saved programs as example. If marked, the
% programs are added to the Examples menu.
% - public_access
% If lib/authenticate.pl is loaded and this flag is `true`,
% _all_ access to SWISH demands authentication. If false,
% only running queries and saving files is restricted. Note
% that this flag has no effect if no authentication module is
% loaded.
% - ping
% Ping pengine status every N seconds. Updates sparkline
% chart with stack usage.
% - nb_eval_script
% Evaluate scripts in HTML cells of notebooks?
% Allow other code to overrule the defaults from this file.
term_expansion(swish_config:config(Config, _Value), []) :-
clause(swish_config:config(Config, _), _).
swish_config:config(show_beware, false).
swish_config:config(tabled_results, false).
swish_config:config(application, swish).
swish_config:config(csv_formats, [prolog]).
swish_config:config(community_examples, false).
swish_config:config(public_access, false).
swish_config:config(ping, 10).
swish_config:config(notebook, _{eval_script: true}).
%% swish_config:source_alias(Alias, Options) is nondet.
%
% Specify access for files below a given _alias_. Options define
%
% - access(Access)
% One of `read` or `both`. Default is `read`.
% - if(Condition)
% Provide additional conditions. Defined conditions are:
% - loaded
% Only provide access to the file if it is loaded.
/*******************************
* CREATE SWISH APPLICATION *
*******************************/
:- multifile
pengines:prepare_module/3.
:- pengine_application(swish).
:- use_module(swish:lib/render).
:- use_module(swish:lib/trace).
:- use_module(swish:lib/jquery).
:- use_module(swish:lib/swish_debug).
:- use_module(swish:library(pengines_io)).
:- use_module(swish:library(solution_sequences)).
:- use_module(swish:library(aggregate)).
:- if(exists_source(library(tabling))).
:- use_module(swish:library(tabling)).
:- endif.
pengines:prepare_module(Module, swish, _Options) :-
pengines_io:pengine_bind_io_to_html(Module).
%:- set_setting(swish:time_limit, 3600).
% Additional sandboxing rules.
:- use_module(lib/flags).
:- use_module(lib/logging).
% Libraries that are nice to have in SWISH, but cannot be loaded
% because they use directives that are considered unsafe. We load
% them here, so they only need to be imported, which is just fine.
:- use_module(library(clpfd), []).
:- use_module(library(clpb), []).
:- use_module(lib/swish_chr, []).
% load rendering modules
:- use_module(swish(lib/render/sudoku), []).
:- use_module(swish(lib/render/chess), []).
:- use_module(swish(lib/render/table), []).
:- use_module(swish(lib/render/codes), []).
:- use_module(swish(lib/render/svgtree), []).
:- use_module(swish(lib/render/graphviz), []).
:- use_module(swish(lib/render/c3), []).
:- use_module(swish(lib/render/url), []).
:- use_module(swish(lib/render/lpad), []).
%:- use_module(lib/pita).
:- use_module(library(pita)).
:- use_module(library(mcintyre)).
:- use_module(library(slipcover)).
:- use_module(library(auc)).
:- use_module(library(clpr)).
:- use_module(library(real)).
:- multifile sandbox:safe_primitive/1.
sandbox:safe_primitive(nf_r:{_}).
sandbox:safe_primitive(real:(_ <- _)).
:- use_module(swish(lib/render/bdd), []).