[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode a629baba89 053/212: More work on bookkeeping
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode a629baba89 053/212: More work on bookkeeping via AST for arrow function variables |
Date: |
Wed, 26 Jan 2022 01:50:42 -0500 (EST) |
branch: externals/phps-mode
commit a629baba89b3f4da9fc9ef53d09e61f4b0131946
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on bookkeeping via AST for arrow function variables
---
phps-mode-ast-bookkeeping.el | 58 +++++++++++++++++++++++++++++++++++++++-----
phps-mode-parser-sdt.el | 2 +-
test/phps-mode-test-ast.el | 2 +-
3 files changed, 54 insertions(+), 8 deletions(-)
diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el
index eeeab5f929..4e2a713399 100644
--- a/phps-mode-ast-bookkeeping.el
+++ b/phps-mode-ast-bookkeeping.el
@@ -78,6 +78,16 @@
scope-string
scope-name)))
+ ((and
+ (equal scope-type 'arrow-function)
+ scope-name)
+ (setq
+ scope-string
+ (format
+ "%s arrow function %s"
+ scope-string
+ scope-name)))
+
((and
(equal scope-type 'static)
(setq
@@ -96,8 +106,8 @@
scope-string))
(defun phps-mode-ast-bookkeeping--generate-variable-scope-string
- (scope name)
- "Generate variable scope string from SCOPE and NAME."
+ (scope name &optional read-only)
+ "Generate variable scope string from SCOPE and NAME and optionally
READ-ONLY."
(let ((scope-string "")
(namespace))
(dolist (bubble (reverse scope))
@@ -150,6 +160,17 @@
scope-string
scope-name)))
+ ((and
+ (equal scope-type 'arrow-function)
+ scope-name
+ (not read-only))
+ (setq
+ scope-string
+ (format
+ "%s arrow function %s"
+ scope-string
+ scope-name)))
+
((and
(equal scope-type 'static)
(setq
@@ -171,7 +192,8 @@
"Generate AST for current buffer."
(let ((bookkeeping (make-hash-table :test 'equal))
(bookkeeping-stack phps-mode-ast--tree)
- (inline-function-count 0))
+ (inline-function-count 0)
+ (arrow-function-count 0))
(while bookkeeping-stack
(let ((item-raw (pop bookkeeping-stack))
(item)
@@ -625,11 +647,35 @@
((equal type 'static-inline-function)
(push `(,scope ,(plist-get item 'inline-function))
bookkeeping-stack))
+ ((equal type 'arrow-function)
+ (let ((sub-scope scope))
+ (setq arrow-function-count (1+ arrow-function-count))
+ (push `(type arrow-function name ,arrow-function-count)
sub-scope)
+ (when-let ((inner-statement-list (reverse (plist-get item
'inner-statement-list))))
+ (dolist (inner-statement inner-statement-list)
+ (push `(,sub-scope ,inner-statement) bookkeeping-stack)))
+ (when-let ((parameter-list (plist-get item 'parameter-list)))
+ (dolist (parameter parameter-list)
+ (let ((id
+
(phps-mode-ast-bookkeeping--generate-variable-scope-string
+ sub-scope
+ (plist-get parameter 'name)))
+ (object
+ (list
+ (plist-get parameter 'start)
+ (plist-get parameter 'end))))
+ (puthash
+ id
+ 1
+ bookkeeping)
+ (puthash
+ object
+ 1
+ bookkeeping))))))
+
((equal type 'inline-function)
- (setq
- inline-function-count
- (1+ inline-function-count))
(let ((sub-scope scope))
+ (setq inline-function-count (1+ inline-function-count))
(push `(type inline-function name ,inline-function-count)
sub-scope)
(when-let ((inner-statement-list (reverse (plist-get item
'inner-statement-list))))
(dolist (inner-statement inner-statement-list)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 1112367852..d37f16630d 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -748,7 +748,7 @@
(let ((ast-object
(list
'ast-type
- 'inline-function
+ 'arrow-function
'start
(car (cdr (nth 9 terminals)))
'end
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 883d2b8eb2..77332896c2 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -537,7 +537,7 @@
(should
(equal
(phps-mode-test--hash-to-list phps-mode-ast-bookkeeping--index t)
- '((" id $y" 1) ((7 9) 1) (" id $fn1" 1) ((15 19) 1) (" anonymous
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) (" anonymous function 2 id $x2" 1) ((58 61) 1) ("
anonymous function 2 anonymous function 3 id $y2" 1) ((69 72) 1) ((77 80) 1)
((83 86) 1) ((89 91) 1) (" anonymous function 3 id $x3" 1) ((102 105) 1) ((110
113) 1) (" id $x4" 1) ((115 118) 1) ((144 147) 1) (" anonymous function 6 id
$x5" 1) ((152 155) 1) ((165 1 [...]
+ '((" 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 3 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 [...]
(phps-mode-test-ast--buffer-contents
"<?php\n$z = (object) array('name' => 'random');\nif ($z->name) {\n echo
'Hit';\n}"
- [elpa] externals/phps-mode 73d460d5a4 181/212: Passing lexer tests with optimized lexer, (continued)
- [elpa] externals/phps-mode 73d460d5a4 181/212: Passing lexer tests with optimized lexer, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e5df43eea9 187/212: More tweaking of indentation helpers, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 413547fbf1 188/212: Searching for previous bracket now steps over optional PHP starting tags, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4b4a96fda2 208/212: Improved cache filename, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode ef97058a67 184/212: Added more tests for indentation helper functions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a1af5b11fb 040/212: More work on bookkeeping of class properties via AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4dc07c9041 050/212: Bookkeeping via AST working with assigned variables from array, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4d226f18cc 048/212: Bookkeeping via AST working with referenced foreach variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5603e6266b 047/212: SDT for array values, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 787d82313e 045/212: Bookkeeping via AST now tracks variables around inline-functions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a629baba89 053/212: More work on bookkeeping via AST for arrow function variables,
Christian Johansson <=
- [elpa] externals/phps-mode df0b707a61 044/212: Added parser SDT for inline-function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 432382eddb 051/212: Added bookkeeping support for global variables in functions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode bb381d8127 041/212: Bookkeeping of class properties via AST passed test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e95df1027b 042/212: Reverted old tests for imenu and bookkeeping for lex-analyzer, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a65c8af308 008/212: Extract ast code into separate file and test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 23c001c33f 037/212: Moved parser SDT to separate file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 261121f096 056/212: Fixed incorrect information in debug output in test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e8a47de694 052/212: Work on supported arrow functions for bookkeeping via AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5686703a6b 074/212: Passing bookkeeping via AST for $this inside arrow function body inside class method, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a9d0e941df 066/212: Started on SDT for static variables statement, Christian Johansson, 2022/01/26