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:
committed by
Aleks Grabowski
parent
ff03432624
commit
a599a11169
@@ -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)//
|
||||
%
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
:- use_module(library(dcgs)).
|
||||
|
||||
d -->
|
||||
( { true } -> []
|
||||
; { true } -> []
|
||||
).
|
||||
@@ -0,0 +1 @@
|
||||
error(representation_error(dcg_body),[culprit-({true}->[])]).
|
||||
@@ -0,0 +1,7 @@
|
||||
# issue 2675
|
||||
args = [
|
||||
"-f",
|
||||
"--no-add-history",
|
||||
"-g", "halt",
|
||||
"main.pl"
|
||||
]
|
||||
Reference in New Issue
Block a user