emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 5994746 4/7: Started on generating imenu-inde


From: Christian Johansson
Subject: [elpa] externals/phps-mode 5994746 4/7: Started on generating imenu-index via parser translation
Date: Sun, 7 Nov 2021 14:21:37 -0500 (EST)

branch: externals/phps-mode
commit 5994746468629e90cd511bd990bb7e0ac22ee807
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Started on generating imenu-index via parser translation
---
 phps-mode-parser.el           | 31 +++++++++++++++++------
 test/phps-mode-test-parser.el | 58 +++++++++++++++++++++++++++----------------
 2 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/phps-mode-parser.el b/phps-mode-parser.el
index 4725e8e..5e4dc21 100644
--- a/phps-mode-parser.el
+++ b/phps-mode-parser.el
@@ -577,7 +577,8 @@
                         (push production-number output)
 
                         (when perform-sdt
-                          (let ((popped-items-meta-contents))
+                          (let ((popped-items-meta-contents)
+                                (popped-items-terminals))
                             (setq
                              popped-items-contents
                              (reverse popped-items-contents))
@@ -587,10 +588,14 @@
                                    (listp popped-item)
                                    (cdr popped-item))
                                   ;; If item is a terminal, use it's literal 
value
-                                  (push
-                                   (phps-mode-parser-lex-analyzer--get-function
-                                    popped-item)
-                                   popped-items-meta-contents)
+                                  (progn
+                                    (push
+                                      
(phps-mode-parser-lex-analyzer--get-function
+                                       popped-item)
+                                       popped-items-meta-contents)
+                                      (push
+                                       popped-item
+                                       popped-items-terminals))
 
                                 ;; If item is a non-terminal
                                 (let ((temp-hash-key
@@ -612,19 +617,28 @@
                                             (push
                                              symbol-translation
                                              popped-items-meta-contents)
+                                            (push
+                                             nil
+                                             popped-items-terminals)
                                             (puthash
                                              temp-hash-key
                                              symbol-translations
                                              translation-symbol-table)))
                                       (push
                                        nil
-                                       popped-items-meta-contents)))))
+                                       popped-items-meta-contents)
+                                      (push
+                                       nil
+                                       popped-items-terminals)))))
 
                               ;; If we just have one argument, pass it as a 
instead of a list
                               (when (= (length popped-items-meta-contents) 1)
                                 (setq
                                  popped-items-meta-contents
-                                 (car popped-items-meta-contents)))
+                                 (car popped-items-meta-contents))
+                                (setq
+                                 popped-items-terminals
+                                 (car popped-items-terminals)))
 
                               ;; Perform translation at reduction if specified
                               (if
@@ -634,7 +648,8 @@
                                          (funcall
                                           
(phps-mode-parser--get-grammar-translation-by-number
                                            production-number)
-                                          popped-items-meta-contents)))
+                                          popped-items-meta-contents
+                                          popped-items-terminals)))
                                     (let ((temp-hash-key
                                            (format
                                             "%S"
diff --git a/test/phps-mode-test-parser.el b/test/phps-mode-test-parser.el
index e3e8045..87ec3f1 100644
--- a/test/phps-mode-test-parser.el
+++ b/test/phps-mode-test-parser.el
@@ -311,28 +311,42 @@
   (message "-- Running tests for parser translation... --\n")
 
   ;; TODO Generate bookkeeping and imenu index here
-
-  ;; (phps-mode-test-parser--buffer-contents
-  ;;  "<?php\nfunction myFunctionA() {}\nfunction myFunctionB() {}\n$var = 
function () {\n    echo 'here';\n};"
-  ;;  "Imenu function-oriented file with anonymous function"
-  ;;  (lambda()
-  ;;    (let ((parse (phps-mode-parser-parse)))
-  ;;      (message "Left-to-right with left-most derivation:\n%S\n" parse)
-  ;;      (dolist (production-number (reverse parse))
-  ;;        (let ((production
-  ;;               (phps-mode-parser--get-grammar-production-by-number
-  ;;                production-number)))
-  ;;          (message
-  ;;           "%d: %S -> %S"
-  ;;           production-number
-  ;;           (car (car production))
-  ;;           (car (cdr production))))))
-  ;;    (let ((translation (phps-mode-parser-translate)))
-  ;;      (should
-  ;;       (equal
-  ;;        (phps-mode-lex-analyzer--get-imenu)
-  ;;        '(("myFunctionA" . 16) ("myFunctionB" . 42))))
-  ;;    )))
+  (let ((imenu-index))
+
+    ;; function_declaration_statement -> (function returns_ref T_STRING 
backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags "{" 
inner_statement_list "}" backup_fn_flags)
+    (puthash
+     174
+     (lambda(args terminals)
+       (push
+        `(,(nth 2 args) . ,(car (cdr (nth 2 terminals))))
+        imenu-index))
+     phps-mode-parser--table-translations)
+
+    (phps-mode-test-parser--buffer-contents
+     "<?php\nfunction myFunctionA() {}\nfunction myFunctionB() {}\n$var = 
function () {\n    echo 'here';\n};"
+     "Imenu function-oriented file with anonymous function"
+     (lambda()
+       (let ((parse (phps-mode-parser-parse)))
+         (message "Left-to-right with left-most derivation:\n%S\n" parse)
+         (dolist (production-number (reverse parse))
+           (let ((production
+                  (phps-mode-parser--get-grammar-production-by-number
+                   production-number)))
+             (message
+              "%d: %S -> %S"
+              production-number
+              (car (car production))
+              (car (cdr production))))))
+       (phps-mode-parser-translate)
+       (setq
+        imenu-index
+        (nreverse imenu-index))
+       (should
+        (equal
+         imenu-index
+         '(("myFunctionA" . 16) ("myFunctionB" . 42))))
+       ;; TODO Test bookkeeping here
+       )))
 
   (message "\n-- Ran tests for parser translation. --"))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]