Skip to content

Commit

Permalink
Merge pull request #2681 from hurufu/remove-dcgs-that-have-failed-to-…
Browse files Browse the repository at this point in the history
…expand

Remove DCGs that have thrown an exception during term expansion
  • Loading branch information
mthom authored Dec 25, 2024
2 parents afc7b74 + a599a11 commit d57f871
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/dcgs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@
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)//
%
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:- use_module(library(dcgs)).

d -->
( { true } -> []
; { true } -> []
).
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error(representation_error(dcg_body),[culprit-({true}->[])]).
7 changes: 7 additions & 0 deletions tests/scryer/cli/issues/not_supported_dcg_constructs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# issue 2675
args = [
"-f",
"--no-add-history",
"-g", "halt",
"main.pl"
]

0 comments on commit d57f871

Please sign in to comment.