From: Eshel Yaron Date: Sun, 8 Oct 2023 10:35:09 +0000 (+0200) Subject: ; Improve detection of unsafe goal extraction X-Git-Tag: V9.1.16-sweep-0.25.4~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1bc9956aa88f1819c67da719f6c5c30ea73a3333;p=sweep.git ; Improve detection of unsafe goal extraction * sweep.pl (sweep_extract_goal_update_safety/4): Adjust. * sweeprolog-tests.el: Add more tests. --- diff --git a/sweep.pl b/sweep.pl index 0e61e28..6215151 100644 --- a/sweep.pl +++ b/sweep.pl @@ -1843,11 +1843,13 @@ sweep_extract_goal_update_clause_string((_;_), 2, [AltPos,_], ClauseString0, Off string_concat(ClauseString1, ClauseAfterAlt, ClauseString). sweep_extract_goal_update_clause_string(_, _, _, ClauseString, Offset, ClauseString, Offset). -sweep_extract_goal_update_safety((_,_), _, Safe, Safe) :- +sweep_extract_goal_update_safety((_,_), _, _, false) :- !. -sweep_extract_goal_update_safety((_;_), _, Safe, Safe) :- +sweep_extract_goal_update_safety((_;_), _, _, false) :- !. -sweep_extract_goal_update_safety((_->_), 2, Safe, Safe) :- +sweep_extract_goal_update_safety((_->_), 2, _, false) :- + !. +sweep_extract_goal_update_safety((_*->_), 2, _, false) :- !. sweep_extract_goal_update_safety(_, _, _, true). diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index 86d7136..b65c603 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -1852,6 +1852,42 @@ bbb(A, B, C, D) :- C = D" "true" "foo" 0 nil)))) +(sweeprolog-deftest extract-region-to-predicate-cut-1 () + "Test `sweeprolog-extract-region-to-predicate' in presence of a cut." + "" + (should + (equal + (sweeprolog--extract-goal " +bar :- + call((foo, ! ; baz)). +" + 12 32 "spam") + '("spam" "spam" ":-" "call((foo, ! ; baz))" "true" "spam" 0 nil)))) + +(sweeprolog-deftest extract-region-to-predicate-cut-2 () + "Test `sweeprolog-extract-region-to-predicate' in presence of a cut." + "" + (should + (equal + (sweeprolog--extract-goal " +bar :- + call((foo, ! ; baz)). +" + 17 31 "spam") + '("spam" "spam" ":-" "(foo, ! ; baz)" "true" "spam" 0 nil)))) + +(sweeprolog-deftest extract-region-to-predicate-cut-3 () + "Test `sweeprolog-extract-region-to-predicate' in presence of a cut." + "" + (should + (equal + (sweeprolog--extract-goal " +bar :- + call((foo, ! ; baz)). +" + 18 24 "spam") + '("spam" "spam" ":-" "foo, !" nil "spam" 0 nil)))) + (sweeprolog-deftest extract-region-to-predicate-dcg () "Test `sweeprolog-extract-region-to-predicate'." ""