[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode eefe70b999 072/135: Work on improving symbol
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode eefe70b999 072/135: Work on improving symbol URI calculation |
Date: |
Sun, 29 Jan 2023 03:11:05 -0500 (EST) |
branch: externals/phps-mode
commit eefe70b9991c364fbf2774dc03ea2879fefadc85
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Work on improving symbol URI calculation
---
phps-mode-parser-sdt.el | 288 +++++++++++++++++++++++++-----------------------
1 file changed, 151 insertions(+), 137 deletions(-)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 7f491b1727..513070d059 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -628,126 +628,132 @@
(defun phps-mode-parser-sdt--get-symbol-uri (name scope)
"Get URI from symbol NAME in SCOPE."
- (let ((namespace)
- (class)
- (interface)
- (trait)
- (function)
- (is-static-p)
- (anonymous-function)
- (arrow-function))
- (when scope
- (dolist (item scope)
- (let ((space-type (car item))
- (space-name (car (cdr item))))
- (cond
- ((equal space-type 'namespace)
- (setq namespace space-name))
- ((equal space-type 'class)
- (setq class space-name))
- ((equal space-type 'interface)
- (setq interface space-name))
- ((equal space-type 'trait)
- (setq trait space-name))
- ((equal space-type 'function)
- (setq function space-name))
- ((equal space-type 'anonymous-function)
- (setq anonymous-function space-name))
- ((equal space-type 'arrow-function)
- (setq arrow-function space-name))
- ((equal space-type 'global)
- (setq namespace nil)
- (setq class nil)
- (setq function nil)
- (setq arrow-function nil)
- (setq anonymous-function nil))
- ((equal space-type 'object-operator)
- (let ((downcased-space-name
- (downcase space-name)))
- (cond
- ((string= downcased-space-name "$this")
- (setq function nil))
- (t
- ;; TODO Do something here
- ))))
- ((equal space-type 'static-member)
- (let ((downcased-space-name
- (downcase space-name)))
- (cond
- ((or
- (string= downcased-space-name "self")
- (string= downcased-space-name "static"))
- (setq is-static-p t)
- (setq function nil))
- (t
- ;; TODO Do something here
- ))))
- ((equal space-type 'static)
- (setq is-static-p t))))))
- (if (gethash
- name
- phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
- name
- (let ((new-symbol-name
- (format
- " id %s"
- name)))
- (when anonymous-function
- (setq
- new-symbol-name
- (format
- " anonymous function%s%s"
- anonymous-function
- new-symbol-name)))
- (when arrow-function
- (setq
- new-symbol-name
- (format
- " arrow function %s%s"
- arrow-function
- new-symbol-name)))
- (when is-static-p
- (setq
- new-symbol-name
- (format
- " static%s"
- new-symbol-name)))
- (when function
- (setq
- new-symbol-name
- (format
- " function %s%s"
- function
- new-symbol-name)))
- (when trait
- (setq
- new-symbol-name
- (format
- " trait %s%s"
- trait
- new-symbol-name)))
- (when interface
- (setq
- new-symbol-name
- (format
- " interface %s%s"
- interface
- new-symbol-name)))
- (when class
- (setq
- new-symbol-name
- (format
- " class %s%s"
- class
- new-symbol-name)))
- (when namespace
- (setq
- new-symbol-name
- (format
- " namespace %s%s"
- namespace
- new-symbol-name)))
- new-symbol-name))))
+ (if (gethash
+ name
+ phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+ name
+ (let ((potential-uris (list "")))
+ (when scope
+ (dolist (item scope)
+ (let ((space-type (car item))
+ (space-name (car (cdr item))))
+ (cond
+
+ ((equal space-type 'namespace)
+ (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 " namespace %s%s" space-name (nth
potential-uri-index potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ((equal space-type 'class)
+ (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 " class %s%s" space-name (nth potential-uri-index
potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ((equal space-type 'interface)
+ (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 " interface %s%s" space-name (nth
potential-uri-index potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ((equal space-type 'trait)
+ (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 " trait %s%s" space-name (nth potential-uri-index
potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ((equal space-type 'function)
+ (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 " function %s%s" space-name (nth
potential-uri-index potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ((equal space-type 'anonymous-function)
+ (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 " anonymous %s%s" space-name (nth
potential-uri-index potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ((equal space-type 'arrow-function)
+ ;; TODO Should branch of two here one with and one without the
arrow function scope
+ (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 " anonymous %s%s" space-name (nth
potential-uri-index potential-uris)))
+ (setq potential-uri-index (1+ potential-uri-index)))))
+
+ ;; TODO Below should alter symbol namespaces instead of build
namespace data
+ ((equal space-type 'global)
+ (setq namespace nil)
+ (setq class nil)
+ (setq function nil)
+ (setq arrow-function nil)
+ (setq anonymous-function nil))
+
+ ((equal space-type 'object-operator)
+ (let ((downcased-space-name
+ (downcase space-name)))
+ (cond
+ ((string= downcased-space-name "$this")
+ (setq function nil))
+ (t
+ ;; TODO Do something here
+ ))))
+
+ ((equal space-type 'static-member)
+ (let ((downcased-space-name
+ (downcase space-name)))
+ (cond
+ ((or
+ (string= downcased-space-name "self")
+ (string= downcased-space-name "static"))
+ (setq is-static-p t)
+ (setq function nil))
+ (t
+ ;; TODO Do something here
+ ))))
+
+ ((equal space-type 'static)
+ (setq is-static-p t))
+
+ ))))
+
+ (let ((potential-uri-count (length potential-uris))
+ (potential-uri-index 0)
+ (matching-uri))
+ ;; Iterate potential-uris, select first match or if no match return
the first
+ (while (< potential-uri-index potential-uri-count)
+ (setf
+ (nth potential-uri-index potential-uris)
+ (format "%s id %s" (nth potential-uri-index potential-uris) name))
+ (setq potential-uri-index (1+ potential-uri-index))
+ (let ((potential-uri (nth potential-uri-index potential-uris)))
+ (when (gethash potential-uri phps-mode-parser-sdt-bookkeeping)
+ (setq matching-uri potential-uri))))
+ (if matching-uri
+ matching-uri
+ (nth 0 potential-uris))))))
(defun phps-mode-parser-sdt--parse-top-statement ()
"Parse latest top statement."
@@ -768,11 +774,13 @@
(phps-mode-parser-sdt--get-symbol-uri
symbol-name
symbol-scope)))
- ;; (message
- ;; "assign symbol uri: %S from %S + %S"
- ;; symbol-uri
- ;; symbol-name
- ;; symbol-scope)
+
+ (message
+ "assign symbol uri: %S from %S + %S"
+ symbol-uri
+ symbol-name
+ symbol-scope)
+
(if (gethash symbol-uri phps-mode-parser-sdt-bookkeeping)
(puthash
symbol-uri
@@ -827,14 +835,15 @@
symbol-hit
phps-mode-parser-sdt-bookkeeping)
- ;; (message
- ;; "reference symbol uri: %S from %S + %S, start: %S, end: %S, hit?:
%S"
- ;; symbol-uri
- ;; symbol-name
- ;; symbol-scope
- ;; symbol-start
- ;; symbol-end
- ;; symbol-hit)
+ (message
+ "reference symbol uri: %S from %S + %S, start: %S, end: %S, hit?: %S"
+ symbol-uri
+ symbol-name
+ symbol-scope
+ symbol-start
+ symbol-end
+ symbol-hit)
+
))
(setq
phps-mode-parser-sdt--bookkeeping-symbol-stack
@@ -2147,6 +2156,10 @@
(puthash
185
(lambda(args terminals)
+
+ ;; TODO Should place class scope first in scope
+ ;; unless a namespace exists, in that case it should be placed second in
scope
+
;; Go through stacks and modify symbol name-spaces
;; but only for non-super-global variables
(let ((class-name (nth 1 args)))
@@ -2158,13 +2171,14 @@
(unless (gethash
symbol-name
phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
- (let ((symbol-scope (car (cdr symbol-list))))
+ (let ((symbol-scope (reverse (car (cdr symbol-list)))))
(push
(list 'class class-name)
symbol-scope)
(setcar
(cdr symbol-list)
- symbol-scope))))))
+ (reverse symbol-scope)))))))
+
(when phps-mode-parser-sdt--bookkeeping-symbol-stack
(dolist (
symbol-list
@@ -2173,13 +2187,13 @@
(unless (gethash
symbol-name
phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
- (let ((symbol-scope (car (cdr symbol-list))))
+ (let ((symbol-scope (reverse (car (cdr symbol-list)))))
(push
(list 'class class-name)
symbol-scope)
(setcar
(cdr symbol-list)
- symbol-scope)))))))
+ (reverse symbol-scope))))))))
`(
ast-type
- [elpa] externals/phps-mode ddc1213d83 002/135: Typo in production number, (continued)
- [elpa] externals/phps-mode ddc1213d83 002/135: Typo in production number, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 7a3b86b11d 011/135: Added SDT for all statements, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode b68d94ee08 030/135: More SDT rules, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode eb07936ea8 036/135: added todo notes, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 0ca63fe2b6 041/135: Passing another bookkeeping test via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e74d0fd634 010/135: SDT for inner_statement, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 8dc2235f17 017/135: Added SDT for if_stmt, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d73af7968e 033/135: SDT to 538, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 0e8923c0bd 042/135: Passed super-globals bookkeeping test via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode cc584ff4d6 061/135: Bookkeping of static class properties test passing, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode eefe70b999 072/135: Work on improving symbol URI calculation,
Christian Johansson <=
- [elpa] externals/phps-mode ebe28c3c9d 073/135: Work on improving symbol URI generation for class method variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 61d3e7b1e0 093/135: Passing bookkeeping test but via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d16c8a4e93 099/135: Passing some tests now with integrated bookkeeping and imenu-generation, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 9a45a530d0 100/135: Passing more imenu tests, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 749659769c 115/135: More work on imenu generation via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 42b983bb16 045/135: More work on bookkeeping via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode cba467b26c 050/135: Added TODO items, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e1752a3aa3 064/135: Bookkeeping of variables inside simple anonymous functions, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d464cb1f01 077/135: Fixed bookkeeping of global variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 1a1245f186 082/135: Passing bookkeeping test isset and empty variables, Christian Johansson, 2023/01/29