Skip to content

Commit f463777

Browse files
committed
Prolog: new parser
Close #2628. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent c41d298 commit f463777

24 files changed

+1208
-2
lines changed

Tmain/extras-long.d/stdout-expected.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ z nulltag no NONE no Include tags with empty st
1515
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
1616
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
1717
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
18+
- arityAppended yes Prolog no Include predicates with their arises
1819
- funcmap yes QemuHX no Include mapping SQMP to C function name
1920
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
2021
# enabling 1
@@ -34,6 +35,7 @@ z nulltag no NONE no Include tags with empty st
3435
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
3536
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
3637
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
38+
- arityAppended yes Prolog no Include predicates with their arises
3739
- funcmap yes QemuHX no Include mapping SQMP to C function name
3840
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
3941
# disabling 1
@@ -53,6 +55,7 @@ z nulltag no NONE no Include tags with empty st
5355
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
5456
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
5557
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
58+
- arityAppended yes Prolog no Include predicates with their arises
5659
- funcmap yes QemuHX no Include mapping SQMP to C function name
5760
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
5861
# combination
@@ -72,6 +75,7 @@ z nulltag no NONE no Include tags with empty st
7275
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
7376
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
7477
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
78+
- arityAppended yes Prolog no Include predicates with their arises
7579
- funcmap yes QemuHX no Include mapping SQMP to C function name
7680
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
7781
# combination with letters
@@ -91,5 +95,6 @@ z nulltag no NONE no Include tags with empty st
9195
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
9296
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
9397
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
98+
- arityAppended yes Prolog no Include predicates with their arises
9499
- funcmap yes QemuHX no Include mapping SQMP to C function name
95100
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars

Tmain/list-extras.d/stdout-expected.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ z nulltag yes NONE no Include tags with empty st
1515
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
1616
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
1717
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
18+
- arityAppended yes Prolog no Include predicates with their arises
1819
- funcmap yes QemuHX no Include mapping SQMP to C function name
1920
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
2021
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
@@ -34,6 +35,7 @@ z nulltag yes NONE no Include tags with empty strings as their names
3435
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
3536
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
3637
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
38+
- arityAppended yes Prolog no Include predicates with their arises
3739
- funcmap yes QemuHX no Include mapping SQMP to C function name
3840
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
3941
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION

Tmain/list-fields-with-prefix.d/stdout-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ x UCTAGSxpath no NONE s-- no -- xpath for
4141
- UCTAGSprotocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
4242
- UCTAGShome yes Passwd s-- no rw home directory
4343
- UCTAGSshell yes Passwd s-- no rw login shell
44+
- UCTAGSarity yes Prolog -i- no rw arity of predicate
4445
- UCTAGSdecorators no Python s-- no -- decorators on functions and classes
4546
- UCTAGSnameref yes Python s-- no -- the original name for the tag
4647
- UCTAGSassignmentop no R s-- no -- operator for assignment

Tmain/list-fields.d/stdout-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
5959
- protocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
6060
- home yes Passwd s-- no rw home directory
6161
- shell yes Passwd s-- no rw login shell
62+
- arity yes Prolog -i- no rw arity of predicate
6263
- decorators no Python s-- no -- decorators on functions and classes
6364
- nameref yes Python s-- no -- the original name for the tag
6465
- assignmentop no R s-- no -- operator for assignment
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-G
2+
--sort=no
3+
--extras=+q
4+
--fields=+neEK
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
unicode_file_name input.pl /^unicode_file_name(Name) :-$/;" predicate line:44 end:47 arity:1
2+
unicode_file_name/1 input.pl /^unicode_file_name(Name) :-$/;" predicate line:44 extras:arityAppended end:47 arity:1
3+
unicode_file input.pl /^unicode_file(mkdir-1) :- % create Cyrillic directory$/;" predicate line:49 end:58 arity:1
4+
unicode_file/1 input.pl /^unicode_file(mkdir-1) :- % create Cyrillic directory$/;" predicate line:49 extras:arityAppended end:58 arity:1
5+
unicode_file input.pl /^unicode_file(file-1) :- % create Cyrillic file$/;" predicate line:59 end:71 arity:1
6+
unicode_file/1 input.pl /^unicode_file(file-1) :- % create Cyrillic file$/;" predicate line:59 extras:arityAppended end:71 arity:1
7+
unicode_file input.pl /^unicode_file(absfile-1) :-$/;" predicate line:72 end:78 arity:1
8+
unicode_file/1 input.pl /^unicode_file(absfile-1) :-$/;" predicate line:72 extras:arityAppended end:78 arity:1
9+
unicode_file input.pl /^unicode_file(ext-1) :-$/;" predicate line:79 end:83 arity:1
10+
unicode_file/1 input.pl /^unicode_file(ext-1) :-$/;" predicate line:79 extras:arityAppended end:83 arity:1
11+
seek input.pl /^seek(write-1) :-$/;" predicate line:90 end:108 arity:1
12+
seek/1 input.pl /^seek(write-1) :-$/;" predicate line:90 extras:arityAppended end:108 arity:1

Units/parser-prolog.r/code.d/input.pl

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
% Taken from pl-9.2.9-build/swipl-9.2.9/src/test.pl
2+
% 0'. can be a troble.
3+
4+
/* Part of SWI-Prolog
5+
6+
Author: Jan Wielemaker and Anjo Anjewierden
7+
8+
WWW: http://www.swi-prolog.org
9+
Copyright (c) 1996-2023, University of Amsterdam
10+
VU University Amsterdam
11+
CWI, Amsterdam
12+
SWI-Prolog Solutions b.v.
13+
All rights reserved.
14+
15+
Redistribution and use in source and binary forms, with or without
16+
modification, are permitted provided that the following conditions
17+
are met:
18+
19+
1. Redistributions of source code must retain the above copyright
20+
notice, this list of conditions and the following disclaimer.
21+
22+
2. Redistributions in binary form must reproduce the above copyright
23+
notice, this list of conditions and the following disclaimer in
24+
the documentation and/or other materials provided with the
25+
distribution.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38+
POSSIBILITY OF SUCH DAMAGE.
39+
*/
40+
/*******************************
41+
* UNICODE FILENAMES *
42+
*******************************/
43+
44+
unicode_file_name(Name) :-
45+
current_prolog_flag(pid, Pid),
46+
atom_codes(Name0, [1074, 1086, 1079, 1076, 1091, 1093, 1072]),
47+
atomic_list_concat([Name0, -, Pid], Name).
48+
49+
unicode_file(mkdir-1) :- % create Cyrillic directory
50+
unicode_file_name(Dir),
51+
catch(delete_directory(Dir), _, true),
52+
make_directory(Dir),
53+
exists_directory(Dir),
54+
working_directory(Old, Dir),
55+
working_directory(O2, '..'),
56+
same_file(Old, '.'),
57+
same_file(O2, Dir),
58+
delete_directory(Dir).
59+
unicode_file(file-1) :- % create Cyrillic file
60+
unicode_file_name(File),
61+
Term = hello(world),
62+
catch(delete_file(File), _, true),
63+
open(File, write, Out),
64+
format(Out, '~q.~n', [Term]),
65+
close(Out),
66+
exists_file(File),
67+
open(File, read, In),
68+
read(In, Read),
69+
close(In),
70+
Read =@= Term,
71+
delete_file(File).
72+
unicode_file(absfile-1) :-
73+
unicode_file_name(File),
74+
absolute_file_name(File, Path),
75+
file_directory_name(Path, Dir),
76+
same_file(Dir, '.'),
77+
file_base_name(Path, Base),
78+
Base == File.
79+
unicode_file(ext-1) :-
80+
atom_codes(File, [1074, 1086, 1079, 1076, 0'., 1091, 1093, 1072]),
81+
file_name_extension(Base, Ext, File),
82+
atom_codes(Base, [1074, 1086, 1079, 1076]),
83+
atom_codes(Ext, [1091, 1093, 1072]).
84+
85+
86+
/*******************************
87+
* SEEK *
88+
*******************************/
89+
90+
seek(write-1) :-
91+
tmp_file(seek, File),
92+
open(File, write, S, [type(binary)]),
93+
Max = 999,
94+
forall(between(0, Max, _),
95+
format(S, '1234567890~n', [])),
96+
forall(between(0, Max, N),
97+
( Pos is N * 11 + 6,
98+
seek(S, Pos, bof, _),
99+
format(S, 'x', [])
100+
)),
101+
close(S),
102+
103+
open(File, read, In, [type(binary)]),
104+
atom_codes('123456x890\n', Bytes),
105+
forall(between(0, Max, N),
106+
must_read(Bytes, In)),
107+
close(In),
108+
delete_file(File).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-G
2+
--sort=no
3+
--fields=+neEK
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
server input.pl /^server :-$/;" predicate line:27 end:28 arity:0
2+
server/0 input.pl /^server :-$/;" predicate line:27 extras:arityAppended end:28 arity:0
3+
server input.pl /^server(Port, Options) :-$/;" predicate line:30 end:35 arity:2
4+
server/2 input.pl /^server(Port, Options) :-$/;" predicate line:30 extras:arityAppended end:35 arity:2
5+
reply input.pl /^reply(Request) :-$/;" predicate line:37 end:39 arity:1
6+
reply/1 input.pl /^reply(Request) :-$/;" predicate line:37 extras:arityAppended end:39 arity:1
7+
reply input.pl /^reply(\/, _Request) :-$/;" predicate line:41 end:45 arity:2
8+
reply/2 input.pl /^reply(\/, _Request) :-$/;" predicate line:41 extras:arityAppended end:45 arity:2
9+
reply input.pl /^reply('\/calc', Request) :-$/;" predicate line:47 end:56 arity:2
10+
reply/2 input.pl /^reply('\/calc', Request) :-$/;" predicate line:47 extras:arityAppended end:56 arity:2
11+
page input.pl /^page(Formula) :-$/;" predicate line:59 end:74 arity:1
12+
page/1 input.pl /^page(Formula) :-$/;" predicate line:59 extras:arityAppended end:74 arity:1
13+
formula input.pl /^formula(Formula) -->$/;" grammar line:76 end:80 arity:1
14+
formula/1 input.pl /^formula(Formula) -->$/;" grammar line:76 extras:arityAppended end:80 arity:1
15+
ops input.pl /^ops -->$/;" grammar line:82 end:88 arity:0
16+
ops/0 input.pl /^ops -->$/;" grammar line:82 extras:arityAppended end:88 arity:0
17+
reply_page input.pl /^reply_page(Title, Content) :-$/;" predicate line:90 end:93 arity:2
18+
reply_page/2 input.pl /^reply_page(Title, Content) :-$/;" predicate line:90 extras:arityAppended end:93 arity:2

Units/parser-prolog.r/dcg.d/input.pl

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
% Taken from swipl-9.2.9
2+
/* $Id$
3+
4+
Part of SWI-Prolog
5+
6+
Author: Jan Wielemaker
7+
8+
WWW: http://www.swi-prolog.org
9+
Copyright (C): Public domain
10+
*/
11+
12+
:- use_module(library('http/thread_httpd')).
13+
:- use_module(library('http/html_write')).
14+
:- use_module(library('http/http_session')).
15+
:- use_module(library('http/http_error')).
16+
17+
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18+
This demo shows session state management in a very simple calculator
19+
package. It also demonstrates the use of the html_write library. To use
20+
it, start Prolog, load this file and run
21+
22+
?- server.
23+
24+
Now direct your browser to http://localhost:3000/
25+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
26+
27+
server :-
28+
server(3000, []).
29+
30+
server(Port, Options) :-
31+
http_server(reply,
32+
[ port(Port),
33+
timeout(20)
34+
| Options
35+
]).
36+
37+
reply(Request) :-
38+
memberchk(path(Path), Request),
39+
reply(Path, Request).
40+
41+
reply(/, _Request) :-
42+
http_session_retractall(formula(_)),
43+
Formula = 0,
44+
http_session_assert(formula(Formula)),
45+
page(Formula).
46+
47+
reply('/calc', Request) :-
48+
memberchk(search(Search), Request),
49+
memberchk(operation=Op, Search),
50+
memberchk(value=AtomVal, Search),
51+
atom_number(AtomVal, Val),
52+
http_session_retract(formula(Formula0)),
53+
debug(calc, 'Formula0 = ~w', [Formula0]),
54+
Formula =.. [Op, Formula0, Val],
55+
http_session_assert(formula(Formula)),
56+
page(Formula).
57+
58+
59+
page(Formula) :-
60+
reply_page('HTTP Session DEMO',
61+
[ h2('Simple session demo'),
62+
form([ action('/calc'),
63+
method('GET')
64+
],
65+
table([align(center), border(1)],
66+
[ tr(td(\formula(Formula))),
67+
tr(td([ \ops,
68+
input([ name(value) ]),
69+
input([ type(submit),
70+
value('Calc!')
71+
])
72+
]))
73+
]))
74+
]).
75+
76+
formula(Formula) -->
77+
{ sformat(S, '~w', [Formula]),
78+
Value is Formula
79+
},
80+
html([ S, ' = ', Value ]).
81+
82+
ops -->
83+
html(select(name(operation),
84+
[ option([selected], +),
85+
option([], -),
86+
option([], /),
87+
option([], *)
88+
])).
89+
90+
reply_page(Title, Content) :-
91+
phrase(page(title(Title), Content), HTML),
92+
format('Content-type: text/html~n~n'),
93+
print_html(HTML).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-G
2+
--sort=no
3+
--extras=+q
4+
--fields=+neEK

0 commit comments

Comments
 (0)