Skip to content

Commit

Permalink
Remove DCGs that have thrown an exception during term expansion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hurufu committed Dec 15, 2024
1 parent ff03432 commit ab91121
Show file tree
Hide file tree
Showing 5 changed files with 21 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,8 @@
:- use_module(library(dcgs)).
:- initialization(abolish(null/0)).
:- dynamic(null/0).

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 ab91121

Please sign in to comment.