]> git.eshelyaron.com Git - sweep.git/commitdiff
ENHANCED: Export DCG non-terminals as 'foo//N', not 'foo/N+2'
authorEshel Yaron <me@eshelyaron.com>
Tue, 6 Jun 2023 05:17:33 +0000 (08:17 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 6 Jun 2023 05:17:33 +0000 (08:17 +0300)
* sweep.pl (strip_det/2): Handle DCG non-terminals with determinism
specification.
(sweep_local_predicate_export_comment/2, sweep_exportable_predicates/2)
* sweeprolog.el (sweeprolog-local-export-comment)
(sweeprolog-local-export-comment): Adapt for DCG non-terminals.

sweep.pl
sweeprolog.el

index 31aa7594a0c6ce7c606ef165c08e91f9ce79937e..e92d632c2ae0ee0759610bfbdb59313b1bf0a377 100644 (file)
--- a/sweep.pl
+++ b/sweep.pl
@@ -792,12 +792,14 @@ sweep_thread_signal([ThreadId|Goal0], _) :-
     term_string(Goal, Goal0),
     thread_signal(ThreadId, Goal).
 
-sweep_local_predicate_export_comment([Path0,F0,A],Comm) :-
+sweep_local_predicate_export_comment([Path0,F0,A,I0],Comm) :-
     atom_string(Path, Path0),
     atom_string(F, F0),
-    doc_comment(_:F/A, Path:_, _Summary, Comment),
+    atom_string(I, I0),
+    compound_name_arguments(PI, I, [F,A]),
+    doc_comment(_:PI, Path:_, _Summary, Comment),
     comment_modes(Comment, Modes),
-    pi_head(F/A, Head),
+    compound_name_arity(Head, F, A),
     member(ModeAndDet, Modes),
     strip_det(ModeAndDet, Head),
     Head =.. [_|Args],
@@ -808,6 +810,7 @@ sweep_local_predicate_export_comment([Path0,F0,A],Comm) :-
                 ]),
     sub_string(Syn0, 6, _, 1, Comm).
 
+strip_det(//(Mode) is _, Mode) :- !.
 strip_det(Mode is _, Mode) :- !.
 strip_det(//(Mode), Mode) :- !.
 strip_det(Mode, Mode).
@@ -973,7 +976,12 @@ sweep_exportable_predicates(Path0, Preds) :-
     findall(D,
             (   xref_defined(Path, D0, _),
                 \+ xref_exported(Path, D0),
-                pi_head(D1, D0),
+                \+ D0 = _:_,
+                pi_head(F/A, D0),
+                (   xref_defined(Path, D0, dcg)
+                ->  B is A - 2, D1 = F//B
+                ;   D1 = F/A
+                ),
                 term_string(D1, D)
             ),
             Preds).
index d9de4908aeb9e5567a087daedb108f19654843a3..ce8be3fb87a6fbf08ba84b07935fa6e634c2af3c 100644 (file)
@@ -4171,9 +4171,9 @@ work."
     (sweeprolog-close-query)
     res))
 
-(defun sweeprolog-local-predicate-export-comment (fun ari)
+(defun sweeprolog-local-predicate-export-comment (fun ari ind)
   (sweeprolog--query-once "sweep" "sweep_local_predicate_export_comment"
-                          (list (buffer-file-name) fun ari)))
+                          (list (buffer-file-name) fun ari ind)))
 
 (defun sweeprolog-exportable-predicates ()
   "Return a list of exportable predicates from the current buffer."
@@ -4197,11 +4197,17 @@ export comment from its PlDoc comment.  Otherwise, prompt for a
 predicate to export providing completion candidates based on the
 non-exported predicates defined in the current buffer."
   (interactive (or (and (not current-prefix-arg)
-                        (when-let ((def (sweeprolog-definition-at-point))
-                                   (fun (cadr def))
-                                   (ari (caddr def)))
-                          (list (concat fun "/" (number-to-string ari))
-                                (sweeprolog-local-predicate-export-comment fun ari))))
+                        (when-let ((def  (sweeprolog-definition-at-point))
+                                   (fun  (nth 1 def))
+                                   (ari  (nth 2 def))
+                                   (neck (nth 4 def))
+                                   (ind  "/"))
+                          (unless (nth 5 def)
+                            (when (string= neck "-->")
+                              (setq ari (- ari 2)
+                                    ind "//"))
+                            (list (concat fun ind (number-to-string ari))
+                                  (sweeprolog-local-predicate-export-comment fun ari ind)))))
                    (list
                     (sweeprolog-read-exportable-predicate)
                     (read-string "Export comment: ")))