Remove DCGs that have thrown an exception during term expansion

Some DCG constructs aren't supported and can't be expanded, here we
remove offending DCG rule and don't compile it at all – in a similar
fashion to what we do when incorrect goal was found – whole predicate
isn't getting compiled.

Fixes #2675
This commit is contained in:
Aleksy Grabowski
2024-12-05 11:15:42 +01:00
committed by Aleks Grabowski
parent ff03432624
commit a599a11169
5 changed files with 19 additions and 2 deletions

View File

@@ -214,10 +214,13 @@ dcg_cbody(( GRIf -> GRThen ), S0, S, ( If -> Then )) :-
dcg_body(GRIf, S0, S1, If),
dcg_body(GRThen, S1, S, Then).
% When DCG expansion throws an exception remove offending term and rethrow.
user:term_expansion(throw_dcg_expansion_error(E), _) :-
throw(E).
user:term_expansion(Term0, Term) :-
nonvar(Term0),
dcg_rule(Term0, Term).
catch(dcg_rule(Term0, Term), E, Term = throw_dcg_expansion_error(E)).
%% seq(Seq)//
%

View File

@@ -0,0 +1,6 @@
:- use_module(library(dcgs)).
d -->
( { true } -> []
; { true } -> []
).

View File

@@ -0,0 +1 @@
error(representation_error(dcg_body),[culprit-({true}->[])]).

View File

@@ -0,0 +1,7 @@
# issue 2675
args = [
"-f",
"--no-add-history",
"-g", "halt",
"main.pl"
]