[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 1cc4aed616 016/212: Passing first bookkeeping
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 1cc4aed616 016/212: Passing first bookkeeping test via generation via parser SDT |
Date: |
Wed, 26 Jan 2022 01:50:13 -0500 (EST) |
branch: externals/phps-mode
commit 1cc4aed61619a2deb7c94210ecd052f8398037d9
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing first bookkeeping test via generation via parser SDT
---
phps-mode-ast.el | 115 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 102 insertions(+), 13 deletions(-)
diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index 0af367a577..45cf992c55 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -127,6 +127,33 @@
ast-object))
phps-mode-parser--table-translations)
+;; statement -> ("{" inner_statement_list "}")
+(puthash
+ 140
+ (lambda(args _terminals)
+ (nth 1 args))
+ phps-mode-parser--table-translations)
+
+;; statement -> (T_ECHO echo_expr_list ";")
+(puthash
+ 152
+ (lambda(args _terminals)
+ (let ((ast-object
+ (list
+ 'type
+ 'echo
+ 'body
+ (nth 1 args))))
+ ast-object))
+ phps-mode-parser--table-translations)
+
+;; statement -> (expr ";")
+(puthash
+ 154
+ (lambda(args _terminals)
+ (car 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
@@ -173,7 +200,6 @@
ast-object))
phps-mode-parser--table-translations)
-
;; interface_declaration_statement -> (T_INTERFACE T_STRING
interface_extends_list backup_doc_comment "{" class_statement_list "}")
(puthash
186
@@ -201,9 +227,17 @@
;; if_stmt_without_else -> (T_IF "(" expr ")" statement)
(puthash
223
- (lambda(args terminals)
- (message "if_stmt_without_else: %S" args terminals)
- args)
+ (lambda(args _terminals)
+ ;; (message "if_stmt_without_else: %S" args _terminals)
+ (let ((ast-object
+ (list
+ 'type
+ 'if
+ 'condition
+ (nth 2 args)
+ 'body
+ (nth 4 args))))
+ ast-object))
phps-mode-parser--table-translations)
;; class_statement_list -> (class_statement_list class_statement)
@@ -245,18 +279,14 @@
;; expr -> (variable "=" expr)
(puthash
337
- (lambda(args terminals)
- ;; (message "expr: %S %S" args terminals)
+ (lambda(args _terminals)
+ ;; (message "expr: %S %S" args _terminals)
(let ((ast-object
(list
'type
'assign-variable
- 'name
+ 'key
(nth 0 args)
- 'start
- (car (cdr (nth 0 terminals)))
- 'end
- (cdr (cdr (nth 0 terminals)))
'value
(nth 2 args))))
;; (message "Method: %S" ast-object)
@@ -278,6 +308,7 @@
args
'start
(car (cdr terminals))
+ 'end
(cdr (cdr terminals)))))
ast-object))
phps-mode-parser--table-translations)
@@ -291,7 +322,8 @@
(let ((translation (phps-mode-parser-translate))
(namespace)
(namespace-children)
- (ast))
+ (ast)
+ (bookkeeping (make-hash-table :test 'equal)))
(message "\nTranslation:\n%S\n\n" translation)
@@ -343,7 +375,7 @@
ast
(reverse ast))
- ;; (message "AST:\n%S\n\n" ast)
+ (message "AST:\n%S\n\n" ast)
(let ((imenu-index))
(dolist (item ast)
@@ -397,6 +429,63 @@
(reverse imenu-index)))
;; (message "imenu:\n%S\n\n" phps-mode-ast--imenu)
+
+
+ ;; TODO Build bookkeeping here
+ (let ((bookkeeping-stack ast))
+ (while bookkeeping-stack
+ (let ((item (pop bookkeeping-stack)))
+ (let ((type (plist-get item 'type)))
+ (cond
+
+ ((equal type 'variable)
+ (let ((id (format " id %s" (plist-get item 'name)))
+ (object (list
+ (plist-get item 'start)
+ (plist-get item 'end)))
+ (defined-p 0))
+ (when (gethash id bookkeeping)
+ (setq
+ defined-p
+ 1))
+ (puthash
+ object
+ defined-p
+ bookkeeping)))
+
+ ((equal type 'if)
+ (let ((condition (plist-get item 'condition)))
+ (when (equal (plist-get condition 'type) 'variable)
+ (push
+ condition
+ bookkeeping-stack))))
+
+ ((equal type 'assign-variable)
+ (let ((id (format " id %s" (plist-get (plist-get item 'key)
'name)))
+ (object (list
+ (plist-get (plist-get item 'key) 'start)
+ (plist-get (plist-get item 'key) 'end)))
+ (defined 1))
+ (message "id: %S from %S" id item)
+ (when-let ((predefined (gethash id bookkeeping)))
+ (setq
+ defined
+ (1+ predefined)))
+ (puthash
+ id
+ defined
+ bookkeeping)
+ (puthash
+ object
+ defined
+ bookkeeping)))
+
+ )))))
+ (setq
+ phps-mode-ast--bookkeeping
+ bookkeeping)
+
+ (message "\nBookkeeping\n:%S\n" bookkeeping)
(setq
phps-mode-ast--tree
- [elpa] externals/phps-mode d8503c70bb 106/212: Passing indent tests for switch case, (continued)
- [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, 2022/01/26
- [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 <=
- [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
- [elpa] externals/phps-mode cef879268b 103/212: Added two new tests for failing indentation for multi-line concatenated strings, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 40ce934c11 116/212: Indent support for string-doc in assignment, Christian Johansson, 2022/01/26