]> Repositorios git - scryer-prolog.git/commitdiff
Working lines DCG
authorMatthieu Wipliez <[email protected]>
Fri, 8 May 2020 21:20:40 +0000 (23:20 +0200)
committerMatthieu Wipliez <[email protected]>
Fri, 8 May 2020 21:20:40 +0000 (23:20 +0200)
src/prolog/examples/defs.txt [new file with mode: 0644]
src/prolog/examples/thun.pl

diff --git a/src/prolog/examples/defs.txt b/src/prolog/examples/defs.txt
new file mode 100644 (file)
index 0000000..8d4e61b
--- /dev/null
@@ -0,0 +1,9 @@
+[   [[abs] ii <=]
+        [
+            [<>] [pop !-] ||
+        ] &&
+    ]
+    [[    !-] [[++]] [[--]] ifte dip]
+    [[pop !-]  [--]   [++]  ifte    ]
+    ifte
+
index a087872550fa6862a68240a3f0128323ea3f001b..674461a79b3208485f60ed6e2ac5827b66f911cd 100644 (file)
@@ -425,10 +425,7 @@ prepare_mapping(    Pl, S, [T|In],                                  Acc,  Out) :
 joy_def --> joy_parse([symbol(Name)|Body]), { assert_def(Name, Body) }.
 
 assert_defs(DefsFile) :-
-    write("hello~n"),
-    format("hello = ~w~n", hello),
     phrase_from_file(lines(Lines), DefsFile),
-    format("lines = ~w~n", Lines),
     maplist(phrase(joy_def), Lines).
 
 assert_def(Symbol, Body) :-
@@ -442,12 +439,15 @@ assert_def(Symbol, Body) :-
 
 % Split on newline chars a list of codes into a list of lists of codes
 % one per line.  Helper function.
-lines([]) --> [].
-lines([Line|Lines]) --> line(Line), lines(Lines).
-line([]) --> '\n', !, [].
-line([H|T]) --> [H], line(T).
+lines([])     --> call(eos), !.
+lines([L|Ls]) --> line(L), lines(Ls).
 
-:- initialization(assert_defs("defs.txt")).
+line([])     --> ( "\n" | call(eos) ), !.
+line([C|Cs]) --> [C], line(Cs).
+
+eos([], []).
+
+:- initialization(assert_defs('defs.txt')).
 
 
 % A meta function that finds the names of all available functions.