emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sweeprolog 62fe11b8ab 2/6: ENHANCED: Export DCG non-termin


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 62fe11b8ab 2/6: ENHANCED: Export DCG non-terminals as 'foo//N', not 'foo/N+2'
Date: Tue, 6 Jun 2023 04:01:34 -0400 (EDT)

branch: elpa/sweeprolog
commit 62fe11b8abed4d1eac05d35180426b187f0e8975
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    ENHANCED: Export DCG non-terminals as 'foo//N', not 'foo/N+2'
    
    * 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      | 16 ++++++++++++----
 sweeprolog.el | 20 +++++++++++++-------
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/sweep.pl b/sweep.pl
index 31aa7594a0..e92d632c2a 100644
--- 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).
diff --git a/sweeprolog.el b/sweeprolog.el
index d9de4908ae..ce8be3fb87 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -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: ")))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]