-
Notifications
You must be signed in to change notification settings - Fork 2
/
lpi-api.pl
executable file
·76 lines (64 loc) · 2.66 KB
/
lpi-api.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
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_error)).
:- use_module(library(http/html_write)).
% we need this module from the HTTP client library for http_read_data
:- use_module(library(http/http_client)).
:- http_handler('/', web_form, []).
:- include('files/listprolog.pl').
server(Port) :-
http_server(http_dispatch, [port(Port)]).
/*
browse http://127.0.0.1:8000/
This demonstrates handling POST requests
*/
web_form(_Request) :-
reply_html_page(
title('List Prolog Interpreter'),
[
form([action='/landing', method='POST'], [
/**
p([], [
label([for=debug],'Debug (on/off):'),
input([name=debug, type=textarea])
]),
**/
p([], [
label([for=query],'Query (e.g. [[n,reverse],[[1,2,3],[],[v,l]]]):'),
input([name=query, type=textarea])
]),
p([], [
label([for=functions],'Functions (e.g. [
[[n,reverse],[[],[v,l],[v,l]]],
[[n,reverse],[[v,l],[v,m],[v,n]],":-",
[[[n,head],[[v,l],[v,h]]],
[[n,tail],[[v,l],[v,t]]],
[[n,wrap],[[v,h],[v,h1]]],
[[n,append],[[v,h1],[v,m],[v,o]]],
[[n,reverse],[[v,t],[v,o],[v,n]]]
]
]
]):'),
input([name=functions, type=textarea])
]),
p([], input([name=submit, type=submit, value='Submit'], []))
])]).
:- http_handler('/landing', landing_pad, []).
landing_pad(Request) :-
member(method(post), Request), !,
http_read_data(Request, Data, []),
format('Content-type: text/html~n~n', []),
format('<p>', []),
%%portray_clause(Data),
%%term_to_atom(Term,Data),
Data=[%%debug='off',%%Debug1,
query=Query1,functions=Functions1,submit=_],
term_to_atom(Debug2,'off'),
term_to_atom(Query2,Query1),
term_to_atom(Functions2,Functions1),
international_interpret([lang,"en"],Debug2,Query2,Functions2,Result),
%%format('</p><p>========~n', []),
%%portray_clause
portray_clause(Result),
%%writeln1(Data),
format('</p>').