branch: externals/phps-mode commit 4d226f18ccb07f77742acfc5d30b03180a1e7fc5 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Bookkeeping via AST working with referenced foreach variables --- phps-mode-ast-bookkeeping.el | 28 +++++++++++++++++++--------- phps-mode-parser-sdt.el | 22 ++++++++++++++++++++++ test/phps-mode-test-ast.el | 4 ++-- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el index bd645fafcd..53a5e8d6f4 100644 --- a/phps-mode-ast-bookkeeping.el +++ b/phps-mode-ast-bookkeeping.el @@ -312,15 +312,25 @@ (dolist (child children) (push `(,scope ,child) bookkeeping-stack))) (when-let ((value (plist-get item 'value))) - (push - (list - scope - (list - 'ast-type - 'assign-variable - 'key - value)) - bookkeeping-stack)) + (if (equal (plist-get value 'ast-type) 'foreach-referenced-variable) + (push + (list + scope + (list + 'ast-type + 'assign-variable + 'key + (plist-get value 'variable))) + bookkeeping-stack) + (push + (list + scope + (list + 'ast-type + 'assign-variable + 'key + value)) + bookkeeping-stack))) (when-let ((key (plist-get item 'key))) (push (list diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index f0ef6c2673..a82a32bcba 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -354,6 +354,14 @@ (nth 1 args)) phps-mode-parser--table-translations) +;; foreach_variable -> ("&" variable) +(puthash + 194 + (lambda(args _terminals) + `(ast-type foreach-referenced-variable variable ,(nth 1 args)) + ) + phps-mode-parser--table-translations) + ;; if_stmt_without_else -> (T_IF "(" expr ")" statement) (puthash 223 @@ -696,6 +704,20 @@ ast-object)) phps-mode-parser--table-translations) +;; dereferencable_scalar -> (T_CONSTANT_ENCAPSED_STRING) +(puthash + 449 + (lambda(args _terminals) + (substring args 1 -1)) + phps-mode-parser--table-translations) + +;; scalar -> (T_LNUMBER) +(puthash + 451 + (lambda(args _terminals) + (string-to-number args)) + phps-mode-parser--table-translations) + ;; callable_variable -> (array_object_dereferencable "[" optional_expr "]") (puthash 483 diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index a4636ef861..569802af74 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -465,7 +465,7 @@ (list (list " id $items" 1) (list (list 7 13) 1) (list (list 41 47) 1) (list " id $item" 1) (list (list 52 57) 1) (list (list 69 74) 1) (list (list 115 121) 1) (list " id $key" 1) (list (list 125 129) 1) (list " id $item2" 1) (list (list 134 140) 1) (list (list 152 157) 1)))))) (phps-mode-test-ast--buffer-contents - "<?php\n\n[$random, $bandom] = myValues();\nif ($random) {\n echo 'Hit';\n}\nif ($bandom) {\n echo 'Hit';\n}\n\narray($random2, $bandom2) = myValues2();\nif ($random2) {\n echo 'Hit';\n}\nif ($bandom3) {\n echo 'Hit';\n}\n\n " + "<?php\n\n[$random, $bandom] = myValues();\nif ($random) {\n echo 'Hit';\n}\nif ($bandom) {\n echo 'Hit';\n}\n" "Bookkeeping of variable declarations in array" (lambda() (let ((parse (phps-mode-parser-parse))) @@ -483,7 +483,7 @@ (phps-mode-ast-bookkeeping--generate) (should (equal (phps-mode-test--hash-to-list phps-mode-ast-bookkeeping--index t) - (list (list " id $random" 1) (list (list 9 16) 1) (list " id $bandom" 1) (list (list 18 25) 1) (list (list 45 52) 1) (list (list 78 85) 1) (list " id $random2" 1) (list (list 114 122) 1) (list " id $bandom2" 1) (list (list 124 132) 1) (list (list 153 161) 1) (list (list 187 195) 0)))))) + (list (list " id $random" 1) (list (list 9 16) 1) (list " id $bandom" 1) (list (list 18 25) 1) (list (list 45 52) 1) (list (list 78 85) 1)))))) (phps-mode-test-ast--buffer-contents "<?php\n\n$var = 123;\n\nfunction test($abc) {\n global $var;\n if ($var) {\n echo 'Hit';\n }\n}"