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

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

[elpa] externals/phps-mode 6c6906317a 095/135: Added bookkeeping test fo


From: Christian Johansson
Subject: [elpa] externals/phps-mode 6c6906317a 095/135: Added bookkeeping test for trait class symbols
Date: Sun, 29 Jan 2023 03:11:08 -0500 (EST)

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

    Added bookkeeping test for trait class symbols
---
 phps-mode-parser-sdt.el    | 55 ++++++++++++++++++++++++++++++++++++++++++++--
 test/phps-mode-test-ast.el |  8 +++----
 2 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 6926c821ea..636d9aefe1 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -2308,6 +2308,58 @@
 (puthash
  190
  (lambda(args _terminals)
+   ;; Go through stacks and modify symbol name-spaces
+   ;; but only for non-super-global variables.
+   ;; 
+   ;; Should place class scope first in scope
+   ;; unless a namespace exists, in that case it should be placed second in 
scope
+   (let ((class-name (nth 1 args)))
+     (when phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack
+       (dolist (
+                symbol-list
+                phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
+         (let ((symbol-name (car symbol-list))
+               (symbol-start (nth 2 symbol-list))
+               (symbol-end (nth 3 symbol-list)))
+           (unless (gethash
+                    symbol-name
+                    phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+             (let ((symbol-scope (reverse (car (cdr symbol-list)))))
+               (if (equal (car (car symbol-scope)) 'namespace)
+                   (let ((namespace-name (car (cdr (car symbol-scope)))))
+                     (setcar symbol-scope (list 'interface class-name))
+                     (push (list 'namespace namespace-name) symbol-scope))
+                 (push
+                  (list 'trait class-name)
+                  symbol-scope))
+               (setq symbol-scope (reverse symbol-scope))
+               (setcar
+                (cdr symbol-list)
+                symbol-scope))))))
+
+     (when phps-mode-parser-sdt--bookkeeping-symbol-stack
+       (dolist (
+                symbol-list
+                phps-mode-parser-sdt--bookkeeping-symbol-stack)
+         (let ((symbol-name (car symbol-list))
+               (symbol-start (nth 2 symbol-list))
+               (symbol-end (nth 3 symbol-list)))
+           (unless (gethash
+                    symbol-name
+                    phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+             (let ((symbol-scope (reverse (car (cdr symbol-list)))))
+               (if (equal (car (car symbol-scope)) 'namespace)
+                   (let ((namespace-name (car (cdr (car symbol-scope)))))
+                     (setcar symbol-scope (list 'interface class-name))
+                     (push (list 'namespace namespace-name) symbol-scope))
+                 (push
+                  (list 'trait class-name)
+                  symbol-scope))
+               (setq symbol-scope (reverse symbol-scope))
+               (setcar
+                (cdr symbol-list)
+                symbol-scope)))))))
+
    `(
      ast-type
      trait-declaration-statement
@@ -2316,8 +2368,7 @@
      backup-doc-comment
      ,(nth 2 args)
      class-statement-list
-     ,(nth 4 args)
-     ))
+     ,(nth 4 args)))
  phps-mode-parser--table-translations)
 
 ;; 191 ((interface_declaration_statement) (T_INTERFACE T_STRING 
interface_extends_list backup_doc_comment "{" class_statement_list "}"))
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index acabb60f85..8190db8fb0 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -379,14 +379,12 @@
    '((" namespace myNamespace class myClass function myMethod id $argument3" 
((180 190))) (" namespace myNamespace class myClass function myMethod id 
$argument2" ((160 170))) (" namespace myNamespace class myClass function 
myMethod id $argument1" ((140 150) (446 456))) (" namespace myNamespace class 
myClass function myMethod id $this" ((197 581))) (" namespace myNamespace class 
myClass id $property2" ((87 97))) (" namespace myNamespace class myClass id 
$property1" ((58 68))) ((180 190) 1 [...]
 
   (phps-mode-test-ast--should-bookkeep
-   "<?php\ntrait Hello {\n    public function sayHello() {\n        echo 
'Hello ';\n    }\n}\n\ntrait World {\n    public function sayWorld() {\n        
echo 'World';\n    }\n}\n\nclass MyHelloWorld {\n    use Hello, World;\n    
public function sayExclamationMark() {\n        echo '!';\n    }\n}\n\n$o = new 
MyHelloWorld();\n$o->sayHello();\n$o->sayWorld();\n$o->sayExclamationMark();\n?>"
-   "Trait classes"
-   nil)
+   "<?php\ntrait MyTrait {\n    private $var = 'abc';\n    public function 
sayHello() {\n        if ($this->var) {\n            echo 'Hit';\n        }\n   
 }\n}\n"
+   "A basic trait class"
+   '((" trait MyTrait function sayHello id $this" ((80 147))) (" trait MyTrait 
id $var" ((35 39))) ((101 104) 1) ((94 99) 1) ((35 39) 1)))
 
-  ;; TODO Add trait class bookkeping test here
   ;; TODO Add test for class properties in class construct here
 
-
   (message "\n-- Ran tests for bookkeeping generation. --"))
 
 (defun phps-mode-test-ast ()



reply via email to

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