Skip to content

Commit c71080d

Browse files
authored
Merge pull request #4249 from masatake/prolog
Prolog: new parser
2 parents 876e82a + c99c2f4 commit c71080d

File tree

37 files changed

+1462
-16
lines changed

37 files changed

+1462
-16
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 1 Include tags with empt
1515
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
1616
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
1717
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
18+
- arityAppended yes Prolog no 0 Include predicates with their arities
1819
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
1920
- whitespaceSwapped yes Robot no 0 Include tags swapping whitespace and underscore chars
2021
# enabling 1
@@ -34,6 +35,7 @@ z nulltag no NONE no 1 Include tags with empt
3435
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
3536
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
3637
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
38+
- arityAppended yes Prolog no 0 Include predicates with their arities
3739
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
3840
- whitespaceSwapped yes Robot no 0 Include tags swapping whitespace and underscore chars
3941
# disabling 1
@@ -53,6 +55,7 @@ z nulltag no NONE no 1 Include tags with empt
5355
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
5456
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
5557
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
58+
- arityAppended yes Prolog no 0 Include predicates with their arities
5659
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
5760
- whitespaceSwapped yes Robot no 0 Include tags swapping whitespace and underscore chars
5861
# combination
@@ -72,6 +75,7 @@ z nulltag no NONE no 1 Include tags with empt
7275
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
7376
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
7477
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
78+
- arityAppended yes Prolog no 0 Include predicates with their arities
7579
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
7680
- whitespaceSwapped yes Robot no 0 Include tags swapping whitespace and underscore chars
7781
# combination with letters
@@ -91,5 +95,6 @@ z nulltag no NONE no 1 Include tags with empt
9195
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
9296
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
9397
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
98+
- arityAppended yes Prolog no 0 Include predicates with their arities
9499
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
95100
- whitespaceSwapped yes Robot no 0 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 1 Include tags with empt
1515
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
1616
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
1717
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
18+
- arityAppended yes Prolog no 0 Include predicates with their arities
1819
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
1920
- whitespaceSwapped yes Robot no 0 Include tags swapping whitespace and underscore chars
2021
#LETTER NAME ENABLED LANGUAGE FIXED VER DESCRIPTION
@@ -34,6 +35,7 @@ z nulltag yes NONE no 1 Include tags with empty strings as their names
3435
- configPrefixed yes Kconfig no 0 prepend CONFIG_ to config names
3536
- CppDef no Make no 1 Include FOO in -DFOO as as a name of CPreProcessor macro
3637
- guessedFromFileName yes PkgConfig no 0 the guessed package name of the .pc file
38+
- arityAppended yes Prolog no 0 Include predicates with their arities
3739
- funcmap yes QemuHX no 0 Include mapping SQMP to C function name
3840
- whitespaceSwapped yes Robot no 0 Include tags swapping whitespace and underscore chars
3941
#LETTER NAME ENABLED LANGUAGE FIXED VER DESCRIPTION

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

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ z kind no NONE s-- no r- 0 [tags output] prepend "kind:" to k/ (or K/) field out
6060
- protocols yes ObjectiveC s-- no -- 0 protocols that the class (or category) confirms to
6161
- home yes Passwd s-- no rw 0 home directory
6262
- shell yes Passwd s-- no rw 0 login shell
63+
- arity yes Prolog -i- no -- 0 the number of parameters
6364
- decorators no Python s-- no -- 0 decorators on functions and classes
6465
- nameref yes Python s-- no -- 0 the original name for the tag
6566
- assignmentop no R s-- no -- 0 operator for assignment

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# ALL
2-
#LANGUAGE NAME DESCRIPTION
3-
Asm commentCharsAtBOL line comment chraracters at the beginning of line ([;*@])
4-
Asm commentCharsInMOL line comment chraracters in the beginning of line ([])
5-
Asm extraLinesepChars extra characters used as a line separator ([])
6-
Asm useCPreProcessor run CPreProcessor parser for extracting macro definitions ([true] or false)
7-
CPreProcessor _expand expand macros if their definitions are in the current C/C++/CUDA input file (true or [false])
8-
CPreProcessor define define replacement for an identifier (name(params,...)=definition)
9-
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
10-
CPreProcessor ignore a token to be specially handled
11-
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
12-
ITcl forceUse enable the parser even when `itcl' namespace is not specified in the input (true or [false])
13-
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
2+
#LANGUAGE NAME DESCRIPTION
3+
Asm commentCharsAtBOL line comment chraracters at the beginning of line ([;*@])
4+
Asm commentCharsInMOL line comment chraracters in the beginning of line ([])
5+
Asm extraLinesepChars extra characters used as a line separator ([])
6+
Asm useCPreProcessor run CPreProcessor parser for extracting macro definitions ([true] or false)
7+
CPreProcessor _expand expand macros if their definitions are in the current C/C++/CUDA input file (true or [false])
8+
CPreProcessor define define replacement for an identifier (name(params,...)=definition)
9+
CPreProcessor if0 examine code within "#if 0" branch (true or [false])
10+
CPreProcessor ignore a token to be specially handled
11+
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
12+
ITcl forceUse enable the parser even when `itcl' namespace is not specified in the input (true or [false])
13+
Prolog allowNestedComments allow nested comments like "/* /* */ */" ([true] or false)
14+
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
1415

1516
# ALL MACHINABLE
1617
#LANGUAGE NAME DESCRIPTION
@@ -24,6 +25,7 @@ CPreProcessor if0 examine code within "#if 0" branch (true or [false])
2425
CPreProcessor ignore a token to be specially handled
2526
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
2627
ITcl forceUse enable the parser even when `itcl' namespace is not specified in the input (true or [false])
28+
Prolog allowNestedComments allow nested comments like "/* /* */ */" ([true] or false)
2729
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
2830

2931
# ALL MACHINABLE NOHEADER
@@ -37,6 +39,7 @@ CPreProcessor if0 examine code within "#if 0" branch (true or [false])
3739
CPreProcessor ignore a token to be specially handled
3840
Fypp guest parser run after Fypp parser parses the original input ("NONE" or a parser name [Fortran])
3941
ITcl forceUse enable the parser even when `itcl' namespace is not specified in the input (true or [false])
42+
Prolog allowNestedComments allow nested comments like "/* /* */ */" ([true] or false)
4043
TclOO forceUse enable the parser even when `oo' namespace is not specified in the input (true or [false])
4144

4245
# CPP

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Perl h/heredoc endmarker on 0 end mar
9898
PkgConfig p/pkg conflicted on 0 conflicted
9999
PkgConfig p/pkg provided on 0 provided
100100
PkgConfig p/pkg required on 0 required
101+
Prolog m/module chainElt off 0 (EXPERIMENTAL)used as an element in a module-qualified atom like module:predicate
101102
Protobuf D/protodef imported on 0 imported
102103
Protobuf m/message extension on 0 extending the message
103104
Python Y/unknown imported on 0 imported from the other module
@@ -248,6 +249,7 @@ Perl h/heredoc endmarker on 0 end mar
248249
PkgConfig p/pkg conflicted on 0 conflicted
249250
PkgConfig p/pkg provided on 0 provided
250251
PkgConfig p/pkg required on 0 required
252+
Prolog m/module chainElt off 0 (EXPERIMENTAL)used as an element in a module-qualified atom like module:predicate
251253
Protobuf D/protodef imported on 0 imported
252254
Protobuf m/message extension on 0 extending the message
253255
Python Y/unknown imported on 0 imported from the other module
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
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 trouble.
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

0 commit comments

Comments
 (0)