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

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

[elpa] externals/phps-mode 83faeee: Improved variable bookkeeping for ca


From: Christian Johansson
Subject: [elpa] externals/phps-mode 83faeee: Improved variable bookkeeping for catch and anonymous function blocks
Date: Fri, 11 Sep 2020 05:54:14 -0400 (EDT)

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

    Improved variable bookkeeping for catch and anonymous function blocks
---
 phps-mode-lex-analyzer.el           | 265 +++++++++++++++++++++++++++---------
 phps-mode.el                        |   4 +-
 test/phps-mode-test-lex-analyzer.el |  46 ++++---
 3 files changed, 231 insertions(+), 84 deletions(-)

diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index cb8f398..316ba68 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -116,18 +116,38 @@
   "Clear region of syntax coloring from START to END."
   (with-silent-modifications (set-text-properties start end nil)))
 
-(defun phps-mode-lex-analyzer--get-token-syntax-color (token)
-  "Return syntax color for TOKEN."
+(defun phps-mode-lex-analyzer--get-token-syntax-color (token &optional 
previous-token previous2-token)
+  "Return syntax color for TOKEN and optionally PREVIOUS-TOKEN and 
PREVIOUS2-TOKEN."
   ;; Syntax coloring
   ;; see 
https://www.gnu.org/software/emacs/manual/html_node/elisp/Faces-for-Font-Lock.html#Faces-for-Font-Lock
-  (let ((start (car (cdr token)))
-        (end (cdr (cdr token)))
-        (token-name (car token)))
+  (let* ((start (car (cdr token)))
+         (end (cdr (cdr token)))
+         (token-name (car token))
+         (previous-token-name)
+         (previous2-token-name)
+         (previous2-token-contents))
+
+    ;; Catch contexts like $this->abc
+    (when (and
+           (equal token-name 'T_STRING)
+           previous-token
+           previous2-token)
+      (setq previous-token-name (car previous-token))
+      (setq previous2-token-name (car previous2-token))
+      (when (and
+             (equal previous-token-name 'T_OBJECT_OPERATOR)
+             (equal previous2-token-name 'T_VARIABLE))
+        (setq previous2-token-contents (downcase 
(buffer-substring-no-properties (car (cdr previous2-token)) (cdr (cdr 
previous2-token)))))))
 
     ;; (message "Color token %s %s %s" token-name start end)
     (cond
 
-     ((equal token-name 'T_VARIABLE)
+     ((or (equal token-name 'T_VARIABLE)
+          (and
+           (equal token-name 'T_STRING)
+           (equal previous-token-name 'T_OBJECT_OPERATOR)
+           (equal previous2-token-name 'T_VARIABLE)
+           (string= previous2-token-contents "$this")))
       (let ((bookkeeping-index (list start end)))
         (if (gethash bookkeeping-index phps-mode-lex-analyzer--bookkeeping)
             (list 'font-lock-face 'font-lock-variable-name-face)
@@ -312,20 +332,24 @@
             old-start
             phps-mode-lex-analyzer--tokens
             (point-max)))
-          (dolist (token phps-mode-lex-analyzer--tokens)
-            (let ((start (car (cdr token)))
-                  (end (cdr (cdr token)))
-                  (token-name (car token)))
-
-              ;; Apply syntax color on token
-              (let ((token-syntax-color
-                     (phps-mode-lex-analyzer--get-token-syntax-color token)))
-                (if token-syntax-color
-                    (phps-mode-lex-analyzer--set-region-syntax-color start end 
token-syntax-color)
-                  (phps-mode-lex-analyzer--clear-region-syntax-color start 
end)))
-
-              (semantic-lex-push-token
-               (semantic-lex-token token-name start end))))
+          (let ((previous-token)
+                (previous2-token))
+            (dolist (token phps-mode-lex-analyzer--tokens)
+              (let ((start (car (cdr token)))
+                    (end (cdr (cdr token)))
+                    (token-name (car token)))
+
+                ;; Apply syntax color on token
+                (let ((token-syntax-color
+                       (phps-mode-lex-analyzer--get-token-syntax-color token 
previous-token previous2-token)))
+                  (if token-syntax-color
+                      (phps-mode-lex-analyzer--set-region-syntax-color start 
end token-syntax-color)
+                    (phps-mode-lex-analyzer--clear-region-syntax-color start 
end)))
+                (setq previous2-token previous-token)
+                (setq previous-token token)
+
+                (semantic-lex-push-token
+                 (semantic-lex-token token-name start end)))))
 
           (setq semantic-lex-end-point (point-max)))
 
@@ -393,13 +417,17 @@
              (phps-mode-lex-analyzer--reset-imenu)
 
              ;; Apply syntax color on tokens
-             (dolist (token phps-mode-lex-analyzer--tokens)
-               (let ((start (car (cdr token)))
-                     (end (cdr (cdr token))))
-                 (let ((token-syntax-color 
(phps-mode-lex-analyzer--get-token-syntax-color token)))
-                   (if token-syntax-color
-                       (phps-mode-lex-analyzer--set-region-syntax-color start 
end token-syntax-color)
-                     (phps-mode-lex-analyzer--clear-region-syntax-color start 
end)))))))))
+             (let ((previous-token)
+                   (previous2-token))
+               (dolist (token phps-mode-lex-analyzer--tokens)
+                 (let ((start (car (cdr token)))
+                       (end (cdr (cdr token))))
+                   (let ((token-syntax-color 
(phps-mode-lex-analyzer--get-token-syntax-color token previous-token 
previous2-token)))
+                     (if token-syntax-color
+                         (phps-mode-lex-analyzer--set-region-syntax-color 
start end token-syntax-color)
+                       (phps-mode-lex-analyzer--clear-region-syntax-color 
start end))))
+                 (setq previous2-token previous-token)
+                 (setq previous-token token)))))))
 
      (lambda(result)
        (when (get-buffer buffer-name)
@@ -487,15 +515,19 @@
              (phps-mode-lex-analyzer--reset-imenu)
 
              ;; Apply syntax color on tokens
-             (dolist (token phps-mode-lex-analyzer--tokens)
-               (let ((start (car (cdr token)))
-                     (end (cdr (cdr token))))
-
-                 ;; Apply syntax color on token
-                 (let ((token-syntax-color 
(phps-mode-lex-analyzer--get-token-syntax-color token)))
-                   (if token-syntax-color
-                       (phps-mode-lex-analyzer--set-region-syntax-color start 
end token-syntax-color)
-                     (phps-mode-lex-analyzer--clear-region-syntax-color start 
end)))))
+             (let ((previous-token)
+                   (previous2-token))
+               (dolist (token phps-mode-lex-analyzer--tokens)
+                 (let ((start (car (cdr token)))
+                       (end (cdr (cdr token))))
+
+                   ;; Apply syntax color on token
+                   (let ((token-syntax-color 
(phps-mode-lex-analyzer--get-token-syntax-color token previous-token 
previous2-token)))
+                     (if token-syntax-color
+                         (phps-mode-lex-analyzer--set-region-syntax-color 
start end token-syntax-color)
+                       (phps-mode-lex-analyzer--clear-region-syntax-color 
start end))))
+                 (setq previous2-token previous-token)
+                 (setq previous-token token)))
 
              (phps-mode-debug-message
               (message "Incremental tokens: %s" 
phps-mode-lex-analyzer--tokens))))))
@@ -1036,7 +1068,11 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
               (in-return-curly-bracket-level nil)
               (in-return-level 0)
               (previous-token nil)
+              (previous-token-end nil)
+              (previous-token-start nil)
               (previous2-token nil)
+              (previous2-token-end nil)
+              (previous2-token-start nil)
               (previous3-token nil)
               (token nil)
               (token-start nil)
@@ -1067,17 +1103,12 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
               (imenu-in-function-index nil)
               (imenu-nesting-level 0)
               (incremental-line-number 1)
+              (in-catch-declaration)
+              (in-anonymous-function-declaration)
+              (in-anonymous-function-number 0)
+              (in-anonymous-function-nesting-level)
               (bookkeeping (make-hash-table :test 'equal)))
 
-          ;; Super-globals
-          (puthash "$_COOKIE" t bookkeeping)
-          (puthash "$_GET" t bookkeeping)
-          (puthash "$_GLOBALS" t bookkeeping)
-          (puthash "$_POST" t bookkeeping)
-          (puthash "$_REQUEST" t bookkeeping)
-          (puthash "$_SERVER" t bookkeeping)
-          (puthash "$_SESSION" t bookkeeping)
-
           (push `(END_PARSE ,(length string) . ,(length string)) tokens)
 
           ;; Iterate through all buffer tokens from beginning to end
@@ -1137,11 +1168,33 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
               (when token
 
                 ;; BOOKKEEPING LOGIC
-                (when (equal token 'T_VARIABLE)
+                (when (or
+                       (equal token 'T_VARIABLE)
+                       (and
+                        ;; $this->...
+                        (equal token 'T_STRING)
+                        (equal previous-token 'T_OBJECT_OPERATOR)
+                        (equal previous2-token 'T_VARIABLE)))
+
                   (let ((bookkeeping-namespace namespace)
                         (bookkeeping-index (list token-start token-end))
                         (bookkeeping-variable-name (substring string (1- 
token-start) (1- token-end)))
-                        (bookkeeping-in-assignment nil))
+                        (bookkeeping-in-assignment nil)
+                        (bookkeeping-named nil)
+                        (bookkeeping-is-superglobal nil))
+
+                    ;; Flag super-globals
+                    (when (and (equal token 'T_VARIABLE)
+                               (or
+                                (equal bookkeeping-variable-name "$_COOKIE")
+                                (equal bookkeeping-variable-name "$_GET")
+                                (equal bookkeeping-variable-name "$_GLOBALS")
+                                (equal bookkeeping-variable-name "$_POST")
+                                (equal bookkeeping-variable-name "$_REQUEST")
+                                (equal bookkeeping-variable-name "$_SERVER")
+                                (equal bookkeeping-variable-name "$_SESSION")
+                                (equal bookkeeping-variable-name "$_FILES")))
+                      (setq bookkeeping-is-superglobal t))
 
                     ;; Build name-space
                     (when (and imenu-in-namespace-name
@@ -1149,21 +1202,58 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                       (setq bookkeeping-namespace (concat 
bookkeeping-namespace " namespace " imenu-in-namespace-name)))
                     (when imenu-in-class-name
                       (setq bookkeeping-namespace (concat 
bookkeeping-namespace " class " imenu-in-class-name)))
-                    (when imenu-in-function-name
-                      (setq bookkeeping-namespace (concat 
bookkeeping-namespace " function " imenu-in-function-name))
 
-                      ;; Add $this special variable in class function scope
-                      (when imenu-in-class-name
-                        (let ((bookkeeping-method-this (concat 
bookkeeping-namespace " id $this")))
-                          (unless (gethash bookkeeping-method-this bookkeeping)
-                            (puthash bookkeeping-method-this t bookkeeping)))))
+                    (when (and
+                           (equal token 'T_VARIABLE)
+                           (string= (downcase bookkeeping-variable-name) 
"$this"))
+                      (setq bookkeeping-variable-name "$this"))
+
+                    ;; self::$abc ... here
+                    (when (and
+                           (equal token 'T_VARIABLE)
+                           (equal previous-token 'T_PAAMAYIM_NEKUDOTAYIM))
+                      (let ((bookkeeping2-variable-name
+                             (downcase (substring string (1- 
previous2-token-start) (1- previous2-token-end)))))
+                        (when (string= bookkeeping2-variable-name "self")
+                          ;; (message "Found self: %s::%s" 
bookkeeping2-variable-name bookkeeping-variable-name)
+                          (setq bookkeeping-namespace (concat 
bookkeeping-namespace " static id " bookkeeping-variable-name))
+                          (setq bookkeeping-named t))))
+
+                    ;; $this->... here
+                    (when (equal token 'T_STRING)
+                      (let ((bookkeeping2-variable-name
+                             (downcase (substring string (1- 
previous2-token-start) (1- previous2-token-end)))))
+                        ;; (message "%s->%s" bookkeeping2-variable-name 
bookkeeping-variable-name)
+                        (when (string= bookkeeping2-variable-name "$this")
+                          (setq bookkeeping-namespace (concat 
bookkeeping-namespace " id $" bookkeeping-variable-name))
+                          ;; (message "Was here: '%s" bookkeeping-namespace)
+                          (setq bookkeeping-named t))))
+
+                    (unless bookkeeping-named
+                      (when imenu-in-function-name
+                        (setq bookkeeping-namespace (concat 
bookkeeping-namespace " function " imenu-in-function-name))
+
+                        ;; Add $this special variable in class function scope
+                        (when imenu-in-class-name
+                          (let ((bookkeeping-method-this (concat 
bookkeeping-namespace " id $this")))
+                            (unless (gethash bookkeeping-method-this 
bookkeeping)
+                              (puthash bookkeeping-method-this t 
bookkeeping)))))
+
+                      ;; Anonymous function level
+                      (when in-anonymous-function-nesting-level
+                        (setq bookkeeping-namespace (format "%s anonymous 
function %s" bookkeeping-namespace in-anonymous-function-number))))
+
+                    (unless bookkeeping-named
+                      (when (equal previous-token 'T_STATIC)
+                        (setq bookkeeping-namespace (concat 
bookkeeping-namespace " static")))
+                      (setq bookkeeping-namespace (concat 
bookkeeping-namespace " id " bookkeeping-variable-name)))
 
-                    (setq bookkeeping-namespace (concat bookkeeping-namespace 
" id " bookkeeping-variable-name))
                     (phps-mode-debug-message
                      (message "Bookkeeping-namespace: '%s'" 
bookkeeping-namespace))
 
                     ;; Support foreach as $key, for ($i = 0), if ($a = ), 
while ($a = ) and do-while ($a)assignments here
                     (when (and
+                           (equal token 'T_VARIABLE)
                            (string= previous-token "(")
                            (string= next-token "=")
                            (or (equal previous2-token 'T_IF)
@@ -1175,6 +1265,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
                     ;; Support foreach as $key => value
                     (when (and
+                           (equal token 'T_VARIABLE)
                            (equal previous3-token 'T_AS)
                            (equal previous2-token 'T_VARIABLE)
                            (equal previous-token 'T_DOUBLE_ARROW)
@@ -1182,16 +1273,31 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                       (setq bookkeeping-in-assignment t))
 
                     ;; Stand-alone variable assignment
-                    (when (and first-token-on-line
+                    (when (and (equal token 'T_VARIABLE)
+                               first-token-on-line
                                (string= next-token "="))
                       (setq bookkeeping-in-assignment t))
 
                     ;; Naming of value
-                    (when (equal previous-token 'T_AS)
+                    (when (and
+                           (equal token 'T_VARIABLE)
+                           (equal previous-token 'T_AS))
+                      (setq bookkeeping-in-assignment t))
+
+                    ;; In catch declaration
+                    (when (and
+                           (equal token 'T_VARIABLE)
+                           in-catch-declaration)
                       (setq bookkeeping-in-assignment t))
 
                     ;; In function arguments
-                    (when imenu-in-function-declaration
+                    (when (and imenu-in-function-declaration
+                               (equal token 'T_VARIABLE))
+                      (setq bookkeeping-in-assignment t))
+
+                    ;; In anonymous function arguments
+                    (when (and in-anonymous-function-declaration
+                               (equal token 'T_VARIABLE))
                       (setq bookkeeping-in-assignment t))
 
                     ;; Class variables
@@ -1217,19 +1323,42 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                          (message "Bookkeeping-assignment: '%s'" 
bookkeeping-namespace))
                         (puthash bookkeeping-namespace declarations 
bookkeeping)))
 
-                    (if (gethash bookkeeping-namespace bookkeeping)
-                        (progn
-                          (phps-mode-debug-message
-                           (message "Bookkeeping-hit: %s" bookkeeping-index))
-                          (puthash bookkeeping-index t bookkeeping))
+                    (if bookkeeping-is-superglobal
+                        ;; Super-globals always hit
+                        (puthash bookkeeping-index t bookkeeping)
 
-                      ;; Check super-globals
-                      (if (gethash bookkeeping-variable-name bookkeeping)
-                          (puthash bookkeeping-index t bookkeeping)
+                      ;; Check scoped variable
+                      (if (gethash bookkeeping-namespace bookkeeping)
+                          (progn
+                            (phps-mode-debug-message
+                             (message "Bookkeeping-hit: %s" bookkeeping-index))
+                            (puthash bookkeeping-index t bookkeeping))
                         (phps-mode-debug-message
                          (message "Bookkeeping-miss: %s" bookkeeping-index))
                         (puthash bookkeeping-index nil bookkeeping)))))
 
+                ;; Keep track of open catch blocks for bookkeeping
+                (when (equal token 'T_CATCH)
+                  (setq in-catch-declaration t))
+                (when (and in-catch-declaration
+                           (equal token "{"))
+                  (setq in-catch-declaration nil))
+
+                ;; Keep track of anonymous functions for bookkeeping
+                (when (and
+                       (equal token 'T_FUNCTION)
+                       (string= next-token "("))
+                  (setq in-anonymous-function-declaration t)
+                  (setq in-anonymous-function-number (1+ 
in-anonymous-function-number))
+                  (push (1+ curly-bracket-level) 
in-anonymous-function-nesting-level))
+                (when (and in-anonymous-function-declaration
+                           (equal token "{"))
+                  (setq in-anonymous-function-declaration nil))
+                (when (and in-anonymous-function-nesting-level
+                           (string= token "}")
+                           (equal curly-bracket-level (car 
in-anonymous-function-nesting-level)))
+                  (pop in-anonymous-function-nesting-level))
+
 
                 ;; IMENU LOGIC
 
@@ -2128,7 +2257,11 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
               ;; Update current token
               (setq previous3-token previous2-token)
               (setq previous2-token previous-token)
+              (setq previous2-token-end previous-token-end)
+              (setq previous2-token-start previous-token-start)
               (setq previous-token token)
+              (setq previous-token-end token-end)
+              (setq previous-token-start token-start)
               (setq token next-token)
               (setq token-start next-token-start)
               (setq token-end next-token-end)
diff --git a/phps-mode.el b/phps-mode.el
index 7d4b4b3..e12dcb1 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -5,8 +5,8 @@
 ;; Author: Christian Johansson <christian@cvj.se>
 ;; Maintainer: Christian Johansson <christian@cvj.se>
 ;; Created: 3 Mar 2018
-;; Modified: 9 Sep 2020
-;; Version: 0.3.53
+;; Modified: 11 Sep 2020
+;; Version: 0.3.54
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
diff --git a/test/phps-mode-test-lex-analyzer.el 
b/test/phps-mode-test-lex-analyzer.el
index cc664b4..8712414 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -1359,56 +1359,71 @@
    "Bookkeeping in root level variable assignments #1."
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list " id $var" 1) (list (list 8 12) t) (list (list 27 32) nil) (list (list 73 
77) t)))))
+            (list (list " id $var" 1) (list (list 8 12) t) (list (list 27 32) 
nil) (list (list 73 77) t)))))
 
   (phps-mode-test--with-buffer
    "<?php\n\n$var = 'abc';\n\nif ($var) {\n    echo 'This never 
happens';\n}\nif ($var2) {\n    echo 'This happens';\n}"
    "Bookkeeping in root level variable assignments #2."
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list " id $var" 1) (list (list 8 12) t) (list (list 27 31) t) (list (list 72 
77) nil)))))
+            (list (list " id $var" 1) (list (list 8 12) t) (list (list 27 31) 
t) (list (list 72 77) nil)))))
 
   (phps-mode-test--with-buffer
    "<?php\n\n$var2 = 4;\n\nfunction myFunction($var)\n{\n    $var3 = 3\n    if 
($var) {\n        echo 'Hit';\n    }\n    if ($var2) {\n        echo 'Miss';\n  
  }\n    if ($var3) {\n        echo 'Hit';\n    }\n}\n\nfunction 
myFunction2($abc)\n{\n    if ($var) {\n        echo 'Miss';\n    }\n    if 
($abc) {\n        echo 'Hit';\n    }\n}\n\nif ($var) {\n    echo 'Miss';\n}\nif 
($var2) {\n    echo 'Hit';\n}"
    "Bookkeeping in function level with variable assignments."
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list " id $var2" 1) (list (list 8 13) t) (list " function myFunction id $var" 
1) (list (list 40 44) t) (list " function myFunction id $var3" 1) (list (list 
52 57) t) (list (list 70 74) t) (list (list 112 117) nil) (list (list 156 161) 
t) (list " function myFunction2 id $abc" 1) (list (list 215 219) t) (list (list 
231 235) nil) (list  [...]
+            (list (list " id $var2" 1) (list (list 8 13) t) (list " function 
myFunction id $var" 1) (list (list 40 44) t) (list " function myFunction id 
$var3" 1) (list (list 52 57) t) (list (list 70 74) t) (list (list 112 117) nil) 
(list (list 156 161) t) (list " function myFunction2 id $abc" 1) (list (list 
215 219) t) (list (list 231 235) nil) (list (list 274 278) t) (list (list 315 
319) nil) (list (list 346 351) t)))))
 
   (phps-mode-test--with-buffer
-   "<?php\n\n// Super-globals\n\nif ($_GET) {\n    echo 'Hit';\n}\nif ($_POST) 
{\n    echo 'Hit';\n}\nif ($_COOKIE) {\n    echo 'Hit';\n}\nif ($_SESSION) {\n  
  echo 'Hit';\n}\nif ($_REQUEST) {\n    echo 'Hit';\n}\nif ($_GLOBALS) {\n    
echo 'Hit';\n}\nif ($_SERVER) {\n    echo 'Hit';\n}\n"
+   "<?php\n\n// Super-globals\n\nif ($_GET) {\n    echo 'Hit';\n}\nif ($_POST) 
{\n    echo 'Hit';\n}\nif ($_COOKIE) {\n    echo 'Hit';\n}\nif ($_SESSION) {\n  
  echo 'Hit';\n}\nif ($_REQUEST) {\n    echo 'Hit';\n}\nif ($_GLOBALS) {\n    
echo 'Hit';\n}\nif ($_SERVER) {\n    echo 'Hit';\n}\nif ($_FILES) {\n    echo 
'Hit';\n}\n"
    "Super-globals"
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list (list 30 35) t) (list (list 61 67) t) (list (list 93 101) t) (list (list 
127 136) t) (list (list 162 171) t) (list (list 197 206) t) (list (list 232 
240) t)))))
+            (list (list (list 30 35) t) (list (list 61 67) t) (list (list 93 
101) t) (list (list 127 136) t) (list (list 162 171) t) (list (list 197 206) t) 
(list (list 232 240) t) (list (list 266 273) t)))))
 
-  ;; TODO Should add support for self::stuff too
   (phps-mode-test--with-buffer
-   "<?php\n\n// Class properties\n\nclass myParent {}\n\nclass myClass extends 
myParent {\n    private $var1 = 123;\n    protected static $var2;\n    public 
$var3;\n    var $var4;\n    function __construct() {\n        if ($this) {\n    
        echo 'Hit';\n        }\n        if ($this->var1) {\n            echo 
'Hit';\n        }\n        if (self::$var2) {\n            echo 'Hit';\n        
}\n        if ($this->var3) {\n            echo 'Hit';\n        }\n        if 
($this->var4) {\n    [...]
+   "<?php\n\nnamespace myNamespaceA {\n    $var = 123;\n    class myClassA {\n 
       private $var2 = 123;\n        function myFunctionA($var3) {\n            
$var4 = 123;\n            if ($var) {\n                echo 'Miss';\n           
 }\n            if ($var2) {\n                echo 'Miss';\n            }\n     
       if ($var3) {\n                echo 'Hit';\n            }\n            if 
($var4) {\n                echo 'Hit';\n            }\n        }\n\n        
function myFuncti [...]
+   "Bookkeeping in maximum level with namespaces, classes and functions."
+   (should (equal
+            (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
+            (list (list " id $var" 1) (list (list 37 41) t) (list " namespace 
myNamespaceA class myClassA id $var2" 1) (list (list 86 91) t) (list " 
namespace myNamespaceA class myClassA function myFunctionA id $this" t) (list " 
namespace myNamespaceA class myClassA function myFunctionA id $var3" 1) (list 
(list 128 133) t) (list " namespace myNamespaceA class myClassA function 
myFunctionA id $var4" 1) (list (list 149 154) t) (list (list 178 182) nil) 
(list (list 245 250) nil) (list (list [...]
+
+  (phps-mode-test--with-buffer
+   "<?php\n\n// Conditional assignments\n\n$items = array(1, 2, 3);\nforeach 
($items as $item) {\n    if ($item) {\n        echo 'Hit';\n    }\n}\nforeach 
($items as $key => $value) {\n    if ($key || $value) {\n        echo 'Hit';\n  
  }\n}\nfor ($i = 0; $i < count($items); $i++) {\n    if ($i) {\n        echo 
'Hit';\n    }\n}\nif ($a = 123) {\n    if ($a) {\n        echo 'Hit';\n    
}\n}\nwhile ($b = 123) {\n    if ($a) {\n        echo 'Hit';\n    }\n}\ndo {\n  
  echo 'Hit';\n} while ( [...]
+   "Conditional assignments"
+   (should (equal
+            (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
+            (list (list " id $items" 1) (list (list 36 42) t) (list (list 70 
76) t) (list " id $item" 1) (list (list 80 85) t) (list (list 97 102) t) (list 
(list 143 149) t) (list " id $key" 1) (list (list 153 157) t) (list " id 
$value" 1) (list (list 161 167) t) (list (list 179 183) t) (list (list 187 193) 
t) (list " id $i" 1) (list (list 230 232) t) (list (list 238 240) t) (list 
(list 249 255) t) (list (list 258 260) t) (list (list 274 276) t) (list " id 
$a" 1) (list (list 312 314) t)  [...]
+
+  (phps-mode-test--with-buffer
+   "<?php\n\n// Class properties\n\nclass myParent {}\n\nclass myClass extends 
myParent {\n    private $var1 = 123;\n    protected static $var2;\n    public 
$var3;\n    var $var4;\n    function __construct() {\n        if ($this) {\n    
        echo 'Hit';\n        }\n        if ($this->var1) {\n            echo 
'Hit';\n        }\n        if (self::$var1) {\n            echo 'Miss';\n       
 }\n        if (self::$var2) {\n            echo 'Hit';\n        }\n        if 
($this->var3) {\n   [...]
    "Class properties"
+   ;; (message "Bookkeeping: %s" (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t))
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list " class myParent id $var1" 1) (list (list 93 98) t) (list " class 
myParent id $var2" 1) (list (list 127 132) t) (list " class myParent id $var3" 
1) (list (list 145 150) t) (list " class myParent id $var4" 1) (list (list 160 
165) t) (list " class myParent function __construct id $this" t) (list (list 
208 213) t) (list (list 263 2 [...]
+            (list (list " class myParent id $var1" 1) (list (list 93 98) t) 
(list " class myParent static id $var2" 1) (list (list 127 132) t) (list " 
class myParent id $var3" 1) (list (list 145 150) t) (list " class myParent id 
$var4" 1) (list (list 160 165) t) (list " class myParent function __construct 
id $this" t) (list (list 208 213) t) (list (list 263 268) t) (list (list 270 
274) t) (list (list 330 335) nil) (list (list 392 397) t) (list (list 447 452) 
t) (list (list 454 458) t) (l [...]
 
   (phps-mode-test--with-buffer
-   "<?php\n\nnamespace myNamespaceA {\n    $var = 123;\n    class myClassA {\n 
       private $var2 = 123;\n        function myFunctionA($var3) {\n            
$var4 = 123;\n            if ($var) {\n                echo 'Miss';\n           
 }\n            if ($var2) {\n                echo 'Miss';\n            }\n     
       if ($var3) {\n                echo 'Hit';\n            }\n            if 
($var4) {\n                echo 'Hit';\n            }\n        }\n\n        
function myFuncti [...]
-   "Bookkeeping in maximum level with namespaces, classes and functions."
+   "<?php\n\ntry {\n    \n} catch (\Exception $e) {\n    if ($e) {\n        
echo 'Hit';\n    }\n}\n\nif ($e) {\n    echo 'Miss';\n}\n"
+   "Try catch variable assignment"
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list " id $var" 1) (list (list 37 41) t) (list " namespace myNamespaceA class 
myClassA id $var2" 1) (list (list 86 91) t) (list " namespace myNamespaceA 
class myClassA function myFunctionA id $this" t) (list " namespace myNamespaceA 
class myClassA function myFunctionA id $var3" 1) (list (list 128 133) t) (list 
" namespace myNamespace [...]
+            (list (list " id $e" 1) (list (list 38 40) t) (list (list 52 54) 
t) (list (list 91 93) t)))))
 
   (phps-mode-test--with-buffer
-   "<?php\n\n// Conditional assignments\n\n$items = array(1, 2, 3);\nforeach 
($items as $item) {\n    if ($item) {\n        echo 'Hit';\n    }\n}\nforeach 
($items as $key => $value) {\n    if ($key || $value) {\n        echo 'Hit';\n  
  }\n}\nfor ($i = 0; $i < count($items); $i++) {\n    if ($i) {\n        echo 
'Hit';\n    }\n}\nif ($a = 123) {\n    if ($a) {\n        echo 'Hit';\n    
}\n}\nwhile ($b = 123) {\n    if ($a) {\n        echo 'Hit';\n    }\n}\ndo {\n  
  echo 'Hit';\n} while ( [...]
-   "Conditional assignments"
+   "<?php\n\n$example = function ($test) {\n    if ($test) {\n        echo 
'Hit';\n    }\n    if ($example) {\n        echo 'Miss';\n    }\n};\n$example2 
= function ($test2) use ($example) {\n    if ($test2) {\n        echo 'Hit';\n  
  }\n    if ($example) {\n        echo 'Hit';\n    }\n    if ($example2) {\n    
    echo 'Miss';\n    }\n    if ($example3) {\n        echo 'Miss';\n    
}\n};\nif ($test) {\n    echo 'Miss';\n}\nif ($test2) {\n    echo 'Miss';\n}"
+   "Anonymous function variable assignments"
    (should (equal
             (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list "$_COOKIE" t) (list "$_GET" t) (list "$_GLOBALS" t) 
(list "$_POST" t) (list "$_REQUEST" t) (list "$_SERVER" t) (list "$_SESSION" t) 
(list " id $items" 1) (list (list 36 42) t) (list (list 70 76) t) (list " id 
$item" 1) (list (list 80 85) t) (list (list 97 102) t) (list (list 143 149) t) 
(list " id $key" 1) (list (list 153 157) t) (list " id $value" 1) (list (list 
161 167) t) (list (list 179 183) t) (list (list 187 193) t) (list " id $i" 1) 
(list (list 230 232) t)  [...]
+            (list (list " id $example" 1) (list (list 8 16) t) (list " 
anonymous function 1 id $test" 1) (list (list 29 34) t) (list (list 46 51) t) 
(list (list 89 97) nil) (list " id $example2" 1) (list (list 131 140) t) (list 
" anonymous function 2 id $test2" 1) (list (list 153 159) t) (list " anonymous 
function 2 id $example" 1) (list (list 166 174) t) (list (list 186 192) t) 
(list (list 230 238) t) (list (list 276 285) nil) (list (list 324 333) nil) 
(list (list 371 376) nil) (list (l [...]
 
   )
 
 (defun phps-mode-test-lex-analyzer ()
   "Run test for functions."
   ;; (setq debug-on-error t)
+  (phps-mode-test-lex-analyzer--bookkeeping)
   (phps-mode-test-lex-analyzer--process-changes)
   (phps-mode-test-lex-analyzer--alternative-indentation)
   (phps-mode-test-lex-analyzer--move-lines-indent)
@@ -1425,8 +1440,7 @@
   (phps-mode-test-lex-analyzer--imenu)
   (phps-mode-test-lex-analyzer--get-moved-imenu)
   (phps-mode-test-lex-analyzer--comment-uncomment-region)
-  (phps-mode-test-lex-analyzer--move-lines-indent)
-  (phps-mode-test-lex-analyzer--bookkeeping))
+  (phps-mode-test-lex-analyzer--move-lines-indent))
 
 (phps-mode-test-lex-analyzer)
 



reply via email to

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