• R/O
  • SSH

Joypy: コミット

Main interpreter and library.


コミットメタ情報

リビジョン0dd62c4d489599ce040df95faa7881163280ce63 (tree)
日時2019-08-14 03:48:08
作者Simon Forman <sforman@hush...>
コミッターSimon Forman

ログメッセージ

Move DCG stuff to own file.

変更サマリ

差分

diff -r 4a55a817f3f0 -r 0dd62c4d4895 .hgignore
--- a/.hgignore Tue Aug 13 11:29:49 2019 -0700
+++ b/.hgignore Tue Aug 13 11:48:08 2019 -0700
@@ -5,4 +5,4 @@
55 .vscode
66 docs/.ipynb_checkpoints
77 test/*
8-thun
8+gnu-prolog/thun
diff -r 4a55a817f3f0 -r 0dd62c4d4895 thun/gnu-prolog/DCG_basics.pl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/thun/gnu-prolog/DCG_basics.pl Tue Aug 13 11:48:08 2019 -0700
@@ -0,0 +1,59 @@
1+/*
2+ Copyright 2019 Simon Forman
3+
4+ This file is part of Thun
5+
6+ Thun is free software: you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation, either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ Thun is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ You should have received a copy of the GNU General Public License
17+ along with Thun. If not see <http://www.gnu.org/licenses/>.
18+
19+
20+DCG basics. For some of this I cribbed the source from SWI library code
21+and adapted it for GNU Prolog Compiler.
22+
23+N.B. is_glyph//1 excludes '[' and ']' characters. D'oh! FIXME
24+
25+*/
26+
27+
28+:- set_prolog_flag(double_quotes, codes).
29+
30+
31+% TODO: scientific notation.
32+
33+signed_float_or_integer(Codes) --> signed_digits(J), ".", !, digits(I),
34+ { append(J, [0'.|I], Codes) }.
35+signed_float_or_integer(Codes) --> signed_digits(Codes).
36+
37+signed_digits([0'-|Codes]) --> "-", !, digits(Codes).
38+signed_digits( Codes ) --> digits(Codes).
39+
40+% Groups of characters.
41+
42+chars(Chars) --> one_or_more(char, Chars).
43+blanks --> blank, !, blanks | [].
44+digits(Digits) --> one_or_more(digit, Digits).
45+
46+% Character types.
47+
48+char(Ch) --> [Ch], { nonvar(Ch), is_glyph(Ch) }.
49+blank --> [Ch], { nonvar(Ch), is_space(Ch) }.
50+digit(Ch) --> [Ch], { nonvar(Ch), between(0'0, 0'9, Ch) }.
51+
52+is_glyph(Ch) :- Ch =\= 0'[, Ch =\= 0'], between(0'!, 0'~, Ch).
53+is_space(Ch) :- Ch =:= 32 ; between(9, 13, Ch).
54+
55+one_or_more(E, List) --> one_or_more_(List, E).
56+
57+one_or_more_([Ch|Rest], P) --> call(P, Ch), one_or_more_(Rest, P).
58+one_or_more_([Ch], P) --> call(P, Ch).
59+
diff -r 4a55a817f3f0 -r 0dd62c4d4895 thun/gnu-prolog/Makefile
--- a/thun/gnu-prolog/Makefile Tue Aug 13 11:29:49 2019 -0700
+++ b/thun/gnu-prolog/Makefile Tue Aug 13 11:48:08 2019 -0700
@@ -2,14 +2,15 @@
22 GPLC_OPTIONS=--no-top-level
33 #GPLC_OPTIONS=
44
5-thun: thun.pl parser.pl defs.pl main.pl math.pl Makefile
6- gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl defs.pl main.pl math.pl
5+thun: thun.pl parser.pl defs.pl main.pl math.pl DCG_basics.pl Makefile
6+ gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl defs.pl main.pl DCG_basics.pl math.pl
77
8-defs.pl: meta-defs.pl parser.pl defs.txt thun.pl
8+defs.pl: meta-defs.pl parser.pl defs.txt thun.pl DCG_basics.pl
99 gprolog \
1010 --consult-file meta-defs.pl \
1111 --consult-file parser.pl \
1212 --consult-file thun.pl \
13+ --consult-file DCG_basics.pl \
1314 --query-goal do
1415
1516 math.pl: meta-math.pl
diff -r 4a55a817f3f0 -r 0dd62c4d4895 thun/gnu-prolog/parser.pl
--- a/thun/gnu-prolog/parser.pl Tue Aug 13 11:29:49 2019 -0700
+++ b/thun/gnu-prolog/parser.pl Tue Aug 13 11:48:08 2019 -0700
@@ -37,38 +37,10 @@
3737 num(N) --> number_digits(Codes), { number_codes(N, Codes) }.
3838
3939 number_digits(Codes) --> signed_float_or_integer(Codes), !, end_num.
40-% TODO: floats, scientific notation.
41-
42-signed_float_or_integer(Codes) --> signed_digits(J), ".", !, digits(I),
43- { append(J, [0'.|I], Codes) }.
44-signed_float_or_integer(Codes) --> signed_digits(Codes).
45-
46-signed_digits([45|Codes]) --> "-", !, digits(Codes).
47-signed_digits( Codes ) --> digits(Codes).
4840
4941 end_num, [Ch] --> [Ch], { [Ch] = "[" ; is_space(Ch) }.
5042 end_num([], []).
5143
52-% Groups of characters.
53-
54-chars(Chars) --> one_or_more(char, Chars).
55-blanks --> blank, !, blanks | [].
56-digits(Digits) --> one_or_more(digit, Digits).
57-
58-% Character types.
59-
60-char(Ch) --> [Ch], { nonvar(Ch), is_glyph(Ch) }.
61-blank --> [Ch], { nonvar(Ch), is_space(Ch) }.
62-digit(Ch) --> [Ch], { nonvar(Ch), between(0'0, 0'9, Ch) }.
63-
64-is_glyph(Ch) :- Ch =\= 0'[, Ch =\= 0'], between(0'!, 0'~, Ch).
65-is_space(Ch) :- Ch =:= 32 ; between(9, 13, Ch).
66-
67-one_or_more(E, List) --> one_or_more_(List, E).
68-
69-one_or_more_([Ch|Rest], P) --> call(P, Ch), one_or_more_(Rest, P).
70-one_or_more_([Ch], P) --> call(P, Ch).
71-
7244
7345 /*
7446
旧リポジトリブラウザで表示