From: Mark Thom Date: Mon, 29 Apr 2024 21:28:17 +0000 (-0600) Subject: delay instantiation errors on lists in phrase/3 until runtime (#1665, #2396) X-Git-Tag: v0.10.0~136 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=f3eea6302d72afc7994ab0cf7b39303070fdfaf5;p=scryer-prolog.git delay instantiation errors on lists in phrase/3 until runtime (#1665, #2396) --- diff --git a/src/lib/dcgs.pl b/src/lib/dcgs.pl index 787f2bab..200e57a8 100644 --- a/src/lib/dcgs.pl +++ b/src/lib/dcgs.pl @@ -246,6 +246,9 @@ seqq([Es|Ess]) --> seq(Es), seqq(Ess). Cs0 = Cs. ... --> [] | [_], ... . +% defer instantiation errors until runtime. instantiations may be made +% then. +error_goal(error(instantiation_error, _Context), _). error_goal(error(E, must_be/2), error(E, must_be/2)). error_goal(error(E, (=..)/2), error(E, (=..)/2)). error_goal(error(representation_error(dcg_body), Context), @@ -259,7 +262,11 @@ user:goal_expansion(phrase(GRBody, S, S0), GRBody2) :- E, dcgs:error_goal(E, GRBody1) ), - ( GRBody = (_:_) -> + ( E = error(instantiation_error, _), + GRBody0 = [T|Ts] -> + GRBody2 = (error:must_be(list, [T|Ts]), + lists:append([T|Ts], S0, S)) + ; GRBody = (_:_) -> GRBody2 = M:GRBody1 ; GRBody2 = GRBody1 ).