branch: externals/phps-mode commit e74d0fd634a722cebc26430c498f59a3d137e6cd Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
SDT for inner_statement --- phps-mode-ast-bookkeeping.el | 39 ++++++++++++------- phps-mode-parser-sdt.el | 90 ++++++++++++++++++++++++++++++++++++++++++-- test/phps-mode-test-ast.el | 18 +++++---- 3 files changed, 123 insertions(+), 24 deletions(-) diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el index c4675fc559..eb92db8cf9 100644 --- a/phps-mode-ast-bookkeeping.el +++ b/phps-mode-ast-bookkeeping.el @@ -254,7 +254,8 @@ (bookkeeping-objects) (inline-function-count 0) (arrow-function-count 0) - (defined-count 0)) + (defined-count 0) + (global-namespace)) (while bookkeeping-stack (let ((item-raw (pop bookkeeping-stack)) (item) @@ -271,6 +272,17 @@ item item-raw)) + ;; Set global namespace (if any) + (when global-namespace + (let ((had-scope-p scope)) + (when had-scopep + (setq scope (reverse scope))) + (push + (list 'type 'namespace 'name global-namespace) + scope) + (when had-scopep + (setq scope (reverse scope))))) + (let ((type (plist-get item 'ast-type))) (cond @@ -472,9 +484,10 @@ (let ((name (plist-get item 'name)) (sub-scope scope)) (push `(type namespace name ,name) sub-scope) - (when-let ((children (reverse (plist-get item 'children)))) - (dolist (child children) - (push `(,sub-scope ,child) bookkeeping-stack))))) + (if-let ((children (reverse (plist-get item 'children)))) + (dolist (child children) + (push `(,sub-scope ,child) bookkeeping-stack)) + (setq global-namespace name)))) ((equal type 'class) (let ((name (plist-get item 'name)) @@ -931,7 +944,7 @@ (phps-mode-ast-bookkeeping--generate-symbol-scope-string sub-scope property-name)) - (bookkeeping-object + (bookkeeping-object2 (list object-start object-end)) @@ -956,11 +969,11 @@ t))) (if predefined (puthash - bookkeeping-object + bookkeeping-object2 1 bookkeeping) (puthash - bookkeeping-object + bookkeeping-object2 0 bookkeeping))))) @@ -1047,7 +1060,7 @@ (phps-mode-ast-bookkeeping--generate-symbol-scope-string sub-scope property-name)) - (bookkeeping-object + (bookkeeping-object2 (list object-start object-end)) @@ -1072,11 +1085,11 @@ t))) (if predefined (puthash - bookkeeping-object + bookkeeping-object2 1 bookkeeping) (puthash - bookkeeping-object + bookkeeping-object2 0 bookkeeping))))) @@ -1159,7 +1172,7 @@ sub-scope object-name t)) - (bookkeeping-object + (bookkeeping-object2 (list object-start object-end)) @@ -1180,11 +1193,11 @@ t))) (if predefined (puthash - bookkeeping-object + bookkeeping-object2 1 bookkeeping) (puthash - bookkeeping-object + bookkeeping-object2 0 bookkeeping))))) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index bfe93e9c30..532f637032 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -1251,15 +1251,84 @@ ;; 131 ((inline_use_declaration) (unprefixed_use_declaration)) (puthash - 130 + 131 (lambda(args terminals) `( ast-type inline-use-declaration - (args) + declation + ,(args) + )) + phps-mode-parser--table-translations) + +;; 132 ((inline_use_declaration) (use_type unprefixed_use_declaration)) +(puthash + 132 + (lambda(args terminals) + `( + ast-type + inline-use-declaration + use-type + ,(nth 0 args) + declaration + ,(nth 1 args) + )) + phps-mode-parser--table-translations) + +;; 133 ((unprefixed_use_declaration) (namespace_name)) +(puthash + 133 + (lambda(args terminals) + `( + namespace-name + ,args + )) + phps-mode-parser--table-translations) + +;; 134 ((unprefixed_use_declaration) (namespace_name T_AS T_STRING)) +(puthash + 134 + (lambda(args terminals) + `( + namespace-name + ,(nth 0 args) + as + ,(nth 2 args) + )) + phps-mode-parser--table-translations) + +;; 135 ((use_declaration) (legacy_namespace_name)) +(puthash + 135 + (lambda(args terminals) + `( + ast-type + use-declaration + legacy-namespace-name + ,args + )) + phps-mode-parser--table-translations) + +;; 136 ((use_declaration) (legacy_namespace_name T_AS T_STRING)) +(puthash + 136 + (lambda(args terminals) + `( + ast-type + use-declaration + legacy-namespace-name + ,(nth 0 args) + as + ,(nth 2 args) )) phps-mode-parser--table-translations) +;; 137 ((const_list) (const_list "," const_decl)) +(puthash 137 (lambda(args terminals) (append (nth 0 args) (list (nth 2 args)))) phps-mode-parser--table-translations) + +;; 138 ((const_list) (const_decl)) +(puthash 138 (lambda(args terminals) (list args)) phps-mode-parser--table-translations) + ;; 139 inner_statement_list -> (inner_statement_list inner_statement) (puthash 139 @@ -1269,7 +1338,22 @@ (cdr args))) phps-mode-parser--table-translations) -;; statement -> ("{" inner_statement_list "}") +;; 140 ((inner_statement_list) (%empty)) +(puthash 140 (lambda(_args _terminals) nil) phps-mode-parser--table-translations) + +;; 141 ((inner_statement) (statement)) +(puthash 141 (lambda(args _terminals) args) phps-mode-parser--table-translations) + +;; 142 ((inner_statement) (attributed_statement)) +(puthash 142 (lambda(args _terminals) args) phps-mode-parser--table-translations) + +;; 143 ((inner_statement) (attributes attributed_statement)) +(puthash 143 (lambda(args _terminals) args) phps-mode-parser--table-translations) + +;; 144 ((inner_statement) (T_HALT_COMPILER "(" ")" ";")) +(puthash 144 (lambda(args _terminals) '(ast-type halt-compiler-inner-statement)) phps-mode-parser--table-translations) + +;; 145 ((statement) ("{" inner_statement_list "}")) (puthash 145 (lambda(args _terminals) diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index d52b348fe1..b52a37be96 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -38,17 +38,19 @@ (message "\n") (phps-mode-ast--generate) (phps-mode-ast-bookkeeping--generate) - ;; (message - ;; "expected-bookkeeping:\n%S\n" - ;; bookkeeping) - ;; (message - ;; "actual-bookkeeping:\n%S\n" - ;; (phps-mode-test--hash-to-list - ;; phps-mode-ast-bookkeeping--index - ;; t)) + + (message + "expected-bookkeeping:\n%S\n" + bookkeeping) + (message + "actual-bookkeeping:\n%S\n" + (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 (phps-mode-test--hash-to-list