branch: externals/phps-mode commit 1e659967a80dcadce45af91ecefa88d95874a4fb Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
More work on constants bookkeeping --- phps-mode-parser-sdt.el | 57 +++++++++++++++++++++++++++++++++++++--------- test/phps-mode-test-ast.el | 2 +- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index 61deae238f..7d0bfe8c7c 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -6860,13 +6860,13 @@ (substring constant-name 0 namespace-last-pos)) (setq constant-name - (substring constant-name namespace-last-pos))) + (substring constant-name (1+ namespace-last-pos)))) ;; (message "constant-name: %S %S" constant-name constant-namespace) (push (list constant-name - (if constant-namespace '((namespace constant-namespace)) nil) + (if constant-namespace `((namespace ,constant-namespace)) nil) constant-start constant-end) phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))))))))))) @@ -7202,24 +7202,59 @@ (constant-start (car (cdr terminals))) (constant-end (cdr (cdr terminals)))) (cond + ((equal constant-name-type 'string-name) - (push - (list - constant-name - nil - constant-start - constant-end) - phps-mode-parser-sdt--bookkeeping-symbol-stack)) + ;; TODO When reading this symbol should check global namespace + ;; and namespace constants for hit + (let ((symbol-scope phps-mode-parser-sdt--bookkeeping-namespace)) + (push (list 'constant) symbol-scope) + (push + (list + constant-name + symbol-scope + constant-start + constant-end) + phps-mode-parser-sdt--bookkeeping-symbol-stack))) ((equal constant-name-type 'qualified-name) ;; TODO Handle this ) + ((equal constant-name-type 'fully-qualified-name) - ;; TODO Handle this - ) + (let* ((constant-namespace) + (string-pos 0) + (namespace-pos + (string-search "\\" constant-name string-pos)) + (namespace-last-pos namespace-pos)) + + ;; Extract any potential constant namespace here + (when namespace-pos + (setq string-pos (1+ string-pos)) + (setq namespace-pos (string-search "\\" constant-name string-pos)) + (while namespace-pos + (setq namespace-last-pos namespace-pos) + (setq string-pos (1+ string-pos)) + (setq namespace-pos (string-search "\\" constant-name string-pos))) + (unless (= namespace-last-pos 0) + (setq + constant-namespace + (substring constant-name 1 namespace-last-pos))) + (setq + constant-name + (substring constant-name (1+ namespace-last-pos)))) + + (push + (list + constant-name + (if constant-namespace `((namespace ,constant-namespace)) nil) + constant-start + constant-end) + phps-mode-parser-sdt--bookkeeping-symbol-stack))) + ((equal constant-name-type 'relative-name) ;; TODO Handle this ) + )) `( diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index 618a2e2f87..2362f06d2c 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -137,7 +137,7 @@ (phps-mode-test-ast--should-bookkeep "<?php\n\nnamespace mySpace\n{\n define('MY_CONSTANT', 'abc123');\n const MY_CONSTANT2 = 'def456';\n\n if (\\MY_CONSTANT) {\n echo 'hit';\n }\n if (MY_CONSTANT) {\n echo 'hit';\n }\n if (MY_CONSTANT2) {\n echo 'hit';\n }\n if (\\mySpace\\MY_CONSTANT2) {\n echo 'hit';\n }\n\n if (\\YOUR_CONSTANT) {\n echo 'miss';\n }\n if (YOUR_CONSTANT) {\n echo 'miss';\n }\n if (\\MY_CONSTANT2) {\n echo 'mis [...] "Constants in all possible scopes" - '(("abc")) + '(((159 170) 1) ((208 220) 1) ((371 384) 0) ((848 862) 5) ((900 911) 1) ((1000 1011) 1)) '(("abc"))) (phps-mode-test-ast--should-bookkeep