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

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

[elpa] externals/phps-mode 8115521ef8 011/212: Imenu-generation via pars


From: Christian Johansson
Subject: [elpa] externals/phps-mode 8115521ef8 011/212: Imenu-generation via parser SDT passing more tests
Date: Wed, 26 Jan 2022 01:50:12 -0500 (EST)

branch: externals/phps-mode
commit 8115521ef8743e2ff52d0d143c05eebaa1194b90
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Imenu-generation via parser SDT passing more tests
---
 phps-mode-ast.el           | 32 ++++++++++++++++--
 test/phps-mode-test-ast.el | 81 +++++++++++-----------------------------------
 2 files changed, 48 insertions(+), 65 deletions(-)

diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index a868d01694..2ff5a1700f 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -167,6 +167,31 @@
      ast-object))
  phps-mode-parser--table-translations)
 
+
+;; interface_declaration_statement -> (T_INTERFACE T_STRING 
interface_extends_list backup_doc_comment "{" class_statement_list "}")
+(puthash
+ 186
+ (lambda(args terminals)
+   (let ((ast-object
+          (list
+           'type
+           'interface
+           'name
+           (nth 1 args)
+           'index
+           (car (cdr (nth 1 terminals)))
+           'start
+           (car (cdr (nth 4 terminals)))
+           'end
+           (car (cdr (nth 6 terminals)))
+           'children
+           (nth 5 args))))
+     ;; (message "Interface %S" ast-object)
+     ;; (message "args: %S" args)
+     ;; (message "terminals: %S" terminals)
+     ast-object))
+ phps-mode-parser--table-translations)
+
 ;; class_statement_list -> (class_statement_list class_statement)
 (puthash
  276
@@ -265,7 +290,8 @@
           (if (and
                (or
                 (equal item-type 'namespace)
-                (equal item-type 'class))
+                (equal item-type 'class)
+                (equal item-type 'interface))
                children)
               (progn
                 (dolist (child children)
@@ -273,7 +299,9 @@
                         (child-type (plist-get child 'type))
                         (subparent))
                     (if (and
-                         (equal child-type 'class)
+                         (or
+                          (equal child-type 'class)
+                          (equal child-type 'interface))
                          grand-children)
                         (progn
                           (dolist (grand-child grand-children)
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 05339ce8e9..09be4b461b 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -76,7 +76,7 @@
 
     ;; Run test
     (funcall logic)
-    (message "Passed %s" name)))
+    (message "Passed test for %S\n" name)))
 
 (defun phps-mode-test-ast-imenu ()
   "Run test for imenu generation."
@@ -87,64 +87,33 @@
    "Imenu generated via parser SDT for simple class"
    (lambda()
      (phps-mode-ast-generate)
-     (message "\nAST:\n%S\n" phps-mode-ast--tree)
-     (message "imenu-index:\n%S\n" phps-mode-ast--imenu)
      (should (equal
               phps-mode-ast--imenu
               '(("myClass" ("myFunction1" . 44) ("myFunction2" . 153)))))))
 
-  ;; (phps-mode-test-ast--buffer-contents
-  ;;  "<?php\ninterface myInterface {\n    public function myFunctionA() {}\n  
  protected function myFunctionB() {}\n}\n"
-  ;;  "Imenu generated via parser SDT for interface"
-  ;;  (lambda()
-  ;;    (phps-mode-ast-generate)
-  ;;    (message "\nAST:\n%S\n" phps-mode-ast--tree)
-  ;;    (message "imenu-index:\n%S\n" phps-mode-ast--imenu)
-  ;;    (should (equal
-  ;;             phps-mode-ast--imenu
-  ;;             '(("myInterface" . (("myFunctionA" . 51) ("myFunctionB" . 
91))))))))
-
-  ;; (phps-mode-test-ast--buffer-contents
-  ;;  "<?php\nfunction myFunctionA() {}\nfunction myFunctionB() {}\n$var = 
function () {\n    echo 'here';\n};"
-  ;;  "Imenu generated via parser SDT for function-oriented file without 
namespace"
-  ;;  (lambda()
-  ;;    (let ((parse (phps-mode-parser-parse)))
-  ;;      (message "Left-to-right with left-most derivation:\n%S\n" parse)
-  ;;      (dolist (production-number (reverse parse))
-  ;;        (let ((production
-  ;;               (phps-mode-parser--get-grammar-production-by-number
-  ;;                production-number)))
-  ;;          (message
-  ;;           "%d: %S -> %S"
-  ;;           production-number
-  ;;           (car (car production))
-  ;;           (car (cdr production))))))
-  ;;    (phps-mode-ast-generate)
-  ;;    ;; (message "\nAST:\n%S\n" phps-mode-ast--tree)
-  ;;    ;; (message "imenu-index:\n%S\n" phps-mode-ast--imenu)
-  ;;    (should (equal
-  ;;             phps-mode-ast--imenu
-  ;;             '(("myFunctionA" . 16) ("myFunctionB" . 42))))))
+  (phps-mode-test-ast--buffer-contents
+   "<?php\ninterface myInterface {\n    public function myFunctionA() {}\n    
protected function myFunctionB() {}\n}\n"
+   "Imenu generated via parser SDT for interface"
+   (lambda()
+     (phps-mode-ast-generate)
+     (should (equal
+              phps-mode-ast--imenu
+              '(("myInterface" . (("myFunctionA" . 51) ("myFunctionB" . 
91))))))))
+
+  (phps-mode-test-ast--buffer-contents
+   "<?php\nfunction myFunctionA() {}\nfunction myFunctionB() {}\n$var = 
function () {\n    echo 'here';\n};"
+   "Imenu generated via parser SDT for function-oriented file without 
namespace"
+   (lambda()
+     (phps-mode-ast-generate)
+     (should (equal
+              phps-mode-ast--imenu
+              '(("myFunctionA" . 16) ("myFunctionB" . 42))))))
 
   (phps-mode-test-ast--buffer-contents
    "<?php\n\nnamespace MyNamespace;\n\nfunction aFunction() {\n    /**\n     * 
With some contents\n     */\n}\n\nclass MyClass\n{\n\n    /**\n     *\n     
*/\n    public function __construct()\n    {\n        if ($test) {\n        }\n 
   }\n\n    /**\n     *\n     */\n    public function myFunction1()\n    {\n    
    $this->addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" : 
\"\") . \" was here.\");\n    }\n    \n    /**\n     *\n     */\n    public 
function myFunction2()\n [...]
    "Passed imenu-generation via parser AST for basic object oriented file"
    (lambda()
-     ;; (let ((parse (phps-mode-parser-parse)))
-     ;;   (message "Left-to-right with left-most derivation:\n%S\n" parse)
-     ;;   (dolist (production-number (reverse parse))
-     ;;     (let ((production
-     ;;            (phps-mode-parser--get-grammar-production-by-number
-     ;;             production-number)))
-     ;;       (message
-     ;;        "%d: %S -> %S"
-     ;;        production-number
-     ;;        (car (car production))
-     ;;        (car (cdr production))))))
      (phps-mode-ast-generate)
-     ;; (message "\nAST:\n%S\n" phps-mode-ast--tree)
-     ;; (message "imenu-index:\n%S\n" phps-mode-ast--imenu)
-
      (should
       (equal
        phps-mode-ast--imenu
@@ -154,21 +123,7 @@
    "<?php\n\nnamespace MyNamespaceA\n{\n    function aFunctionA() {\n        
/**\n         * With some contents\n         */\n    }\n    class MyClass\n    
{\n\n        /**\n         *\n         */\n        public function 
__construct()\n        {\n            if ($test) {\n            }\n        
}\n\n        /**\n         *\n         */\n        public function 
myFunction1()\n        {\n            $this->addMessage(\"My random {$message} 
here\" . ($random > 1 ? \"A\" : \"\") . \" was h [...]
    "Passed imenu-generation via parser AST for advanced object oriented file"
    (lambda()
-     ;; (let ((parse (phps-mode-parser-parse)))
-     ;;   (message "Left-to-right with left-most derivation:\n%S\n" parse)
-     ;;   (dolist (production-number (reverse parse))
-     ;;     (let ((production
-     ;;            (phps-mode-parser--get-grammar-production-by-number
-     ;;             production-number)))
-     ;;       (message
-     ;;        "%d: %S -> %S"
-     ;;        production-number
-     ;;        (car (car production))
-     ;;        (car (cdr production))))))
-
      (phps-mode-ast-generate)
-     ;; (message "\nAST:\n%S\n" phps-mode-ast--tree)
-     ;; (message "imenu-index:\n%S\n" phps-mode-ast--imenu)
      (should
       (equal
        phps-mode-ast--imenu



reply via email to

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