[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode a80c12ef14 005/212: Passing imenu-generation
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode a80c12ef14 005/212: Passing imenu-generation for file with multiple namespaces |
Date: |
Wed, 26 Jan 2022 01:50:10 -0500 (EST) |
branch: externals/phps-mode
commit a80c12ef14017fc2ee585aeb2f814c7de955e1d1
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing imenu-generation for file with multiple namespaces
---
test/phps-mode-test-lex-analyzer.el | 5 +
test/phps-mode-test-parser.el | 221 +++++++++++++++++++++++++++++-------
2 files changed, 186 insertions(+), 40 deletions(-)
diff --git a/test/phps-mode-test-lex-analyzer.el
b/test/phps-mode-test-lex-analyzer.el
index c062a2ecb4..172eec894d 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -1244,6 +1244,11 @@
"Imenu with double quoted string with variable inside it and concatenated
string"
(should (equal (phps-mode-lex-analyzer--get-imenu) '(("MyNamespace"
("aFunction" . 41) ("MyClass" ("__construct" . 160) ("myFunction1" . 261)
("myFunction2" . 433) ("myFunction3" . 513) ("myFunction4" . 583)))))))
+ (phps-mode-test--with-buffer
+ "<?php\n\nnamespace MyNamespaceA\n{\n function aFunctionA() {\n
/**\n * With some contents\n */\n }\n class MyClass\n
{\n\n /**\n *\n */\n public function
__construct()\n {\n if ($test) {\n }\n
}\n\n /**\n *\n */\n public function
myFunction1()\n {\n $this->addMessage(\"My random {$message}
here\" . ($random > 1 ? \"A\" : \"\") . \" was he [...]
+ "Imenu with double quoted string with variable inside it and concatenated
string in two namespaces"
+ (should (equal (phps-mode-lex-analyzer--get-imenu) '(("MyNamespaceA"
("aFunctionA" . 46) ("MyClass" ("__construct" . 205) ("myFunction1" . 338)
("myFunction2" . 542) ("myFunction3" . 646) ("myFunction4" . 740)))
("aFunctionB" . 807) ("MyClass" ("__construct" . 925) ("myFunction1" . 1058)
("myFunction2" . 1262) ("myFunction3" . 1366) ("myFunction4" . 1460))))))
+
)
(defun phps-mode-test-lex-analyzer--get-moved-imenu ()
diff --git a/test/phps-mode-test-parser.el b/test/phps-mode-test-parser.el
index 62e64bf11b..4b4bbd83c8 100644
--- a/test/phps-mode-test-parser.el
+++ b/test/phps-mode-test-parser.el
@@ -314,79 +314,107 @@
(ast-current-namespace)
(ast-current-namespace-children))
- ;; function_declaration_statement -> (function returns_ref T_STRING
backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags "{"
inner_statement_list "}" backup_fn_flags)
+ ;; top_statement_list -> (top_statement_list top_statement)
(puthash
- 174
+ 79
+ (lambda(args terminals)
+ ;; (message "top_statement_list: %S" args)
+ (let ((ast-object))
+ (if (car args)
+ (setq ast-object (append (car args) (cdr args)))
+ (setq ast-object (cdr args)))
+ ;; (message "ast-object: %S" ast-object)
+ ast-object))
+ phps-mode-parser--table-translations)
+
+ ;; top_statement -> (T_NAMESPACE namespace_declaration_name ";")
+ (puthash
+ 106
(lambda(args terminals)
(let ((ast-object
(list
'type
- 'function
+ 'namespace
'name
- (nth 2 args)
+ (nth 1 args)
'index
- (car (cdr (nth 2 terminals)))
+ (car (cdr (nth 1 terminals)))
'start
- (car (cdr (nth 9 terminals)))
+ (car (cdr (nth 2 terminals)))
'end
- (car (cdr (nth 11 terminals))))))
- ;; (message "Function: %S" ast-object)
+ 'max)))
+ ;; (message "Namespace %S" ast-object)
;; (message "args: %S" args)
;; (message "terminals: %S" terminals)
- (if ast-current-namespace
- (push
- ast-object
- ast-current-namespace-children)
- (push
- ast-object
- ast))
+ (setq
+ ast-current-namespace
+ ast-object)
ast-object))
phps-mode-parser--table-translations)
- ;; attributed_class_statement -> (method_modifiers function returns_ref
identifier backup_doc_comment "(" parameter_list ")" return_type
backup_fn_flags method_body backup_fn_flags)
+ ;; top_statement -> (T_NAMESPACE namespace_declaration_name "{"
top_statement_list "}")
(puthash
- 280
+ 107
(lambda(args terminals)
(let ((ast-object
(list
'type
- 'method
+ 'namespace
'name
- (nth 3 args)
+ (nth 1 args)
'index
- (car (cdr (nth 3 terminals)))
+ (car (cdr (nth 1 terminals)))
'start
- (car (cdr (car (nth 10 terminals))))
+ (car (cdr (nth 2 terminals)))
'end
- (cdr (cdr (car (cdr (cdr (nth 10 terminals)))))))))
- ;; (message "Method: %S" ast-object)
+ (car (cdr (nth 4 terminals)))
+ 'children
+ (nth 3 args))))
+ ;; (message "Namespace %S" ast-object)
;; (message "args: %S" args)
;; (message "terminals: %S" terminals)
+ ;; (message "ast-object: %S" ast-object)
+ (push
+ ast-object
+ ast)
ast-object))
phps-mode-parser--table-translations)
- ;; top_statement -> (T_NAMESPACE namespace_declaration_name ";")
+ ;; top_statement -> (T_NAMESPACE "{" top_statement_list "}")
(puthash
- 106
+ 108
+ (lambda(args terminals)
+ (message "T_NAMESPACE: %S" args)
+ (when (nth 2 args)
+ (setq
+ ast
+ (append ast (nth 2 args))))
+ (nth 2 args))
+ phps-mode-parser--table-translations)
+
+ ;; 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)
(let ((ast-object
(list
'type
- 'namespace
+ 'function
'name
- (nth 1 args)
+ (nth 2 args)
'index
- (car (cdr (nth 1 terminals)))
- 'start
(car (cdr (nth 2 terminals)))
+ 'start
+ (car (cdr (nth 9 terminals)))
'end
- 'max)))
- ;; (message "Namespace %S" ast-object)
+ (car (cdr (nth 11 terminals))))))
+ ;; (message "Function: %S" ast-object)
;; (message "args: %S" args)
;; (message "terminals: %S" terminals)
- (setq
- ast-current-namespace
- ast-object)
+ (when ast-current-namespace
+ (push
+ ast-object
+ ast-current-namespace-children))
ast-object))
phps-mode-parser--table-translations)
@@ -411,13 +439,10 @@
;; (message "Class %S" ast-object)
;; (message "args: %S" args)
;; (message "terminals: %S" terminals)
- (if ast-current-namespace
- (push
- ast-object
- ast-current-namespace-children)
+ (when ast-current-namespace
(push
ast-object
- ast))
+ ast-current-namespace-children))
ast-object))
phps-mode-parser--table-translations)
@@ -434,6 +459,28 @@
ast-object))
phps-mode-parser--table-translations)
+ ;; attributed_class_statement -> (method_modifiers function returns_ref
identifier backup_doc_comment "(" parameter_list ")" return_type
backup_fn_flags method_body backup_fn_flags)
+ (puthash
+ 280
+ (lambda(args terminals)
+ (let ((ast-object
+ (list
+ 'type
+ 'method
+ 'name
+ (nth 3 args)
+ 'index
+ (car (cdr (nth 3 terminals)))
+ 'start
+ (car (cdr (car (nth 10 terminals))))
+ 'end
+ (cdr (cdr (car (cdr (cdr (nth 10 terminals)))))))))
+ ;; (message "Method: %S" ast-object)
+ ;; (message "args: %S" args)
+ ;; (message "terminals: %S" terminals)
+ ast-object))
+ phps-mode-parser--table-translations)
+
(phps-mode-test-parser--buffer-contents
"<?php\n\nnamespace MyNamespace;\n\nfunction aFunction() {\n /**\n
* With some contents\n */\n}\n\nclass MyClass\n{\n\n /**\n *\n
*/\n public function __construct()\n {\n if ($test) {\n }\n
}\n\n /**\n *\n */\n public function myFunction1()\n {\n
$this->addMessage(\"My random {$message} here\" . ($random > 1 ? \"A\" :
\"\") . \" was here.\");\n }\n \n /**\n *\n */\n public
function myFunction2() [...]
"Imenu with double quoted string with variable inside it and concatenated
string"
@@ -511,7 +558,101 @@
(equal
imenu-index
'(("MyNamespace" ("aFunction" . 41) ("MyClass" ("__construct" .
160) ("myFunction1" . 261) ("myFunction2" . 433) ("myFunction3" . 513)
("myFunction4" . 583))))))
- )))))
+ ))))
+
+ (setq
+ ast-current-namespace
+ nil)
+ (setq
+ ast-current-namespace-children
+ nil)
+ (setq
+ ast
+ nil)
+
+ (phps-mode-test-parser--buffer-contents
+ "<?php\n\nnamespace MyNamespaceA\n{\n function aFunctionA() {\n
/**\n * With some contents\n */\n }\n class MyClass\n
{\n\n /**\n *\n */\n public function
__construct()\n {\n if ($test) {\n }\n
}\n\n /**\n *\n */\n public function
myFunction1()\n {\n $this->addMessage(\"My random {$message}
here\" . ($random > 1 ? \"A\" : \"\") . \" was [...]
+ "Imenu with double quoted string with variable inside it and concatenated
string in two namespaces"
+ (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))
+ (imenu-index))
+ ;; (message "translation: %S" translation)
+
+ (when ast-current-namespace
+ (plist-put
+ ast-current-namespace
+ 'children
+ (reverse ast-current-namespace-children))
+ (push
+ ast-current-namespace
+ ast))
+
+ (message "\nAST:\n%S\n" ast)
+
+ (let ((imenu-index))
+ (dolist (item ast)
+ (let ((children (plist-get item 'children))
+ (item-type (plist-get item 'type))
+ (parent))
+ (if (and
+ (or
+ (equal item-type 'namespace)
+ (equal item-type 'class))
+ children)
+ (progn
+ (dolist (child children)
+ (let ((grandchildren (plist-get child 'children))
+ (child-type (plist-get child 'type))
+ (subparent))
+ (if (and
+ (equal child-type 'class)
+ grandchildren)
+ (progn
+ (dolist (grandchild grandchildren)
+ (push
+ `(,(plist-get grandchild 'name) .
,(plist-get grandchild 'index))
+ subparent))
+ (push
+ (append
+ (list (plist-get child 'name))
+ (reverse subparent))
+ parent))
+ (push
+ `(,(plist-get child 'name) . ,(plist-get child
'index))
+ parent)))
+ )
+ (push
+ (append
+ (list (plist-get item 'name))
+ (reverse parent))
+ imenu-index))
+ (push
+ `(,(plist-get item 'name) . ,(plist-get item 'index))
+ imenu-index))))
+ (setq
+ imenu-index
+ (reverse imenu-index))
+
+ (message "imenu-index:\n%S\n" imenu-index)
+
+ (should
+ (equal
+ imenu-index
+ '(("MyNamespaceA" ("aFunctionA" . 46) ("MyClass" ("__construct" .
205) ("myFunction1" . 338) ("myFunction2" . 542) ("myFunction3" . 646)
("myFunction4" . 740))) ("aFunctionB" . 807) ("MyClass" ("__construct" . 925)
("myFunction1" . 1058) ("myFunction2" . 1262) ("myFunction3" . 1366)
("myFunction4" . 1460)))))
+ ))))
+
+ )
(message "\n-- Ran tests for parser translation. --"))
- [elpa] externals/phps-mode f79b6118a4 087/212: Optimization of string indentation function, (continued)
- [elpa] externals/phps-mode f79b6118a4 087/212: Optimization of string indentation function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b94ee63396 089/212: More work on indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d8503c70bb 106/212: Passing indent tests for switch case, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4f20de353e 109/212: Passed indent tests for PSR-2, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6655248e86 105/212: Passing indent test for regular switch statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4e5be4f8f8 112/212: More indentation work for mixed PHP/HTML content, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode ff62626f48 110/212: Passing indent test for square bracket array, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 50d006852c 129/212: Fixed issue with indent being dependent on position of point on current line, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3de8eff9f1 114/212: More wrestling with indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d3b5a85b70 001/212: Using property list as basis for AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a80c12ef14 005/212: Passing imenu-generation for file with multiple namespaces,
Christian Johansson <=
- [elpa] externals/phps-mode 0071b40aae 007/212: Syntax coloring is now in separate file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1cc4aed616 016/212: Passing first bookkeeping test via generation via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b3b27951bd 015/212: More work on bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 395a4ed045 036/212: Started on bookkeeping via parser SDT for properties, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 69341c9709 039/212: More working on bookkeeping of class properties via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cefab36fa8 054/212: More work on bookkeeping arrow function variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9cbe630b3 068/212: Passing bookkeeping of variables inside echo statements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0919855a31 073/212: Added SDT for concat operation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5df554fc47 070/212: Bookkeeping via AST properly handles $this reference in only non-static methods, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2432928a86 096/212: Indentation passing more tests for alternative control structures, Christian Johansson, 2022/01/26