From: Eshel Yaron Date: Tue, 6 Jun 2023 05:17:33 +0000 (+0300) Subject: ENHANCED: Export DCG non-terminals as 'foo//N', not 'foo/N+2' X-Git-Tag: V9.1.10-sweep-0.18.4~4 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=62fe11b8abed4d1eac05d35180426b187f0e8975;p=sweep.git 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. --- diff --git a/sweep.pl b/sweep.pl index 31aa759..e92d632 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 d9de490..ce8be3f 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: ")))