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

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

[nongnu] elpa/sweeprolog 8ef9be4609 2/2: Support new DCG SSU rules


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 8ef9be4609 2/2: Support new DCG SSU rules
Date: Thu, 7 Nov 2024 16:00:47 -0500 (EST)

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

    Support new DCG SSU rules
    
    * sweep.pl: Support DCG rules with '==>' (SSU) neck.
    * sweeprolog-tests.el: Add tests.
---
 sweep.pl            | 15 ++++++++++++---
 sweeprolog-tests.el | 38 +++++++++++++++++++++++++++++++-------
 2 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/sweep.pl b/sweep.pl
index bbffab2922..98d572a308 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -276,6 +276,9 @@ sweep_short_documentation_clause_((Head => Body), _Pos, 
[HeadPos, BodyPos], Poin
 sweep_short_documentation_clause_((Head --> Body), _Pos, [HeadPos, BodyPos], 
Point, FileName, Mod, PIString, Doc, ArgSpan) :-
     !,
     sweep_short_documentation_clause_neck(Head, HeadPos, Body, BodyPos, '//', 
Point, FileName, Mod, PIString, Doc, ArgSpan).
+sweep_short_documentation_clause_((Head ==> Body), _Pos, [HeadPos, BodyPos], 
Point, FileName, Mod, PIString, Doc, ArgSpan) :-
+    !,
+    sweep_short_documentation_clause_neck(Head, HeadPos, Body, BodyPos, '//', 
Point, FileName, Mod, PIString, Doc, ArgSpan).
 sweep_short_documentation_clause_((:- Directive), _Pos, [Pos], Point, 
FileName, Mod, PIString, Doc, ArgSpan) :-
     !,
     sweep_short_documentation_body(Pos, Directive, 0, Point, FileName, Mod, 
PIString, Doc, ArgSpan).
@@ -315,7 +318,7 @@ sweep_short_documentation_head(term_position(_, _, _, _, 
[HeadPos, GuardPos]), (
     ->  sweep_short_documentation_head(HeadPos, Head, Neck, Point, FileName, 
Mod, PIString, Doc, ArgSpan)
     ;   pos_bounds(GuardPos, GuardBeg, GuardEnd),
         GuardBeg =< Point, Point =< GuardEnd
-    ->  sweep_short_documentation_body(GuardPos, Guard, Neck, Point, FileName, 
Mod, PIString, Doc, ArgSpan)
+    ->  sweep_short_documentation_body(GuardPos, Guard, 0, Point, FileName, 
Mod, PIString, Doc, ArgSpan)
     ).
 sweep_short_documentation_head(term_position(_, _, _, _, [_, Pos]), Mod:Head, 
Neck, Point, FileName, _, PIString, Doc, ArgSpan) :-
     !,
@@ -1405,7 +1408,9 @@ sweep_context_callable([H|T], R) :-
     atom_string(F, F0),
     op_is_neck(F),
     !,
-    (   F == (-->)
+    (   (   F == (-->)
+        ;   F == (==>)
+        )
     ->  R0 = 2
     ;   R0 = 0
     ),
@@ -1437,6 +1442,7 @@ sweep_context_callable_([H|T], R0, R) :-
     sweep_context_callable_(T, R1, R).
 
 sweep_context_callable_arg((-->), _, _, 2) :- !.
+sweep_context_callable_arg((==>), _, _, 2) :- !.
 sweep_context_callable_arg(^, _, _, 0) :- !.
 sweep_context_callable_arg(Neck, _, _, 0) :-
     op_is_neck(Neck),
@@ -1725,7 +1731,7 @@ sweep_replace_stream_(end_of_file, _, _, _, _, _, _, _, 
_, _, []) :- !.
 sweep_replace_stream_(Term, Pos, Stream, FileName, Module, BodyIndent, Final, 
TemplateGoal, VarNames0, Rep-VarNames, Res) :-
     (   var(Term)
     ->  State = clause
-    ;   memberchk(Term, [(_:-_),(_=>_),(_-->_)])
+    ;   memberchk(Term, [(_:-_),(_=>_),(_-->_),(_==>_)])
     ->  State = clause
     ;   Term = (:-_)
     ->  State = directive
@@ -1861,6 +1867,8 @@ sweep_replace_update_state(_FileName, _Module, '=>', 2, 
1, clause, head) :- !.
 sweep_replace_update_state(_FileName, _Module, '=>', 2, 2, clause, goal(0)) :- 
!.
 sweep_replace_update_state(_FileName, _Module, '-->', 2, 1, clause, head) :- !.
 sweep_replace_update_state(_FileName, _Module, '-->', 2, 2, clause, goal(2)) 
:- !.
+sweep_replace_update_state(_FileName, _Module, '==>', 2, 1, clause, head) :- !.
+sweep_replace_update_state(_FileName, _Module, '==>', 2, 2, clause, goal(2)) 
:- !.
 sweep_replace_update_state(_FileName, _Module, _Functor, _Arity, _I, clause, 
data) :- !.
 sweep_replace_update_state(_FileName, _Module, ',', 2, 1, head, head) :- !.    
 %  SSU head
 sweep_replace_update_state(_FileName, _Module, ',', 2, 2, head, goal(0)) :- !. 
 %  SSU guard
@@ -2172,6 +2180,7 @@ clause_body_pos_neck_((:-B), term_position(_,_,_,_,[BP]), 
B, BP,0) :- !.
 clause_body_pos_neck_((_:-B), term_position(_,_,_,_,[_,BP]), B, BP,0) :- !.
 clause_body_pos_neck_((_=>B), term_position(_,_,_,_,[_,BP]), B, BP,0) :- !.
 clause_body_pos_neck_((_-->B), term_position(_,_,_,_,[_,BP]), B, BP,//).
+clause_body_pos_neck_((_==>B), term_position(_,_,_,_,[_,BP]), B, BP,//).
 
 sweep_extract_goal([ClauseString,GoalBeg,GoalEnd,Functor0,FileName0],
                    [Call,Head,Neck,Body,Safe,Functor,Arity,Exists]) :-
diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el
index b7c8b9052d..c24ce50ed8 100644
--- a/sweeprolog-tests.el
+++ b/sweeprolog-tests.el
@@ -823,6 +823,16 @@ foo(Bar) --> optiona"
                    ":- use_module(library(dcg/high_order)).
 foo(Bar) --> optional(Match, Default)")))
 
+(sweeprolog-deftest dcg-ssu-completion-at-point ()
+  "Test completing DCG grammar rule invocation with SSU."
+  ":- use_module(library(dcg/high_order)).
+foo(Bar) ==> optiona"
+  (goto-char (point-max))
+  (complete-symbol nil)
+  (should (string= (buffer-string)
+                   ":- use_module(library(dcg/high_order)).
+foo(Bar) ==> optional(Match, Default)")))
+
 (sweeprolog-deftest definition-at-point ()
   "Test recognizing predicate definitions."
   "foo(Bar) :- bar(Bar)."
@@ -2463,10 +2473,24 @@ foo(Bar) --> baz(Bar).
 "
                    (7 . 12)))))
 
+(sweeprolog-deftest eldoc-dcg-ssu-guard ()
+  "Test `sweep_short_documentation/2' with a DCG SSU guard."
+  "
+:- module(eldocdcgssuguard, []).
+
+:- use_module(library(lists)).
+"
+  (should (equal (sweeprolog--query-once
+                  "sweep" "sweep_short_documentation"
+                  (list "foo(a), member(a,[a]) ==> [b]." 15 
(buffer-file-name)))
+                 '("lists:member/2" "member(?Elem,?List) is unspec.
+    True if Elem is a member of List.
+"
+                   (7 . 12)))))
 
 (sweeprolog-deftest eldoc-dcg-pushback ()
-  "Test `sweep_short_documentation/2' with DCG pushback list."
-  "
+                    "Test `sweep_short_documentation/2' with DCG pushback 
list."
+                    "
 :- module(eldocdcgpushback, []).
 
 %!  foo(-Baz:string)// is det.
@@ -2476,13 +2500,13 @@ foo(Bar) --> baz(Bar).
 foo(_) --> [].
 
 "
-  (should (equal (sweeprolog--query-once
-                  "sweep" "sweep_short_documentation"
-                  (list "foo(X), [1,2,3] --> []." 5 (buffer-file-name)))
-                 '("eldocdcgpushback:foo//1" "foo(-Baz:string)// is det.
+                    (should (equal (sweeprolog--query-once
+                                    "sweep" "sweep_short_documentation"
+                                    (list "foo(X), [1,2,3] --> []." 5 
(buffer-file-name)))
+                                   '("eldocdcgpushback:foo//1" 
"foo(-Baz:string)// is det.
     Doit.
 "
-                   (4 . 15)))))
+                                     (4 . 15)))))
 
 (sweeprolog-deftest replace-with-anonymous-variable ()
   "Test `sweeprolog-replace-with-anonymous-variable'."



reply via email to

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