branch: externals/phps-mode
commit ae68e19c0ae11baef1ab7a64a75adeacde838f04
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Passing bookkeeping arrow function
---
phps-mode-parser-sdt.el | 57 +++++++++++++++++++++++-----------------------
test/phps-mode-test-ast.el | 2 +-
2 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 6f2d4bbaa9..8537608f76 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -763,9 +763,9 @@
(format " arrow %s%s" space-name (nth
potential-uri-index potential-uris))
new-potential-uris)
(setq potential-uri-index (1+ potential-uri-index)))
- (setq potential-uris (append potential-uris
new-potential-uris))
- (message "new-potential-uris: %S" new-potential-uris)
- (message "potential-uris: %S" potential-uris)
+ (setq potential-uris (append new-potential-uris
potential-uris))
+ ;; (message "new-potential-uris: %S" new-potential-uris)
+ ;; (message "potential-uris: %S" potential-uris)
))
;; TODO Below should alter symbol namespaces instead of build
namespace data
@@ -782,15 +782,16 @@
(let ((potential-uri-count (length potential-uris))
(potential-uri-index 0)
(matching-uri))
+
;; Iterate potential-uris, select first match or if no match return
the first
(while (< potential-uri-index potential-uri-count)
(setf
(nth potential-uri-index potential-uris)
(format "%s id %s" (nth potential-uri-index potential-uris) name))
- (setq potential-uri-index (1+ potential-uri-index))
(let ((potential-uri (nth potential-uri-index potential-uris)))
(when (gethash potential-uri phps-mode-parser-sdt-bookkeeping)
- (setq matching-uri potential-uri))))
+ (setq matching-uri potential-uri)))
+ (setq potential-uri-index (1+ potential-uri-index)))
(if matching-uri
matching-uri
(nth 0 potential-uris))))))
@@ -5192,7 +5193,6 @@
(puthash
440
(lambda(args terminals)
- ;; TODO Perform bookkeeping here
(let ((namespace
phps-mode-parser-sdt--bookkeeping-namespace)
(parameter-list
@@ -5206,6 +5206,27 @@
phps-mode-parser-sdt--bookkeeping-arrow-function-count)
namespace)
+ ;; Go through symbol stack in scope and add namespace
+ (when phps-mode-parser-sdt--bookkeeping-symbol-stack
+ (dolist (
+ symbol-list
+ phps-mode-parser-sdt--bookkeeping-symbol-stack)
+ (let ((symbol-name (nth 0 symbol-list))
+ (symbol-namespace (nth 1 symbol-list))
+ (symbol-start (nth 2 symbol-list)))
+ (unless (gethash
+ symbol-name
+ phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+ (let ((symbol-scope (car (cdr symbol-list))))
+ (push
+ (list
+ 'arrow-function
+ phps-mode-parser-sdt--bookkeeping-arrow-function-count)
+ symbol-scope)
+ (setcar
+ (cdr symbol-list)
+ symbol-scope))))))
+
;; Go through parameters and assign variables inside function
(when parameter-list
(dolist (parameter parameter-list)
@@ -5236,29 +5257,7 @@
namespace
parameter-start
parameter-end)
- phps-mode-parser-sdt--bookkeeping-symbol-stack)))))))
-
- ;; Go through phps-mode-parser-sdt--bookkeeping-symbol-stack in scope and
add namespace
- (when phps-mode-parser-sdt--bookkeeping-symbol-stack
- (dolist (
- symbol-list
- phps-mode-parser-sdt--bookkeeping-symbol-stack)
- (let ((symbol-name (nth 0 symbol-list))
- (symbol-namespace (nth 1 symbol-list))
- (symbol-start (nth 2 symbol-list)))
- (unless (gethash
- symbol-name
- phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
- (let ((symbol-scope (car (cdr symbol-list))))
- (push
- (list
- 'arrow-function
- phps-mode-parser-sdt--bookkeeping-arrow-function-count)
- symbol-scope)
- (setcar
- (cdr symbol-list)
- symbol-scope)))))))
-
+ phps-mode-parser-sdt--bookkeeping-symbol-stack))))))))
`(
ast-type
inline-fn
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index a824a3a67a..da96e06aee 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -281,7 +281,7 @@
(phps-mode-test-ast--should-bookkeep
"<?php\n$y = 1;\n$fn1 = fn($x) => $x + $y;\n$z = 1;\n$fn = fn($x2) =>
fn($y2) => $x2 * $y2 + $z;\nfn(array $x3) => $x3;\n$x4 = 4;\nstatic fn(): int
=> $x4;\nfn($x5 = 42) => $x5;\nfn(&$x6) => $x6;\nfn&($x7) => $x7;\nfn($x8,
...$rest) => $rest;"
"Bookkeeping in arrow functions"
- '((" id $y" 1) ((7 9) 1) (" id $fn1" 1) ((15 19) 1) (" arrow function 1 id
$x" 1) ((25 27) 1) ((32 34) 1) ((37 39) 1) (" id $z" 1) ((41 43) 1) (" id $fn"
1) ((49 52) 1) (" arrow function 2 id $x2" 1) ((58 61) 1) (" arrow function 2
arrow function 3 id $y2" 1) ((69 72) 1) ((77 80) 1) ((83 86) 1) ((89 91) 1) ("
arrow function 4 id $x3" 1) ((102 105) 1) ((110 113) 1) (" id $x4" 1) ((115
118) 1) ((144 147) 1) (" arrow function 6 id $x5" 1) ((152 155) 1) ((165 168)
1) (" arrow function 7 i [...]
+ '((" id $y" ((7 9))) ((7 9) 1) (" id $fn1" ((15 19))) (" arrow 1 id $x"
((25 27))) ((25 27) 1) ((37 39) 1) ((32 34) 1) ((15 19) 1) (" id $z" ((41 43)))
((41 43) 1) (" id $fn" ((49 52))) (" arrow 3 id $x2" ((58 61))) (" arrow 2 id
$y2" ((69 72))) ((58 61) 1) ((69 72) 1) ((89 91) 1) ((83 86) 1) ((77 80) 1)
((49 52) 1) (" arrow 4 id $x3" ((102 105))) ((102 105) 1) ((110 113) 1) (" id
$x4" ((115 118))) ((115 118) 1) ((144 147) 1) (" arrow 6 id $x5" ((152 155)))
((152 155) 1) ((165 168) 1) [...]
(phps-mode-test-ast--should-bookkeep
"<?php\n$z = (object) array('name' => 'random');\nif ($z->name) {\n echo
'Hit';\n}"