Skip to content

Prolog: new parser #4249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Tmain/extras-long.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ z nulltag no NONE no Include tags with empty st
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# enabling 1
Expand All @@ -34,6 +35,7 @@ z nulltag no NONE no Include tags with empty st
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# disabling 1
Expand All @@ -53,6 +55,7 @@ z nulltag no NONE no Include tags with empty st
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# combination
Expand All @@ -72,6 +75,7 @@ z nulltag no NONE no Include tags with empty st
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
# combination with letters
Expand All @@ -91,5 +95,6 @@ z nulltag no NONE no Include tags with empty st
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
2 changes: 2 additions & 0 deletions Tmain/list-extras.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ z nulltag yes NONE no Include tags with empty st
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
Expand All @@ -34,6 +35,7 @@ z nulltag yes NONE no Include tags with empty strings as their names
- configPrefixed yes Kconfig no prepend CONFIG_ to config names
- CppDef no Make no Include FOO in -DFOO as as a name of CPreProcessor macro
- guessedFromFileName yes PkgConfig no the guessed package name of the .pc file
- arityAppended yes Prolog no Include predicates with their arises
- funcmap yes QemuHX no Include mapping SQMP to C function name
- whitespaceSwapped yes Robot no Include tags swapping whitespace and underscore chars
#LETTER NAME ENABLED LANGUAGE FIXED DESCRIPTION
Expand Down
1 change: 1 addition & 0 deletions Tmain/list-fields-with-prefix.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ x UCTAGSxpath no NONE s-- no -- xpath for
- UCTAGSprotocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
- UCTAGShome yes Passwd s-- no rw home directory
- UCTAGSshell yes Passwd s-- no rw login shell
- UCTAGSarity yes Prolog -i- no -- the number of parameters
- UCTAGSdecorators no Python s-- no -- decorators on functions and classes
- UCTAGSnameref yes Python s-- no -- the original name for the tag
- UCTAGSassignmentop no R s-- no -- operator for assignment
Expand Down
1 change: 1 addition & 0 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
- protocols yes ObjectiveC s-- no -- protocols that the class (or category) confirms to
- home yes Passwd s-- no rw home directory
- shell yes Passwd s-- no rw login shell
- arity yes Prolog -i- no -- the number of parameters
- decorators no Python s-- no -- decorators on functions and classes
- nameref yes Python s-- no -- the original name for the tag
- assignmentop no R s-- no -- operator for assignment
Expand Down
2 changes: 2 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Perl h/heredoc endmarker on end marker
PkgConfig p/pkg conflicted on confliected
PkgConfig p/pkg provided on provided
PkgConfig p/pkg required on required
Prolog m/module chainElt off (EXPERIMENTAL)used as an element in a module-qualified atom like module:predicate
Protobuf D/protodef imported on imported
Protobuf m/message extension on extending the message
Python Y/unknown imported on imported from the other module
Expand Down Expand Up @@ -244,6 +245,7 @@ Perl h/heredoc endmarker on end marker
PkgConfig p/pkg conflicted on confliected
PkgConfig p/pkg provided on provided
PkgConfig p/pkg required on required
Prolog m/module chainElt off (EXPERIMENTAL)used as an element in a module-qualified atom like module:predicate
Protobuf D/protodef imported on imported
Protobuf m/message extension on extending the message
Python Y/unknown imported on imported from the other module
Expand Down
4 changes: 4 additions & 0 deletions Units/parser-prolog.r/code.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-G
--sort=no
--extras=+q
--fields=+neEK
12 changes: 12 additions & 0 deletions Units/parser-prolog.r/code.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unicode_file_name input.pl /^unicode_file_name(Name) :-$/;" predicate line:44 end:47 arity:1
unicode_file_name/1 input.pl /^unicode_file_name(Name) :-$/;" predicate line:44 extras:arityAppended end:47 arity:1
unicode_file input.pl /^unicode_file(mkdir-1) :- % create Cyrillic directory$/;" predicate line:49 end:58 arity:1
unicode_file/1 input.pl /^unicode_file(mkdir-1) :- % create Cyrillic directory$/;" predicate line:49 extras:arityAppended end:58 arity:1
unicode_file input.pl /^unicode_file(file-1) :- % create Cyrillic file$/;" predicate line:59 end:71 arity:1
unicode_file/1 input.pl /^unicode_file(file-1) :- % create Cyrillic file$/;" predicate line:59 extras:arityAppended end:71 arity:1
unicode_file input.pl /^unicode_file(absfile-1) :-$/;" predicate line:72 end:78 arity:1
unicode_file/1 input.pl /^unicode_file(absfile-1) :-$/;" predicate line:72 extras:arityAppended end:78 arity:1
unicode_file input.pl /^unicode_file(ext-1) :-$/;" predicate line:79 end:83 arity:1
unicode_file/1 input.pl /^unicode_file(ext-1) :-$/;" predicate line:79 extras:arityAppended end:83 arity:1
seek input.pl /^seek(write-1) :-$/;" predicate line:90 end:108 arity:1
seek/1 input.pl /^seek(write-1) :-$/;" predicate line:90 extras:arityAppended end:108 arity:1
108 changes: 108 additions & 0 deletions Units/parser-prolog.r/code.d/input.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
% Taken from pl-9.2.9-build/swipl-9.2.9/src/test.pl
% 0'. can be a troble.

/* Part of SWI-Prolog

Author: Jan Wielemaker and Anjo Anjewierden
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 1996-2023, University of Amsterdam
VU University Amsterdam
CWI, Amsterdam
SWI-Prolog Solutions b.v.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*******************************
* UNICODE FILENAMES *
*******************************/

unicode_file_name(Name) :-
current_prolog_flag(pid, Pid),
atom_codes(Name0, [1074, 1086, 1079, 1076, 1091, 1093, 1072]),
atomic_list_concat([Name0, -, Pid], Name).

unicode_file(mkdir-1) :- % create Cyrillic directory
unicode_file_name(Dir),
catch(delete_directory(Dir), _, true),
make_directory(Dir),
exists_directory(Dir),
working_directory(Old, Dir),
working_directory(O2, '..'),
same_file(Old, '.'),
same_file(O2, Dir),
delete_directory(Dir).
unicode_file(file-1) :- % create Cyrillic file
unicode_file_name(File),
Term = hello(world),
catch(delete_file(File), _, true),
open(File, write, Out),
format(Out, '~q.~n', [Term]),
close(Out),
exists_file(File),
open(File, read, In),
read(In, Read),
close(In),
Read =@= Term,
delete_file(File).
unicode_file(absfile-1) :-
unicode_file_name(File),
absolute_file_name(File, Path),
file_directory_name(Path, Dir),
same_file(Dir, '.'),
file_base_name(Path, Base),
Base == File.
unicode_file(ext-1) :-
atom_codes(File, [1074, 1086, 1079, 1076, 0'., 1091, 1093, 1072]),
file_name_extension(Base, Ext, File),
atom_codes(Base, [1074, 1086, 1079, 1076]),
atom_codes(Ext, [1091, 1093, 1072]).


/*******************************
* SEEK *
*******************************/

seek(write-1) :-
tmp_file(seek, File),
open(File, write, S, [type(binary)]),
Max = 999,
forall(between(0, Max, _),
format(S, '1234567890~n', [])),
forall(between(0, Max, N),
( Pos is N * 11 + 6,
seek(S, Pos, bof, _),
format(S, 'x', [])
)),
close(S),

open(File, read, In, [type(binary)]),
atom_codes('123456x890\n', Bytes),
forall(between(0, Max, N),
must_read(Bytes, In)),
close(In),
delete_file(File).
3 changes: 3 additions & 0 deletions Units/parser-prolog.r/dcg.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-G
--sort=no
--fields=+neEK
18 changes: 18 additions & 0 deletions Units/parser-prolog.r/dcg.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server input.pl /^server :-$/;" predicate line:27 end:28 arity:0
server/0 input.pl /^server :-$/;" predicate line:27 extras:arityAppended end:28 arity:0
server input.pl /^server(Port, Options) :-$/;" predicate line:30 end:35 arity:2
server/2 input.pl /^server(Port, Options) :-$/;" predicate line:30 extras:arityAppended end:35 arity:2
reply input.pl /^reply(Request) :-$/;" predicate line:37 end:39 arity:1
reply/1 input.pl /^reply(Request) :-$/;" predicate line:37 extras:arityAppended end:39 arity:1
reply input.pl /^reply(\/, _Request) :-$/;" predicate line:41 end:45 arity:2
reply/2 input.pl /^reply(\/, _Request) :-$/;" predicate line:41 extras:arityAppended end:45 arity:2
reply input.pl /^reply('\/calc', Request) :-$/;" predicate line:47 end:56 arity:2
reply/2 input.pl /^reply('\/calc', Request) :-$/;" predicate line:47 extras:arityAppended end:56 arity:2
page input.pl /^page(Formula) :-$/;" predicate line:59 end:74 arity:1
page/1 input.pl /^page(Formula) :-$/;" predicate line:59 extras:arityAppended end:74 arity:1
formula input.pl /^formula(Formula) -->$/;" grammar line:76 end:80 arity:1
formula/1 input.pl /^formula(Formula) -->$/;" grammar line:76 extras:arityAppended end:80 arity:1
ops input.pl /^ops -->$/;" grammar line:82 end:88 arity:0
ops/0 input.pl /^ops -->$/;" grammar line:82 extras:arityAppended end:88 arity:0
reply_page input.pl /^reply_page(Title, Content) :-$/;" predicate line:90 end:93 arity:2
reply_page/2 input.pl /^reply_page(Title, Content) :-$/;" predicate line:90 extras:arityAppended end:93 arity:2
93 changes: 93 additions & 0 deletions Units/parser-prolog.r/dcg.d/input.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
% Taken from swipl-9.2.9
/* $Id$

Part of SWI-Prolog

Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (C): Public domain
*/

:- use_module(library('http/thread_httpd')).
:- use_module(library('http/html_write')).
:- use_module(library('http/http_session')).
:- use_module(library('http/http_error')).

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This demo shows session state management in a very simple calculator
package. It also demonstrates the use of the html_write library. To use
it, start Prolog, load this file and run

?- server.

Now direct your browser to http://localhost:3000/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

server :-
server(3000, []).

server(Port, Options) :-
http_server(reply,
[ port(Port),
timeout(20)
| Options
]).

reply(Request) :-
memberchk(path(Path), Request),
reply(Path, Request).

reply(/, _Request) :-
http_session_retractall(formula(_)),
Formula = 0,
http_session_assert(formula(Formula)),
page(Formula).

reply('/calc', Request) :-
memberchk(search(Search), Request),
memberchk(operation=Op, Search),
memberchk(value=AtomVal, Search),
atom_number(AtomVal, Val),
http_session_retract(formula(Formula0)),
debug(calc, 'Formula0 = ~w', [Formula0]),
Formula =.. [Op, Formula0, Val],
http_session_assert(formula(Formula)),
page(Formula).


page(Formula) :-
reply_page('HTTP Session DEMO',
[ h2('Simple session demo'),
form([ action('/calc'),
method('GET')
],
table([align(center), border(1)],
[ tr(td(\formula(Formula))),
tr(td([ \ops,
input([ name(value) ]),
input([ type(submit),
value('Calc!')
])
]))
]))
]).

formula(Formula) -->
{ sformat(S, '~w', [Formula]),
Value is Formula
},
html([ S, ' = ', Value ]).

ops -->
html(select(name(operation),
[ option([selected], +),
option([], -),
option([], /),
option([], *)
])).

reply_page(Title, Content) :-
phrase(page(title(Title), Content), HTML),
format('Content-type: text/html~n~n'),
print_html(HTML).
4 changes: 4 additions & 0 deletions Units/parser-prolog.r/module.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-G
--sort=no
--extras=+q
--fields=+neEK
Loading
Loading