Merge pull request #2681 from hurufu/remove-dcgs-that-have-failed-to-expand

Remove DCGs that have thrown an exception during term expansion
This commit is contained in:
Mark Thom
2024-12-25 14:29:38 -07:00
committed by GitHub
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"
]