branch: externals/phps-mode
commit 0bf9b31fefe7443dbbd808512f67c296244c1578
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Passed bookkeeping via SDT for try catch variables
---
phps-mode-ast.el | 3 +++
phps-mode-parser-sdt.el | 29 ++++++++++++++++++++++++-----
test/phps-mode-test-ast.el | 2 +-
3 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index 5483c9bb1d..0e392b127e 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -36,6 +36,9 @@
(setq
phps-mode-parser-sdt--bookkeeping-namespace
nil)
+ (setq
+ phps-mode-parser-sdt--bookkeeping-namespace-stack
+ nil)
(setq
phps-mode-parser-sdt--bookkeeping-symbol-stack
nil)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 6c7fb4b525..139c340665 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -1836,20 +1836,39 @@
(puthash
169
(lambda(args terminals)
+ (let ((optional-variable (nth 4 args))
+ (optional-variable-start)
+ (optional-variable-end))
+ (when optional-variable
+ (setq optional-variable-start (car (cdr (nth 4 terminals))))
+ (setq optional-variable-end (cdr (cdr (nth 4 terminals))))
+ (push
+ (list
+ optional-variable
+ phps-mode-parser-sdt--bookkeeping-namespace
+ optional-variable-start
+ optional-variable-end)
+ phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
+ (push
+ (list
+ optional-variable
+ phps-mode-parser-sdt--bookkeeping-namespace
+ optional-variable-start
+ optional-variable-end)
+ phps-mode-parser-sdt--bookkeeping-symbol-stack))
`(
ast-type
catch-list
catch-name-list
,(nth 3 args)
optional-variable
- ,(nth 4 args)
+ ,optional-variable
optional-variable-start
- ,(car (cdr (nth 4 terminals)))
+ ,optional-variable-start
optional-variable-end
- ,(cdr (cdr (nth 4 terminals)))
+ ,optional-variable-end
inner-statement-list
- ,(nth 7 args)
- ))
+ ,(nth 7 args))))
phps-mode-parser--table-translations)
;; 170 ((catch_name_list) (class_name))
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index ce995c6c02..4d79c3153c 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -251,7 +251,7 @@
(phps-mode-test-ast--should-bookkeep
"<?php\n\ntry {\n \n} catch (\\Exception $e) {\n if ($e) {\n
echo 'Hit';\n }\n}\n\nif ($e) {\n echo 'Miss';\n}\n"
"Bookkeeping of try catch variable assignment"
- '((" id $e" 1) ((39 41) 1) ((53 55) 1) ((92 94) 1)))
+ '((" id $e" ((39 41))) ((39 41) 1) ((53 55) 1) ((92 94) 1)))
(phps-mode-test-ast--should-bookkeep
"<?php\n\n$example = function ($test) {\n if ($test) {\n echo
'Hit';\n }\n if ($example) {\n echo 'Miss';\n }\n};\n$example2
= function ($test2) use ($example) {\n if ($test2) {\n echo 'Hit';\n
}\n if ($example) {\n echo 'Hit';\n }\n if ($example2) {\n
echo 'Miss';\n }\n if ($example3) {\n echo 'Miss';\n
}\n};\nif ($test) {\n echo 'Miss';\n}\nif ($test2) {\n echo 'Miss';\n}"