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:
@@ -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