From 5108f146898f16aed6fc2efd73669d25cb26b3ec Mon Sep 17 00:00:00 2001 From: Matthieu Wipliez Date: Fri, 8 May 2020 23:20:40 +0200 Subject: [PATCH] Working lines DCG --- src/prolog/examples/defs.txt | 9 +++++++++ src/prolog/examples/thun.pl | 16 ++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 src/prolog/examples/defs.txt diff --git a/src/prolog/examples/defs.txt b/src/prolog/examples/defs.txt new file mode 100644 index 00000000..8d4e61b1 --- /dev/null +++ b/src/prolog/examples/defs.txt @@ -0,0 +1,9 @@ +[ [[abs] ii <=] + [ + [<>] [pop !-] || + ] && + ] + [[ !-] [[++]] [[--]] ifte dip] + [[pop !-] [--] [++] ifte ] + ifte + diff --git a/src/prolog/examples/thun.pl b/src/prolog/examples/thun.pl index a0878725..674461a7 100644 --- a/src/prolog/examples/thun.pl +++ b/src/prolog/examples/thun.pl @@ -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. -- 2.54.0