branch: externals/phps-mode commit f4d2164f8b97d4393ba7317608f5b4021606591b Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Bookkeeping via parser SDT passing static variables in function --- phps-mode-ast-bookkeeping.el | 34 +++++++++++++++++++++++++--------- phps-mode-parser-sdt.el | 8 ++++---- test/phps-mode-test-ast.el | 4 +++- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el index 77f853866c..41002d560d 100644 --- a/phps-mode-ast-bookkeeping.el +++ b/phps-mode-ast-bookkeeping.el @@ -110,14 +110,15 @@ (scope name &optional read-only) "Generate variable scope string from SCOPE and NAME and optionally READ-ONLY." (let ((scope-strings) - (bubbles-stack (list (list "" nil (reverse scope))))) ;; scope-string namespace bubbles + (bubbles-stack (list (list "" nil nil (reverse scope))))) ;; scope-string namespace bubbles (while bubbles-stack (setq bubbles-data (pop bubbles-stack)) (let ((scope-string (car bubbles-data)) (namespace (car (cdr bubbles-data))) - (bubbles (car (cdr (cdr bubbles-data))))) + (class (car (cdr (cdr bubbles-data)))) + (bubbles (car (cdr (cdr (cdr bubbles-data)))))) (while bubbles (let* ((bubble (pop bubbles)) (scope-type (plist-get bubble 'type)) @@ -148,17 +149,30 @@ (format "%s class %s" scope-string - scope-name)))) + scope-name))) + (setq + class + scope-name)) ((and (equal scope-type 'function) scope-name) - (setq - scope-string - (format - "%s function %s" - scope-string - scope-name))) + (if (and + namespace + (not class)) + (setq + scope-string + (format + "%s namespace %s function %s" + scope-string + namespace + scope-name)) + (setq + scope-string + (format + "%s function %s" + scope-string + scope-name)))) ((and (equal scope-type 'inline-function) @@ -180,6 +194,7 @@ (list scope-string namespace + class bubbles) bubbles-stack)) (setq @@ -199,6 +214,7 @@ (list scope-string namespace + class bubbles) bubbles-stack)) (setq diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index 1919616bb2..a960db1678 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -522,13 +522,13 @@ ast-type variable name - ,(nth 0 args) + ,args index - ,(car (cdr (nth 0 terminals))) + ,(car (cdr terminals)) start - ,(car (cdr (nth 0 terminals))) + ,(car (cdr terminals)) end - ,(cdr (cdr (nth 0 terminals))))) + ,(cdr (cdr terminals)))) phps-mode-parser--table-translations) ;; static_var -> (T_VARIABLE "=" expr) diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index a8715957e0..38b13cd274 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -849,7 +849,7 @@ (phps-mode-test-ast--buffer-contents "<?php\n\n$a = $b = $c = 3;\n\nif ($a) {\n echo 'a=',$a;\n} else {\n echo '$a is undefined!';\n}\nif ($b) {\n echo 'b=',$b;\n} else {\n echo '$b is undefined!';\n}\nif ($c) {\n echo 'c=',$c;\n} else {\n echo '$c is undefined!';\n}" - "Bookkeeping of typed class variables" + "Bookkeeping of chained variable assignments" (lambda() (let ((parse (phps-mode-parser-parse))) (message "Left-to-right with right-most derivation:\n%S\n" parse) @@ -869,6 +869,8 @@ (phps-mode-test--hash-to-list phps-mode-ast-bookkeeping--index t) '((" id $a" 1) ((8 10) 1) (" id $b" 1) ((13 15) 1) (" id $c" 1) ((18 20) 1) ((31 33) 1) ((51 53) 1) ((99 101) 1) ((119 121) 1) ((167 169) 1) ((187 189) 1)))))) + ;; TODO Test nullable typed class properties + ;; TODO Test variables inside static function and method ;; TODO Test this and make sure all variables hit