[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phpinspect 2520c89680 02/18: Account for tokens after @
From: |
ELPA Syncer |
Subject: |
[elpa] externals/phpinspect 2520c89680 02/18: Account for tokens after @method annotation when indexing |
Date: |
Fri, 16 Aug 2024 06:58:55 -0400 (EDT) |
branch: externals/phpinspect
commit 2520c8968011ba714919448e09c59c857ecc77e0
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>
Account for tokens after @method annotation when indexing
- Add :rest keyword to `phpinspect--match-sequence'
- Use :rest keyword in `phpinspect--index-method-annotations'
---
phpinspect-index.el | 12 ++++++++----
phpinspect-util.el | 23 +++++++++++++++++++----
test/test-index.el | 2 +-
test/test-util.el | 28 ++++++++++++++++++++++++++++
4 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/phpinspect-index.el b/phpinspect-index.el
index f948d6f61b..474e9123ca 100644
--- a/phpinspect-index.el
+++ b/phpinspect-index.el
@@ -224,24 +224,28 @@ SCOPE should be a scope token (`phpinspect-scope-p')."
(dolist (annotation annotations)
(let ((return-type) (name) (arg-list) (static))
;; Annotation is static
- (when (phpinspect--match-sequence (take 2 annotation)
- :m :method-annotation :m '(:word "static"))
+ (when (phpinspect--match-sequence annotation
+ :m :method-annotation :m '(:word "static") :rest *)
(setcdr annotation (cddr annotation))
(setq static t))
(cond
+ ;; Sequence is: return-type, method-name, method signature
((phpinspect--match-sequence annotation
:m :method-annotation
:f #'phpinspect-word-p
:f #'phpinspect-word-p
- :f #'phpinspect-list-p)
+ :f #'phpinspect-list-p
+ :rest *)
(setq return-type (cadr (nth 1 annotation)))
(setq name (cadr (nth 2 annotation)))
(setq arg-list (nth 3 annotation)))
+ ;; Sequence is: method-name, method-signature
((phpinspect--match-sequence annotation
:m :method-annotation
:f #'phpinspect-word-p
- :f #'phpinspect-list-p)
+ :f #'phpinspect-list-p
+ :rest *)
(setq return-type "void")
(setq name (cadr (nth 1 annotation)))
(setq arg-list (nth 2 annotation))))
diff --git a/phpinspect-util.el b/phpinspect-util.el
index bd722871f2..4aaf2fa32a 100644
--- a/phpinspect-util.el
+++ b/phpinspect-util.el
@@ -170,6 +170,13 @@ pattern. See `phpinspect--match-sequence'."
"Match SEQUENCE to PATTERN."
(funcall (phpinspect--pattern-matcher pattern) sequence))
+(defun phpinspect--list-all-equal (val sequence)
+ (catch 'not-equal
+ (dolist (item sequence)
+ (unless (equal val item)
+ (throw 'not-equal nil)))
+ t))
+
(defmacro phpinspect--match-sequence (sequence &rest pattern)
"Match SEQUENCE to positional matchers defined in PATTERN.
@@ -201,7 +208,7 @@ it evaluates to a non-nil value."
(match-rear-sym (gensym))
(checkers (cons nil nil))
(checkers-rear checkers)
- key value)
+ rest key value)
(while (setq key (pop pattern))
(unless (keywordp key)
@@ -224,6 +231,8 @@ it evaluates to a non-nil value."
`(,value (elt ,sequence-sym ,sequence-pos))
`(funcall ,value (elt ,sequence-sym ,sequence-pos)))
nil))))
+ ((eq key :rest)
+ (setq rest value))
(t (error "Invalid keyword: %s" key)))
(setq checkers-rear
@@ -240,9 +249,15 @@ it evaluates to a non-nil value."
`(let* ((,sequence-sym ,sequence)
(,match-sym (cons nil nil))
(,match-rear-sym ,match-sym))
- (and (= ,sequence-length (length ,sequence))
- ,@checkers
- (cdr ,match-sym)))))
+ ,(if rest
+ `(and ,@checkers
+ (cdr ,match-sym)
+ ,(if (eq rest '*)
+ 't
+ `(phpinspect--list-all-equal ,rest (nthcdr
,sequence-length ,sequence-sym))))
+ `(and (= ,sequence-length (length ,sequence))
+ ,@checkers
+ (cdr ,match-sym))))))
(defun phpinspect--pattern-concat (pattern1 pattern2)
(let* ((pattern1-sequence-length (/ (length (phpinspect--pattern-code
pattern1)) 2)))
diff --git a/test/test-index.el b/test/test-index.el
index d1621bc8ae..5f3f4bf4e0 100644
--- a/test/test-index.el
+++ b/test/test-index.el
@@ -127,7 +127,7 @@ return StaticThing::create(new
ThingFactory())->makeThing((((new Potato())->anti
"<?php
/* @method int peel(bool $fast, array $loose)
- * @method Banana duplicate()
+ * @method Banana duplicate() Words after annotation
@method hold() **/
class Banana {}")))
(class (car (alist-get 'classes result)))
diff --git a/test/test-util.el b/test/test-util.el
index 2e708dceb8..c580367519 100644
--- a/test/test-util.el
+++ b/test/test-util.el
@@ -55,3 +55,31 @@
:m '(:object-attrib (:word "not-a-match")))))
(should-not result)))
+
+(ert-deftest phpinspect--pattern-match-rest ()
+ (should (phpinspect--match-sequence '((:variable "this") (:object-attrib
(:word "em")) (:list))
+ :m '(:variable "this")
+ :m *
+ :rest '(:list)))
+
+ (should (phpinspect--match-sequence '((:variable "this") (:object-attrib
(:word "em")) (:list))
+ :m '(:variable "this")
+ :m *
+ :rest *))
+
+ (should (phpinspect--match-sequence '((:variable "this") (:object-attrib
(:word "em")) (:list))
+ :m '(:variable "this")
+ :m *
+ :rest '(:list)))
+
+ (should (phpinspect--match-sequence '((:variable "this") (:object-attrib
(:word "em")) (:list))
+ :m '(:variable "this")
+ :rest *))
+
+ (should-not (phpinspect--match-sequence '((:variable "this") (:object-attrib
(:word "em")) (:variable "ba") (:list))
+ :m '(:variable "this")
+ :rest '(:list)))
+
+ (should-not (phpinspect--match-sequence '((:variable "this") (:object-attrib
(:word "em")) (:list))
+ :m '(:variable "this")
+ :m *)))
- [elpa] externals/phpinspect updated (3887bc58d4 -> 4ec4c40c9d), ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect d3f100388e 04/18: Resolve property types using other methods when resolving from constructor fails, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 3fff772d8a 03/18: Fix phpinspect-buffer-index-functions test, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect d141f8a6db 08/18: Infer namespace token within import manipulation loop, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 8296641ba9 07/18: Implement removal of unused imports in `phpinspect-fix-imports', ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 93b815d71a 14/18: Index used traits (juste use of type, no actual functionality outside of that), ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 6a175c9e44 06/18: Update a few doc strings in phpinspect-index.el, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 31c6e06934 09/18: Reparse buffer when fixing import (+ add comment explaining why), ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 2e064d52e1 17/18: Implement containing type inference for collection-like class properties, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 5528aff2a2 01/18: Handle cases where the filepath of a type cannot be determined, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 2520c89680 02/18: Account for tokens after @method annotation when indexing,
ELPA Syncer <=
- [elpa] externals/phpinspect f2f1ac9b84 05/18: Add property types and anonymous function argument types to used-types index, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 130e2c06c5 13/18: Index types used in arrays, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect f1dc699560 11/18: Detect types used with "instanceoff", ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 3a0ce3ac2d 16/18: Fix another infinite recursion bug, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect b6eadfb799 12/18: Make autoload indexation more robust and prevent double indexation, ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect c20f010ee4 10/18: Introduce `phpinspect-buffer-fresh-p' and `phpinspect-buffer-reparse-if-not-fresh', ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 2d93ec7f79 15/18: Fix infinite recursion bug in `phpinspect--get-pattern-type-in-block', ELPA Syncer, 2024/08/16
- [elpa] externals/phpinspect 4ec4c40c9d 18/18: Add eldoc for sigil variables and allow display of multiple eldoc results, ELPA Syncer, 2024/08/16