From: Mark Thom Date: Wed, 3 Feb 2021 23:03:12 +0000 (-0700) Subject: introduce cuts over indexed (:)/2 of dcgs:phrase_/3 (#786) X-Git-Tag: v0.9.0~150^2~66^2~2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=a8a82e45a01fd49cc6876e8e7caf18dcc6af393f;p=scryer-prolog.git introduce cuts over indexed (:)/2 of dcgs:phrase_/3 (#786) --- diff --git a/src/lib/dcgs.pl b/src/lib/dcgs.pl index a33c870b..07b82b95 100644 --- a/src/lib/dcgs.pl +++ b/src/lib/dcgs.pl @@ -31,11 +31,12 @@ phrase(GRBody, S0, S) :- phrase_([], S, S). phrase_(!, S, S). -phrase_(_:[], S, S). -phrase_(_:!, S, S). +phrase_(_:[], S, S) :- !. +phrase_(_:!, S, S) :- !. phrase_((A, B), S0, S) :- phrase(A, S0, S1), phrase(B, S1, S). phrase_(M:(A, B), S0, S) :- + !, phrase(M:A, S0, S1), phrase(M:B, S1, S). phrase_((A -> B ; C), S0, S) :- !, @@ -52,26 +53,32 @@ phrase_(M:(A -> B ; C), S0, S) :- phrase_((A ; B), S0, S) :- ( phrase(A, S0, S) ; phrase(B, S0, S) ). phrase_(M:(A ; B), S0, S) :- + !, ( phrase(M:A, S0, S) ; phrase(M:B, S0, S) ). phrase_((A | B), S0, S) :- ( phrase(A, S0, S) ; phrase(B, S0, S) ). phrase_(M:(A | B), S0, S) :- + !, ( phrase(M:A, S0, S) ; phrase(M:B, S0, S) ). phrase_({G}, S0, S) :- ( call(G), S0 = S ). phrase_(M:{G}, S0, S) :- + !, ( call(M:G), S0 = S ). phrase_(call(G), S0, S) :- call(G, S0, S). phrase_(M:call(G), S0, S) :- + !, call(M:G, S0, S). phrase_((A -> B), S0, S) :- phrase((A -> B ; fail), S0, S). phrase_(M:(A -> B), S0, S) :- + !, phrase((M:A -> M:B ; fail), S0, S). phrase_(phrase(NonTerminal), S0, S) :- phrase(NonTerminal, S0, S). phrase_(M:phrase(NonTerminal), S0, S) :- + !, phrase(M:NonTerminal, S0, S). phrase_([T|Ts], S0, S) :- append([T|Ts], S, S0).