[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 8aae220c57 098/135: Started on integrating im
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 8aae220c57 098/135: Started on integrating imenu generation in SDT bookkeeping |
Date: |
Sun, 29 Jan 2023 03:11:08 -0500 (EST) |
branch: externals/phps-mode
commit 8aae220c5760c2202e387a16ee5adb6a69d159fb
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Started on integrating imenu generation in SDT bookkeeping
---
phps-mode-ast.el | 12 +++
phps-mode-parser-sdt.el | 189 +++++++++++++++++++++++++++++++--------------
test/phps-mode-test-ast.el | 7 +-
3 files changed, 149 insertions(+), 59 deletions(-)
diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index 46d7f9a130..7fd9d7a1eb 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -33,6 +33,18 @@
(setq
phps-mode-parser-sdt-bookkeeping
(make-hash-table :test 'equal))
+ (setq
+ phps-mode-parser-sdt-symbol-table-index
+ 0)
+ (setq
+ phps-mode-parser-sdt-symbol-imenu
+ nil)
+ (setq
+ phps-mode-parser-sdt-symbol-table
+ (make-hash-table :test 'equal))
+ (setq
+ phps-mode-parser-sdt-symbol-table-by-uri
+ (make-hash-table :test 'equal))
(setq
phps-mode-parser-sdt--bookkeeping-namespace
nil)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 9debeadd39..590e7a3821 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -589,7 +589,27 @@
(defvar-local
phps-mode-parser-sdt-bookkeeping
(make-hash-table :test 'equal)
- "Bookkeeping")
+ "Bookkeeping of symbol references.")
+
+(defvar-local
+ phps-mode-parser-sdt-symbol-table-index
+ 0
+ "Symbol table index.")
+
+(defvar-local
+ phps-mode-parser-sdt-symbol-table
+ (make-hash-table :test 'equal)
+ "Symbol table of parse, symbol ID => (list URI start end)")
+
+(defvar-local
+ phps-mode-parser-sdt-symbol-table-by-uri
+ (make-hash-table :test 'equal)
+ "Symbol table of parse, symbol URI => list of symbol IDs.")
+
+(defvar-local
+ phps-mode-parser-sdt-symbol-imenu
+ nil
+ "Imenu for symbols of parse.")
(defvar-local
phps-mode-parser-sdt--bookkeeping-namespace
@@ -673,7 +693,7 @@
(while (< potential-uri-index potential-uri-count)
(setf
(nth potential-uri-index potential-uris)
- (format " static%s" (nth potential-uri-index
potential-uris)))
+ (format "static%s" (nth potential-uri-index
potential-uris)))
(setq potential-uri-index (1+
potential-uri-index)))))
(setq next-scope-is-self-static-member-operator
t)))))))
@@ -690,7 +710,7 @@
(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)))
+ (format "namespace %s%s" space-name (nth
potential-uri-index potential-uris)))
(setq potential-uri-index (1+ potential-uri-index)))))
((and
@@ -701,7 +721,7 @@
(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)))
+ (format "class %s%s" space-name (nth
potential-uri-index potential-uris)))
(setq potential-uri-index (1+ potential-uri-index)))))
((and
@@ -712,7 +732,7 @@
(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)))
+ (format "interface %s%s" space-name (nth
potential-uri-index potential-uris)))
(setq potential-uri-index (1+ potential-uri-index)))))
((and
@@ -723,7 +743,7 @@
(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)))
+ (format "trait %s%s" space-name (nth
potential-uri-index potential-uris)))
(setq potential-uri-index (1+ potential-uri-index)))))
((and
@@ -737,7 +757,7 @@
(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)))
+ (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)
@@ -746,7 +766,7 @@
(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)))
+ (format "anonymous %s%s" space-name (nth
potential-uri-index potential-uris)))
(setq potential-uri-index (1+ potential-uri-index)))))
((equal space-type 'static)
@@ -755,7 +775,7 @@
(while (< potential-uri-index potential-uri-count)
(setf
(nth potential-uri-index potential-uris)
- (format " static%s" (nth potential-uri-index
potential-uris)))
+ (format "static%s" (nth potential-uri-index
potential-uris)))
(setq potential-uri-index (1+ potential-uri-index)))))
((equal space-type 'arrow-function)
@@ -766,7 +786,7 @@
(new-potential-uris))
(while (< potential-uri-index potential-uri-count)
(push
- (format " arrow %s%s" space-name (nth
potential-uri-index potential-uris))
+ (format "arrow %s%s" space-name (nth
potential-uri-index potential-uris))
new-potential-uris)
(setq potential-uri-index (1+ potential-uri-index)))
(setq potential-uris (append new-potential-uris
potential-uris))
@@ -780,15 +800,30 @@
(let ((potential-uri-count (length potential-uris))
(potential-uri-index 0)
(matching-uri))
- ;; (message "potential-uris: %S" potential-uris)
;; 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))
- (let ((potential-uri (nth potential-uri-index potential-uris)))
- (when (gethash potential-uri phps-mode-parser-sdt-bookkeeping)
+ (while (and
+ (< potential-uri-index potential-uri-count)
+ (not matching-uri))
+ (let ((old-uri
+ (nth potential-uri-index potential-uris))
+ (potential-uri))
+ (if (string= old-uri "")
+ (setq
+ potential-uri
+ (format
+ "id %s"
+ name))
+ (setq
+ potential-uri
+ (format
+ "%s id %s"
+ old-uri
+ name)))
+ (setf
+ (nth potential-uri-index potential-uris)
+ potential-uri)
+ (when (gethash potential-uri
phps-mode-parser-sdt-symbol-table-by-uri)
(setq matching-uri potential-uri)))
(setq potential-uri-index (1+ potential-uri-index)))
(if matching-uri
@@ -815,28 +850,55 @@
symbol-name
symbol-scope)))
- ;; (message
- ;; "assign symbol uri: %S from %S + %S, start: %S, end: %S"
- ;; symbol-uri
- ;; symbol-name
- ;; symbol-scope
- ;; symbol-start
- ;; symbol-end)
-
- (if (gethash symbol-uri phps-mode-parser-sdt-bookkeeping)
- (puthash
- symbol-uri
- (append
- (gethash symbol-uri phps-mode-parser-sdt-bookkeeping)
- (list (list symbol-start symbol-end)))
- phps-mode-parser-sdt-bookkeeping)
+ (message
+ "assign symbol uri: %S from %S + %S, start: %S, end: %S"
+ symbol-uri
+ symbol-name
+ symbol-scope
+ symbol-start
+ symbol-end)
+
+ (setq
+ phps-mode-parser-sdt-symbol-table-index
+ (1+ phps-mode-parser-sdt-symbol-table-index))
+
+ ;; Register new symbol in symbol-table
+ ;; and place a reference to it in the symbol URI hash-map
+ (if (gethash symbol-uri phps-mode-parser-sdt-symbol-table-by-uri)
+ (progn
+ (push
+ (list symbol-uri symbol-start)
+ phps-mode-parser-sdt-symbol-imenu)
+
+ (puthash
+ phps-mode-parser-sdt-symbol-table-index
+ (list
+ symbol-uri
+ symbol-start
+ symbol-end)
+ phps-mode-parser-sdt-symbol-table)
+ (puthash
+ symbol-uri
+ (append
+ (gethash symbol-uri phps-mode-parser-sdt-symbol-table-by-uri)
+ (list phps-mode-parser-sdt-symbol-table-index))
+ phps-mode-parser-sdt-symbol-table-by-uri))
+
+ (push
+ `(,symbol-uri . ,symbol-start)
+ phps-mode-parser-sdt-symbol-imenu)
+
(puthash
- symbol-uri
+ phps-mode-parser-sdt-symbol-table-index
(list
- (list
- symbol-start
- symbol-end))
- phps-mode-parser-sdt-bookkeeping))))
+ symbol-uri
+ symbol-start
+ symbol-end)
+ phps-mode-parser-sdt-symbol-table)
+ (puthash
+ symbol-uri
+ (list phps-mode-parser-sdt-symbol-table-index)
+ phps-mode-parser-sdt-symbol-table-by-uri))))
(setq
phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack
nil))
@@ -861,21 +923,36 @@
((gethash
symbol-name
phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
- (setq symbol-hit 1))
+ (setq symbol-hit -1))
;; Declared variable
((gethash
symbol-uri
- phps-mode-parser-sdt-bookkeeping)
- (let ((matching-symbols
- (gethash
- symbol-uri
- phps-mode-parser-sdt-bookkeeping)))
- (dolist (matching-symbol matching-symbols)
- (let ((matching-symbol-start (car matching-symbol))
- (matching-symbol-end (car (cdr matching-symbol))))
- (when (<= matching-symbol-start symbol-start)
- (setq symbol-hit 1)))))))
+ phps-mode-parser-sdt-symbol-table-by-uri)
+ (let* ((matching-symbol-ids
+ (gethash
+ symbol-uri
+ phps-mode-parser-sdt-symbol-table-by-uri))
+ (matching-symbol-index 0)
+ (matching-symbol-count (length matching-symbol-ids))
+ (matching-hit)
+ (matching-symbol-id
+ (nth matching-symbol-index matching-symbol-ids))
+ (matching-symbol
+ (gethash
+ matching-symbol-id
+ phps-mode-parser-sdt-symbol-table))
+ (matching-symbol-start
+ (nth 1 matching-symbol))
+ (matching-symbol-end
+ (nth 2 matching-symbol)))
+ (while (and
+ (not matching-hit)
+ (< matching-symbol-index matching-symbol-count))
+ (when (<= matching-symbol-start symbol-start)
+ (setq matching-hit t)
+ (setq symbol-hit matching-symbol-id))
+ (setq matching-symbol-index (1+ matching-symbol-index))))))
(puthash
(list
@@ -884,14 +961,14 @@
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
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 98a7fa7ccf..c3c847b008 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -39,6 +39,10 @@
(phps-mode-ast--generate)
(phps-mode-ast-bookkeeping--generate)
+ (message "imenu: \n%S\n" phps-mode-parser-sdt-symbol-imenu)
+ (message "symbol-table: \n%S\n" phps-mode-parser-sdt-symbol-table)
+ (message "phps-mode-parser-sdt-symbol-table-by-uri: \n%S\n"
phps-mode-parser-sdt-symbol-table-by-uri)
+
(message
"expected-bookkeeping:\n%S\n"
bookkeeping)
@@ -47,9 +51,6 @@
(phps-mode-test--hash-to-list
phps-mode-ast-bookkeeping--index
t))
- (message
- "object-index:\n%S\n"
- phps-mode-ast-bookkeeping--object-index)
(should
(equal
- [elpa] externals/phps-mode 7b9f8011f1 056/135: More testing, (continued)
- [elpa] externals/phps-mode 7b9f8011f1 056/135: More testing, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e2f2c86e18 059/135: Improved class properties bookkeeping test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode eac10d63e6 063/135: Started on bookkeeping of variables inside anonymous functions, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e924ac83b6 065/135: Improved bookkeeping test for anonymous function, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e614a20ada 066/135: Added bookkeeping for referenced foreach variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d33625bb1a 067/135: Bookkeeping for array assignment passing test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode a646676781 084/135: Passing more bookkeeping tests, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 7609f09f04 090/135: More bookkeeping final touches, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 6c6906317a 095/135: Added bookkeeping test for trait class symbols, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode ada5e79291 097/135: Passing bookkeeping test for class properties in class constructor, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 8aae220c57 098/135: Started on integrating imenu generation in SDT bookkeeping,
Christian Johansson <=
- [elpa] externals/phps-mode 95f563fc70 102/135: Passing bookkeeping tests with integrated imenu generation, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode ae516f9e19 105/135: Using separate imenu items for redeclared symbols, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode b21c9f3f3a 107/135: Imenu generation via SDT all tests now passing, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 3332b2bfa9 109/135: Fixes syntax coloring of super-globals, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode bddf800099 111/135: Added failing test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d98f6d78d8 114/135: Saving symbol-table after parse, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 1594c15e9e 117/135: More work on imenu generation, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 776c818ff9 121/135: Passing some more imenu tests, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode c6e4844753 122/135: Some byte-compilation fixes, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 96eeff74f8 130/135: Added more todo items for bookkeeping and imenu, Christian Johansson, 2023/01/29