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

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

[elpa] externals/phpinspect 11ecfdf314 13/30: Fix bug in parsing of inte


From: ELPA Syncer
Subject: [elpa] externals/phpinspect 11ecfdf314 13/30: Fix bug in parsing of interfaces
Date: Sat, 31 Aug 2024 09:58:53 -0400 (EDT)

branch: externals/phpinspect
commit 11ecfdf314c067c36f7af90958aba3a2bfe3d407
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>

    Fix bug in parsing of interfaces
---
 phpinspect-parser.el  | 17 ++++-------------
 phpinspect-typedef.el | 17 ++++-------------
 test/test-buffer.el   | 15 +++++++++------
 test/test-parser.el   | 40 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/phpinspect-parser.el b/phpinspect-parser.el
index 5ef32de767..728e546c2f 100644
--- a/phpinspect-parser.el
+++ b/phpinspect-parser.el
@@ -790,23 +790,13 @@ Returns the consumed text string without face properties."
   :handlers '(comment word list terminator tag)
   :delimiter-predicate #'phpinspect-end-of-token-p)
 
-;; TODO: Look into using different names for function and class :declaration 
tokens. They
-;; don't necessarily require the same handlers to parse.
-(define-inline phpinspect-parse-declaration (buffer max-point &optional 
continue-condition root)
-  (inline-quote
-     (let ((result (phpinspect--parse-declaration ,buffer ,max-point nil 
,continue-condition ,root)))
-       (if (phpinspect-terminator-p (car (last result)))
-           (butlast result)
-         result))))
-
 (phpinspect-defhandler function-keyword (start-token max-point)
   "Handler for the function keyword and tokens that follow to give it meaning"
   ((regexp . (concat "function" (phpinspect--word-end-regex))))
   (setq start-token (phpinspect--strip-word-end-space start-token))
   (let* ((continue-condition (lambda () (not (or (char-equal (char-after) ?{)
-                                                 (char-equal (char-after) 
?})))))
-         (declaration (phpinspect-parse-declaration (current-buffer) max-point 
continue-condition 'root)))
-
+                                                           (char-equal 
(char-after) ?})))))
+         (declaration (phpinspect--parse-declaration (current-buffer) 
max-point nil continue-condition 'root)))
     (if (phpinspect-end-of-token-p (car (last declaration)))
         ;; Abstract function?
         (list :function declaration)
@@ -904,9 +894,10 @@ the properties of the class"
   ((regexp . (concat 
"\\(abstract\\|final\\|class\\|interface\\|trait\\|enum\\)"
                      (phpinspect--word-end-regex))))
   (setq start-token (phpinspect--strip-word-end-space start-token))
-  `(:class ,(phpinspect-parse-declaration
+  `(:class ,(phpinspect--parse-declaration
                 (current-buffer)
                 max-point
+                nil
                 (lambda () (not (char-equal (char-after) ?{)))
                 'root)
            ,@(cdr (phpinspect--parse-class-body (current-buffer) max-point 
nil))))
diff --git a/phpinspect-typedef.el b/phpinspect-typedef.el
index 2081483b0f..a6f4a659d2 100644
--- a/phpinspect-typedef.el
+++ b/phpinspect-typedef.el
@@ -131,13 +131,12 @@ structure returned by `phpinspect--index-trait-use'."
       (push (cons type overrides) (phpi-ma-overrides ma)))))
 
 (defun phpi-ma-add (ma mcol method &optional overwrite)
-
   (let ((overrides (phpi-ma-get-overrides ma (phpi-method-origin-type method)))
         (aliases (phpi-ma-get-aliases ma (phpi-method-origin-type method)))
-        alias override)
+        alias)
 
     ;; Can't alias if overriding, can't override if aliasing
-    (cond ((and overrides (setq override (alist-get (phpi-method-name method) 
overrides)))
+    (cond ((and overrides (alist-get (phpi-method-name method) overrides))
            ;; Override basically just means insert and overwrite without 
checking
            (phpi-mcol-add mcol method 'overwrite))
           ((and aliases (setq alias (alist-get (phpi-method-name method) 
aliases)))
@@ -175,7 +174,7 @@ structure returned by `phpinspect--index-trait-use'."
     (phpi-typedef-trigger-subscriber-method-update def m)))
 
 (cl-defmethod phpi-typedef-set-method ((def phpinspect-typedef) (fn 
phpinspect--function) &optional no-propagate)
-  (phpi-typedef-set-method def (phpinspect-make-method (phpi-typedef-name def) 
fn)))
+  (phpi-typedef-set-method def (phpinspect-make-method (phpi-typedef-name def) 
fn) no-propagate))
 
 (cl-defmethod phpi-typedef-set-static-method ((def phpinspect-typedef) (m 
phpinspect-method) &optional no-propagate)
   (phpi-ma-add (phpi-typedef-method-adder def) (phpi-typedef-static-methods 
def) m 'overwrite)
@@ -183,15 +182,7 @@ structure returned by `phpinspect--index-trait-use'."
     (phpi-typedef-trigger-subscriber-method-update def m 'static)))
 
 (cl-defmethod phpi-typedef-set-static-method ((def phpinspect-typedef) (fn 
phpinspect--function) &optional no-propagate)
-  (phpi-typedef-set-static-method def (phpinspect-make-method 
(phpi-typedef-name def) fn)))
-
-
-(cl-defmethod phpi-typedef-set-static-method ((def phpinspect-typedef) (fn 
phpinspect--function) &optional no-propagate)
-  (let ((method (phpinspect-make-method (phpi-typedef-name def) fn)))
-    (phpi-ma-add (phpi-typedef-method-adder def)
-                 (phpi-typedef-static-methods def)
-                 method 'overwrite)))
-
+  (phpi-typedef-set-static-method def (phpinspect-make-method 
(phpi-typedef-name def) fn) no-propagate))
 
 (cl-defmethod phpi-typedef-delete-method ((def phpinspect-typedef) (name (head 
phpinspect-name)))
   (phpi-mcol-delete-for-type
diff --git a/test/test-buffer.el b/test/test-buffer.el
index b50e29a3e7..3b99595c80 100644
--- a/test/test-buffer.el
+++ b/test/test-buffer.el
@@ -132,14 +132,17 @@
       (should (phpinspect-function-p (phpinspect-meta-token 
(phpinspect-meta-parent (phpinspect-meta-parent bello)))))
       (should (phpinspect-function-p (phpinspect-meta-token 
(phpinspect-meta-parent (phpinspect-meta-parent bello1)))))
 
-      (let ((function (phpinspect-meta-token (phpinspect-meta-parent 
(phpinspect-meta-parent bello1)))))
-        ;; There's 5 nested tokens in the function. It is not a valid function
-        ;; token, a correct function would only contain a declaration and a
-        ;; block. But the incremental parser doesn't complain.
-        (should (= 5 (length function)))
+      (let* ((function-meta (phpinspect-meta-parent (phpinspect-meta-parent 
bello1)))
+             (function (phpinspect-meta-token function-meta)))
+        ;; The uncomplete function body was absorbed by the declaration up 
until
+        ;; the first semicolon.
+        (should (= 2 (length function)))
         (should (phpinspect-declaration-p (cadr function)))
         (should (member '(:word "Bello") (cadr function)))
-        (should (member '(:word "echo") (cadr function))))
+        (should (member '(:word "echo") (cadr function)))
+
+        ;; rest of tokens is absorbed by parent.
+        (should (equal `(:word "if")  (phpinspect-meta-token 
(phpinspect-meta-find-right-sibling function-meta)))))
 
       (phpinspect-document-apply-edit document 24 25 1 "{")
       (should (string= "<?php function Bello() { echo 'Hello World!'; if 
($name) { echo 'Hello ' . $name . '!';} }"
diff --git a/test/test-parser.el b/test/test-parser.el
index b3195979e8..741a65b4ee 100644
--- a/test/test-parser.el
+++ b/test/test-parser.el
@@ -156,4 +156,42 @@ class TestClass {
                                           (:block
                                            (:word "C") (:static-attrib (:word 
"foo"))
                                            (:word "insteadof") (:word "A"))))))
-            tree))))
+             tree))))
+
+(ert-deftest phpinspect-parse-interface-methods ()
+  (let ((result (phpinspect-parse-string "
+interface Test
+{
+    public function __call($method, $parameters);
+
+    public static function __callStatic($method, $parameters);
+}"))
+        (expected '(:root
+                    (:class
+                     (:declaration
+                      (:word "interface")
+                      (:word "Test"))
+                     (:block
+                      (:public
+                       (:function
+                        (:declaration
+                         (:word "function")
+                         (:word "__call")
+                         (:list
+                          (:variable "method")
+                          (:comma ",")
+                          (:variable "parameters"))
+                         (:terminator ";"))))
+                      (:public
+                       (:static
+                        (:function
+                         (:declaration
+                          (:word "function")
+                          (:word "__callStatic")
+                          (:list
+                              (:variable "method")
+                              (:comma ",")
+                              (:variable "parameters"))
+                          (:terminator ";"))))))))))
+
+    (should (equal expected result))))



reply via email to

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