Parse joy definitions from text.

This way a definitions file can be shared between Python Joy and Prolog Joy.
This commit is contained in:
Simon Forman 2019-07-15 12:53:48 -07:00
parent 166355dccf
commit 087c141c72
1 changed files with 8 additions and 1 deletions

View File

@ -41,13 +41,20 @@ joy_parse([]) --> [].
joy_term(N) --> number(N), !.
joy_term(J) --> "[", !, joy_parse(J), "]".
joy_term(C) --> chars(Chars), !, {atom_string(C, Chars)}.
joy_term(C) --> symbol(C).
symbol(C) --> chars(Chars), !, {Chars \= [61, 61], atom_string(C, Chars)}.
chars([Ch|Rest]) --> char(Ch), chars(Rest).
chars([Ch]) --> char(Ch).
char(Ch) --> [Ch], {Ch \== 91, Ch \== 93, code_type(Ch, graph)}.
joy_def(Def Body) --> symbol(Def), blanks, "==", joy_parse(Body).
joy_defs([Def|Defs]) --> blanks, joy_def(Def), blanks, joy_defs(Defs).
joy_defs([]) --> [].
/*
Interpreter
thun(Expression, InputStack, OutputStack)