[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode d456658676 089/135: Passing bookkeeping test
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode d456658676 089/135: Passing bookkeeping test for $this inside arrow function |
Date: |
Sun, 29 Jan 2023 03:11:07 -0500 (EST) |
branch: externals/phps-mode
commit d4566586764e1ce3ca88e8b55e68dcac4fe849c9
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing bookkeeping test for $this inside arrow function
---
phps-mode-parser-sdt.el | 76 +++++++++++++++++++++++++++++-----------------
test/phps-mode-test-ast.el | 6 ++--
2 files changed, 51 insertions(+), 31 deletions(-)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 3382481f34..7904d8ccf4 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -642,30 +642,40 @@
;; Should add one scope look-ahead to determine if we should
;; ignore function scope before a $this-> or self:: or static::
operator
(when (< scope-index (1- scope-count))
- (setq next-scope (nth (1+ scope-index) scope))
- (setq next-scope-type (car next-scope))
- (cond
- ((equal next-scope-type 'global)
- (setq next-scope-is-global t))
- ((equal next-scope-type 'object-operator)
- (let ((downcased-scope-name (downcase (car (cdr
next-scope)))))
- (when (string= downcased-scope-name "$this")
- (setq next-scope-is-this-object-operator t))))
- ((equal next-scope-type 'static-member)
- (let ((downcased-scope-name (downcase (car (cdr
next-scope)))))
- (when (or
- (string= downcased-scope-name "self")
- (string= downcased-scope-name "static"))
-
- (let ((potential-uri-count (length potential-uris))
- (potential-uri-index 0))
- (while (< potential-uri-index potential-uri-count)
- (setf
- (nth potential-uri-index potential-uris)
- (format " static%s" (nth potential-uri-index
potential-uris)))
- (setq potential-uri-index (1+ potential-uri-index))))
-
- (setq next-scope-is-self-static-member-operator t))))))
+ (let ((next-scope-index (1+ scope-index)))
+ (setq next-scope (nth next-scope-index scope))
+ (setq next-scope-type (car next-scope))
+
+ ;; When next scope is arrow function, ignore it
+ (while (and
+ (equal next-scope-type 'arrow-function)
+ (< next-scope-index (1- scope-count)))
+ (setq next-scope-index (1+ next-scope-index))
+ (setq next-scope (nth next-scope-index scope))
+ (setq next-scope-type (car next-scope)))
+
+ (cond
+ ((equal next-scope-type 'global)
+ (setq next-scope-is-global t))
+ ((equal next-scope-type 'object-operator)
+ (let ((downcased-scope-name (downcase (car (cdr
next-scope)))))
+ (when (string= downcased-scope-name "$this")
+ (setq next-scope-is-this-object-operator t))))
+ ((equal next-scope-type 'static-member)
+ (let ((downcased-scope-name (downcase (car (cdr
next-scope)))))
+ (when (or
+ (string= downcased-scope-name "self")
+ (string= downcased-scope-name "static"))
+
+ (let ((potential-uri-count (length potential-uris))
+ (potential-uri-index 0))
+ (while (< potential-uri-index potential-uri-count)
+ (setf
+ (nth potential-uri-index potential-uris)
+ (format " static%s" (nth potential-uri-index
potential-uris)))
+ (setq potential-uri-index (1+
potential-uri-index))))
+
+ (setq next-scope-is-self-static-member-operator
t)))))))
(let ((space-type (car item))
(space-name (car (cdr item))))
@@ -769,6 +779,7 @@
(let ((potential-uri-count (length potential-uris))
(potential-uri-index 0)
(matching-uri))
+ (message "potential-uris: %S" potential-uris)
;; Iterate potential-uris, select first match or if no match return
the first
(while (< potential-uri-index potential-uri-count)
@@ -3344,6 +3355,7 @@
symbol-end)
phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))))))))
+ ;; Method Declaration
((equal attributed-class-statement-type 'method)
;; Go through stacks and modify symbol namespaces
;; - add function scope but only for:
@@ -3367,6 +3379,7 @@
'parameter-list))
(is-static-p))
+ ;; Is static method?
(when-let (method-modifiers
(plist-get
attributed-class-statement
@@ -3374,7 +3387,10 @@
(dolist (method-modifier method-modifiers)
(when (equal method-modifier 'static)
(setq is-static-p t))))
+
(when (and function-start function-end)
+
+ ;; Add $this symbol in scope unless method is static
(unless is-static-p
(push
(list
@@ -3383,6 +3399,10 @@
(plist-get attributed-class-statement 'ast-start)
(plist-get attributed-class-statement 'ast-end))
phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))
+
+ ;; TODO if we have a arrow function scope function should come
before it (to the right)
+
+ ;; Add function scope to symbol assignments
(when phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack
(dolist (
symbol-list
@@ -3402,6 +3422,8 @@
(setcar
(cdr symbol-list)
symbol-scope))))))
+
+ ;; Add function scope to symbol reads
(when phps-mode-parser-sdt--bookkeeping-symbol-stack
(dolist (
symbol-list
@@ -3416,14 +3438,12 @@
(< symbol-start function-start)
(> symbol-start function-end))
(let ((symbol-scope (car (cdr symbol-list))))
- (push
- (list 'function function-name)
- symbol-scope)
+ (push (list 'function function-name) symbol-scope)
(setcar
(cdr symbol-list)
symbol-scope)))))))
- ;; Bookkeep method parameters
+ ;; Create symbol assignments out of method parameters
(let ((symbol-scope
phps-mode-parser-sdt--bookkeeping-namespace))
(push (list 'function function-name) symbol-scope)
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 80e901d542..091167e56a 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -364,12 +364,12 @@
'((" class MyClass function there id $this" ((139 196))) ((153 158) 1) ((68
73) 0)))
(phps-mode-test-ast--should-bookkeep
- "<?php\n\nclass myClass\n{\n private $test = 'abc';\n public function
test($d)\n {\n return fn($e) => $this->test . $d . $e;\n
}\n}\n\n$a = new myClass();\necho $a->test('def')('ghi');"
+ "<?php\n\nclass myClass\n{\n private $tost = 'abc';\n public function
test($d)\n {\n return fn($e) => $this->tost . $d . $e;\n
}\n}\n\n$a = new myClass();\necho $a->test('def')('ghi');"
"Bookkeeping of $this reference inside arrow function inside of method"
- '((" class myClass id $test" 1) ((36 41) 1) (" class myClass function test
id $this" 1) (" class myClass function test id $d" 1) ((76 78) 1) (" class
myClass function test arrow function 1 id $e" 1) ((104 106) 1) ((111 116) 1)
((118 122) 1) ((125 127) 1) ((130 132) 1) (" id $a" 1) ((143 145) 1)))
+ '((" class myClass function test id $d" ((76 78))) (" class myClass
function test id $this" ((84 139))) (" class myClass arrow 1 function test id
$e" ((104 106))) (" class myClass id $tost" ((36 41))) ((104 106) 1) ((130 132)
1) ((125 127) 1) ((118 122) 1) ((111 116) 1) (" id $a" ((143 145))) ((143 145)
1) ((168 170) 1)))
(phps-mode-test-ast--should-bookkeep
- "<?php class myClass { static $var = '123'; static function myMethod($a) {
return fn($b) => self::$var . $a . $b; }} echo myClass::myMethod('4')('5');"
+ "<?php\n\nclass myClass\n{\n static $var = '123';\n static function
myMethod($a)\n {\n return fn($b) => self::$var . $a . $b;\n
}\n}\n\necho myClass::myMethod('4')('5');"
"Bookkeeping of self reference inside arrow function inside of static
method"
'((" class myClass static id $var" 1) ((30 34) 1) (" class myClass function
myMethod id $a" 1) ((69 71) 1) (" class myClass function myMethod arrow
function 1 id $b" 1) ((85 87) 1) ((98 102) 1) ((105 107) 1) ((110 112) 1)))
- [elpa] externals/phps-mode 3b6eb46d4c 129/135: Added new MVP bookkeeping and imenu test, (continued)
- [elpa] externals/phps-mode 3b6eb46d4c 129/135: Added new MVP bookkeeping and imenu test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode f9ddef260c 039/135: Passing first bookkeeping test using SDT generated bookkeeping, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode fb42b49970 044/135: Added more TODO items, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode dd2fadefe7 048/135: Bookkeeping class properties, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 804a0dbdb9 074/135: Added static uri for symbol names, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 7bb676dc8b 076/135: Bookkeeping for anonymous function passing, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode f86d8dc6ac 078/135: More work on arrow function variable uri, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 787aaa2bb4 081/135: Passing another bookkeeping test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 66c02b9be1 083/135: Passing test for bookkeeping of interface variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 1afe6aaec7 086/135: Passing more tests for static variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d456658676 089/135: Passing bookkeeping test for $this inside arrow function,
Christian Johansson <=
- [elpa] externals/phps-mode f4be94ccfc 094/135: Passing bookkeeping test for class properties inside conditional expression, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 18f1f12fc6 096/135: Added new bookkeeping test for class parameters in constructor method, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 6d3cadbdf0 104/135: More integration of new imenu and bookkeeping via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 171e96b043 123/135: Fixes for some tests, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 6944154fd3 125/135: Imenu via SDT passing some more tests, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d1b1fd0a19 071/135: Started bookkeeping of arrow function variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode ae68e19c0a 080/135: Passing bookkeeping arrow function, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode f053587ff6 091/135: Passing another bookkeeping test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 9c43bc30c4 103/135: Removed old bookkeeping and imenu and integrated new via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode a447ae69ba 106/135: Starting on generating imenu index for namespaces, classes, methods, traits, interfaces via SDT, Christian Johansson, 2023/01/29