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

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

[elpa] externals/phps-mode bc2ecad56a 11/15: More work on PHP 8.1


From: Christian Johansson
Subject: [elpa] externals/phps-mode bc2ecad56a 11/15: More work on PHP 8.1
Date: Sat, 26 Feb 2022 02:06:37 -0500 (EST)

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

    More work on PHP 8.1
---
 phps-mode-ast-bookkeeping.el | 90 ++++++++++++++++++++++++++++++++++++++++++++
 phps-mode-ast.el             |  4 +-
 phps-mode-lexer.el           | 18 +++++++--
 phps-mode-parser-sdt.el      |  2 +-
 phps-mode-syntax-color.el    |  2 +-
 test/phps-mode-test-ast.el   | 15 +++++---
 6 files changed, 119 insertions(+), 12 deletions(-)

diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el
index d8bda44a4a..0484eed3cd 100644
--- a/phps-mode-ast-bookkeeping.el
+++ b/phps-mode-ast-bookkeeping.el
@@ -847,6 +847,96 @@
 
                  ))))
 
+           ((equal type 'variable)
+            (let* ((subject (plist-get item 'array-object-dereferencable))
+                   (downcase-subject-name (downcase (plist-get subject 'name)))
+                   (property-name (plist-get item 'property-name)))
+
+              (when downcase-subject-name
+                (cond
+
+                 ((string= downcase-subject-name "$this")
+                  (puthash
+                   (list
+                    (plist-get subject 'start)
+                    (plist-get subject 'end))
+                   1
+                   bookkeeping)
+                  ;; When current scope is arrow function
+                  ;; we should go up in scope until we get out of
+                  ;; arrow functions scope
+                  (let ((sub-scope scope)
+                        (head-scope)
+                        (is-arrow-function-scope t))
+                    (while (and
+                            sub-scope
+                            is-arrow-function-scope)
+                      (setq
+                       head-scope
+                       (car sub-scope))
+                      (setq
+                       sub-scope
+                       (cdr sub-scope))
+                      (unless (equal
+                               (plist-get head-scope 'type)
+                               'arrow-function)
+                        (setq is-arrow-function-scope nil)))
+                    (let* ((predefined)
+                           (variable-ids
+                            
(phps-mode-ast-bookkeeping--generate-variable-scope-string
+                             sub-scope
+                             (concat "$" property-name)
+                             t))
+                           (symbol-id
+                            
(phps-mode-ast-bookkeeping--generate-symbol-scope-string
+                             sub-scope
+                             property-name))
+                           (bookkeeping-object
+                            (list
+                             (plist-get item 'property-start)
+                             (plist-get item 'property-end))))
+                      (when (gethash symbol-id bookkeeping)
+                        (setq
+                         predefined
+                         t))
+                      (dolist (variable-id variable-ids)
+                        (when (gethash variable-id bookkeeping)
+                          (setq
+                           predefined
+                           t)))
+                      (if predefined
+                          (puthash
+                           bookkeeping-object
+                           1
+                           bookkeeping)
+                        (puthash
+                         bookkeeping-object
+                         0
+                         bookkeeping)))))
+
+                 (t
+                  (let ((variable-ids
+                         
(phps-mode-ast-bookkeeping--generate-variable-scope-string
+                          scope
+                          (plist-get subject 'name)
+                          t))
+                        (predefined 0))
+                    (dolist (variable-id variable-ids)
+                      (when (gethash
+                             variable-id
+                             bookkeeping)
+                        (setq
+                         predefined
+                         1)))
+                    (puthash
+                     (list
+                      (plist-get subject 'start)
+                      (plist-get subject 'end))
+                     predefined
+                     bookkeeping)))
+
+                 ))))
+
            ((equal type 'static-member)
             (let* ((parent-class (plist-get item 'class))
                    (downcased-parent-class (downcase parent-class))
diff --git a/phps-mode-ast.el b/phps-mode-ast.el
index eca2c86800..e395a23a12 100644
--- a/phps-mode-ast.el
+++ b/phps-mode-ast.el
@@ -40,7 +40,7 @@
      phps-mode-ast--parse-trail
      parse-trail)
 
-    ;; (message "\nTranslation:\n%S\n\n" translation)
+    (message "\nTranslation:\n%S\n\n" translation)
 
     (when translation
       (dolist (item translation)
@@ -90,7 +90,7 @@
      ast
      (reverse ast))
 
-    ;; (message "AST:\n%S\n\n" ast)
+    (message "AST:\n%S\n\n" ast)
 
     (setq
      phps-mode-ast--tree
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index e3a2193d98..077e9d762d 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -9,8 +9,8 @@
 ;; any higher order meta-lexer logic goes into `phps-mode-lex-analyzer.el'.
 ;;
 ;; Features:
-;; * Defines the lexer for this grammar based on the Zend PHP 8.0 Lexer at
-;; 
https://raw.githubusercontent.com/php/php-src/php-8.0.0/Zend/zend_language_parser.y
+;; * Defines the lexer for this grammar based on the Zend PHP 8.1 Lexer at
+;; 
https://raw.githubusercontent.com/php/php-src/PHP-8.1/Zend/zend_language_scanner.l
 ;; which is using re2c.
 
 ;;; Code:
@@ -109,7 +109,8 @@
 
 (defconst
   phps-mode-lexer--lambdas-by-state
-  #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (ST_IN_SCRIPTING ((lambda nil (when (looking-at "exit") (let ((match-end 
(match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- 
match-end match-beginning))) (when (> matching-length 0) (when (or (not 
phps-mode-lexer--match-length) (> matching-length 
phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length 
matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps- [...]
+  #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (ST_IN_SCRIPTING ((lambda nil (when (looking-at "exit") (let ((match-end 
(match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- 
match-end match-beginning))) (when (> matching-length 0) (when (or (not 
phps-mode-lexer--match-length) (> matching-length 
phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length 
matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps- [...]
+]*" "\\(\\$\\|\\.\\.\\.\\)")) (let ((match-end (match-end 0)) (match-beginning 
(match-beginning 0))) (let ((matching-length (- match-end match-beginning))) 
(when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> 
matching-length phps-mode-lexer--match-length)) (setq 
phps-mode-lexer--match-length matching-length) (setq 
phps-mode-lexer--match-body (lambda nil (phps-mode-lexer--yyless 1) 
(phps-mode-lexer--return-token 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG))) (setq 
phps- [...]
 " phps-mode-lexer--heredoc-label ";?
 \\|\\$" phps-mode-lexer--label "\\|{\\$" phps-mode-lexer--label "\\|\\${" 
phps-mode-lexer--label "\\)") nil t))) (if string-start (let* ((start 
(match-beginning 0)) (end (match-end 0)) (data (buffer-substring-no-properties 
start end))) (cond ((string-match (concat "
 " phps-mode-lexer--heredoc-label ";?
@@ -1145,6 +1146,17 @@
    (looking-at ">>")
    (phps-mode-lexer--return-token 'T_SR))
 
+  (phps-mode-lexer--match-macro
+   ST_IN_SCRIPTING
+   (looking-at (concat "&" "[ \t\r\n]*" "\\(\\$\\|\\.\\.\\.\\)"))
+   (phps-mode-lexer--yyless 1)
+   (phps-mode-lexer--return-token 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG))
+
+  (phps-mode-lexer--match-macro
+   ST_IN_SCRIPTING
+   (looking-at "&")
+   (phps-mode-lexer--return-token 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG))
+
   (phps-mode-lexer--match-macro
    ST_IN_SCRIPTING
    (looking-at
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 83fe389536..b72207a1d9 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -1156,7 +1156,7 @@
 
 ;; attributed_class_statement -> (variable_modifiers 
optional_type_without_static property_list ";")
 (puthash
- 299
+ 298
  (lambda(args terminals)
    `(
      ast-type
diff --git a/phps-mode-syntax-color.el b/phps-mode-syntax-color.el
index 60feee7449..5f622b2c08 100644
--- a/phps-mode-syntax-color.el
+++ b/phps-mode-syntax-color.el
@@ -11,7 +11,7 @@
 
 (defvar
   phps-mode-syntax-color--token-font-face
-  #s(hash-table size 145 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (T_ERROR font-lock-warning-face T_OPEN_TAG font-lock-constant-face 
T_OPEN_TAG_WITH_ECHO font-lock-constant-face T_CLOSE_TAG 
font-lock-constant-face T_START_HEREDOC font-lock-constant-face T_END_HEREDOC 
font-lock-constant-face T_ELLIPSIS font-lock-constant-face T_COALESCE 
font-lock-constant-face T_DOUBLE_ARROW font-lock-constant-face T_INC 
font-lock-constant-face T_DEC font-lock-constant-face T_IS_IDENTICAL f [...]
+  #s(hash-table size 149 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (T_ERROR font-lock-warning-face T_OPEN_TAG font-lock-constant-face 
T_OPEN_TAG_WITH_ECHO font-lock-constant-face T_CLOSE_TAG 
font-lock-constant-face T_START_HEREDOC font-lock-constant-face T_END_HEREDOC 
font-lock-constant-face T_ELLIPSIS font-lock-constant-face T_COALESCE 
font-lock-constant-face T_DOUBLE_ARROW font-lock-constant-face T_INC 
font-lock-constant-face T_DEC font-lock-constant-face T_IS_IDENTICAL f [...]
   "Syntax color table for tokens")
 
 (defvar
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index bab8269a7b..3c7c470345 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -26,7 +26,7 @@
    (lambda()
       (let ((parse (phps-mode-parser-parse)))
         (message "Left-to-right with right-most derivation in reverse:\n%S\n" 
parse)
-        (dolist (production-number (reverse parse))
+        (dolist (production-number parse)
           (let ((production
                  (phps-mode-parser--get-grammar-production-by-number
                   production-number)))
@@ -38,9 +38,14 @@
       (message "\n")
       (phps-mode-ast--generate)
       (phps-mode-ast-bookkeeping--generate)
-      (message "bookkeeping: %S" (phps-mode-test--hash-to-list
-         phps-mode-ast-bookkeeping--index
-         t))
+      (message
+       "expected-bookkeeping: %S\n"
+       bookkeeping)
+      (message
+       "actual-bookkeeping: %S\n"
+       (phps-mode-test--hash-to-list
+        phps-mode-ast-bookkeeping--index
+        t))
       (should
        (equal
         (phps-mode-test--hash-to-list
@@ -55,7 +60,7 @@
    (lambda()
       (let ((parse (phps-mode-parser-parse)))
         (message "Left-to-right with right-most derivation in reverse:\n%S\n" 
parse)
-        (dolist (production-number (reverse parse))
+        (dolist (production-number parse)
           (let ((production
                  (phps-mode-parser--get-grammar-production-by-number
                   production-number)))



reply via email to

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