]> Repositorios git - scryer-prolog.git/commitdiff
Remove DCGs that have thrown an exception during term expansion
authorAleksy Grabowski <[email protected]>
Thu, 5 Dec 2024 10:15:42 +0000 (11:15 +0100)
committerAleks Grabowski <[email protected]>
Sun, 22 Dec 2024 09:37:32 +0000 (10:37 +0100)
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

src/lib/dcgs.pl
tests/scryer/cli/issues/not_supported_dcg_constructs.in/main.pl [new file with mode: 0644]
tests/scryer/cli/issues/not_supported_dcg_constructs.stderr [new file with mode: 0644]
tests/scryer/cli/issues/not_supported_dcg_constructs.stdout [new file with mode: 0644]
tests/scryer/cli/issues/not_supported_dcg_constructs.toml [new file with mode: 0644]

index 200e57a8e8205ca98c2bc14673f21bc79e9711f0..2dc858a46e9cc152015bcc7153a7b42334f18a8c 100644 (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)//
 % 
diff --git a/tests/scryer/cli/issues/not_supported_dcg_constructs.in/main.pl b/tests/scryer/cli/issues/not_supported_dcg_constructs.in/main.pl
new file mode 100644 (file)
index 0000000..188e02a
--- /dev/null
@@ -0,0 +1,6 @@
+:- use_module(library(dcgs)).
+
+d -->
+        (   { true } -> []
+        ;   { true } -> []
+        ).
diff --git a/tests/scryer/cli/issues/not_supported_dcg_constructs.stderr b/tests/scryer/cli/issues/not_supported_dcg_constructs.stderr
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/scryer/cli/issues/not_supported_dcg_constructs.stdout b/tests/scryer/cli/issues/not_supported_dcg_constructs.stdout
new file mode 100644 (file)
index 0000000..664e0e2
--- /dev/null
@@ -0,0 +1 @@
+   error(representation_error(dcg_body),[culprit-({true}->[])]).
diff --git a/tests/scryer/cli/issues/not_supported_dcg_constructs.toml b/tests/scryer/cli/issues/not_supported_dcg_constructs.toml
new file mode 100644 (file)
index 0000000..12c5176
--- /dev/null
@@ -0,0 +1,7 @@
+# issue 2675
+args = [
+    "-f",
+    "--no-add-history",
+    "-g", "halt",
+     "main.pl"
+]