[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 4d226f18cc 048/212: Bookkeeping via AST worki
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 4d226f18cc 048/212: Bookkeeping via AST working with referenced foreach variables |
Date: |
Wed, 26 Jan 2022 01:50:40 -0500 (EST) |
branch: externals/phps-mode
commit 4d226f18ccb07f77742acfc5d30b03180a1e7fc5
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@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}"
- [elpa] externals/phps-mode 7135a30446 173/212: Updated TODO items, (continued)
- [elpa] externals/phps-mode 7135a30446 173/212: Updated TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 63c5fef240 175/212: Started on tests for more basic functions of indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 735f1e0c89 176/212: More notes, Christian Johansson, 2022/01/26
- [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 <=
- [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, 2022/01/26
- [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