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

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

[elpa] externals/phps-mode 6be9923: Improved incremental parsing and boo


From: Christian Johansson
Subject: [elpa] externals/phps-mode 6be9923: Improved incremental parsing and bookkeeping of super-globals variables
Date: Fri, 29 Jan 2021 05:47:01 -0500 (EST)

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

    Improved incremental parsing and bookkeeping of super-globals variables
---
 phps-mode-lex-analyzer.el           | 30 ++++++++++++++++++++++++------
 phps-mode-lexer.el                  |  9 +++++++++
 phps-mode-macros.el                 |  4 +++-
 phps-mode.el                        |  4 ++--
 test/phps-mode-test-integration.el  |  8 ++++++++
 test/phps-mode-test-lex-analyzer.el |  4 ++--
 6 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index f834f18..ed66b6d 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -684,14 +684,31 @@
 
                 (catch 'quit
                   (dolist (token old-tokens)
-                    (let ((start (car (cdr token)))
+                    (let ((token-type (car token))
+                          (start (car (cdr token)))
                           (end (cdr (cdr token))))
                       (if (< end change-start)
                           (push token head-tokens)
                         (when (< start change-start)
+                          (when (equal token-type 'T_END_HEREDOC)
+                            ;; When incremental start is on a T_END_HEREDOC 
token
+                            ;; rewind another token to allow expansion of
+                            ;; T_ENCAPSED_AND_WHITESPACE
+                            (phps-mode-debug-message
+                             (message
+                              "Rewinding incremental start due to 
'T_END_HEREDOC token"))
+                            (let ((previous-token (pop head-tokens)))
+                              (setq
+                               start
+                               (car (cdr previous-token)))))
+
                           (phps-mode-debug-message
-                           (message "New incremental-start-new-buffer: %s" 
start))
-                          (setq incremental-start-new-buffer start))
+                           (message
+                            "New incremental-start-new-buffer: %s"
+                            start))
+                          (setq
+                           incremental-start-new-buffer
+                           start))
                         (throw 'quit "break")))))
 
                 (setq head-tokens (nreverse head-tokens))
@@ -705,15 +722,13 @@
                       (phps-mode-debug-message
                        (message "Found head tokens"))
 
-                      ;; TODO Change on ST_END_HEREDOC should start before it
-
                       ;; In old buffer:
                       ;; 1. Determine state (incremental-state) and 
state-stack (incremental-state-stack) heredoc label (incremental-heredoc-label) 
heredoc-label-stack (heredoc-label-stack) before incremental start
                       ;; 2. Build list of states before incremental start 
(head-states)
                       (catch 'quit
                         (dolist (state-object (nreverse old-states))
                           (let ((end (nth 1 state-object)))
-                            (if (< end change-start)
+                            (if (<= end incremental-start-new-buffer)
                                 (progn
                                   (setq incremental-state (nth 2 state-object))
                                   (setq incremental-state-stack (nth 3 
state-object))
@@ -1231,6 +1246,9 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                                   (equal bookkeeping-variable-name "$_REQUEST")
                                   (equal bookkeeping-variable-name "$_SERVER")
                                   (equal bookkeeping-variable-name "$_SESSION")
+                                  (equal bookkeeping-variable-name "$argc")
+                                  (equal bookkeeping-variable-name "$argv")
+                                  (equal bookkeeping-variable-name 
"$http_​response_​header")
                                   ))
                         (setq bookkeeping-is-superglobal t))
 
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index 47c3449..358d8b3 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -260,6 +260,15 @@
 
 (defun phps-mode-lexer--emit-token (token start end)
   "Emit TOKEN with START and END."
+  (when (= start end)
+    (signal
+     'phps-lexer-error
+     (list
+      (format "Empty token detected: %s %s %s" token start end)
+      start
+      end
+      token)))
+
   (semantic-lex-push-token (semantic-lex-token token start end))
   (push `(,token ,start . ,end) phps-mode-lexer--generated-tokens)
 
diff --git a/phps-mode-macros.el b/phps-mode-macros.el
index 9e505e7..5591e6f 100644
--- a/phps-mode-macros.el
+++ b/phps-mode-macros.el
@@ -7,7 +7,9 @@
 
 ;;; Code:
 
-(defconst phps-mode-macrotime-debug nil
+(defconst
+  phps-mode-macrotime-debug
+  nil
   "Debug messages during macro expansion time, default nil.")
 
 (defmacro phps-mode-debug-message (&rest message)
diff --git a/phps-mode.el b/phps-mode.el
index 5339a28..cbab269 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -5,8 +5,8 @@
 ;; Author: Christian Johansson <christian@cvj.se>
 ;; Maintainer: Christian Johansson <christian@cvj.se>
 ;; Created: 3 Mar 2018
-;; Modified: 28 Jan 2021
-;; Version: 0.4.0
+;; Modified: 29 Jan 2021
+;; Version: 0.4.1
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
diff --git a/test/phps-mode-test-integration.el 
b/test/phps-mode-test-integration.el
index cf2ce03..0a8e90e 100644
--- a/test/phps-mode-test-integration.el
+++ b/test/phps-mode-test-integration.el
@@ -161,6 +161,14 @@
    (goto-char 85)
    (kill-line))
 
+  (phps-mode-test--incremental-vs-intial-buffer
+   "<?php\n$str = <<<EOD\nExample of string\nspanning multiple lines\nusing 
heredoc syntax.\nEOD;\n\n/* More complex example, with variables. */\nclass 
foo\n{\n    var $foo;\n    var $bar;\n\n    function __construct()\n    {\n     
   $this->foo = 'Foo';\n        $this->bar = array('Bar1', 'Bar2', 'Bar3');\n   
 }\n}\n\n$foo = new foo();\n$name = 'MyName';\n\necho <<<EOT\nMy name is 
\"$name\". I am printing some $foo->foo.\nNow, I am printing some 
{$foo->bar[1]}.\nThis should print a capi [...]
+   "Integration-test 14 complex HEREDOC with removed heredoc delimiter 
semicolon"
+   ;; (message "\nTokens: %s" phps-mode-lex-analyzer--tokens)
+   ;; (message "States: %s\n" phps-mode-lex-analyzer--states)
+   (goto-char 88)
+   (delete-char 1))
+
   )
 
 (defun phps-mode-test-integration--whitespace-modifications ()
diff --git a/test/phps-mode-test-lex-analyzer.el 
b/test/phps-mode-test-lex-analyzer.el
index 80d4318..75a2e2b 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -1404,12 +1404,12 @@
             (list (list " id $var2" 1) (list (list 8 13) 1) (list " function 
myFunction id $var" 1) (list (list 40 44) 1) (list " function myFunction id 
$var3" 1) (list (list 52 57) 1) (list (list 70 74) 1) (list (list 112 117) 0) 
(list (list 156 161) 1) (list " function myFunction2 id $abc" 1) (list (list 
215 219) 1) (list (list 231 235) 0) (list (list 274 278) 1) (list (list 315 
319) 0) (list (list 346 351) 1)))))
 
   (phps-mode-test--with-buffer
-   "<?php\n\n// Super-globals\n\nif ($_GET) {\n    echo 'Hit';\n}\nif ($_POST) 
{\n    echo 'Hit';\n}\nif ($_COOKIE) {\n    echo 'Hit';\n}\nif ($_SESSION) {\n  
  echo 'Hit';\n}\nif ($_REQUEST) {\n    echo 'Hit';\n}\nif ($GLOBALS) {\n    
echo 'Hit';\n}\nif ($_SERVER) {\n    echo 'Hit';\n}\nif ($_FILES) {\n    echo 
'Hit';\n}\nif ($_ENV) {\n    echo 'Hit';\n}"
+   "<?php\n\n// Super-globals\n\nif ($_GET) {\n    echo 'Hit';\n}\nif ($_POST) 
{\n    echo 'Hit';\n}\nif ($_COOKIE) {\n    echo 'Hit';\n}\nif ($_SESSION) {\n  
  echo 'Hit';\n}\nif ($_REQUEST) {\n    echo 'Hit';\n}\nif ($GLOBALS) {\n    
echo 'Hit';\n}\nif ($_SERVER) {\n    echo 'Hit';\n}\nif ($_FILES) {\n    echo 
'Hit';\n}\nif ($_ENV) {\n    echo 'Hit';\n}\nif ($argc) {\n    echo 
'Hit';\n}\nif ($argv) {\n    echo 'Hit';\n}\nif ($http_​response_​header) {\n   
 echo 'Hit';\n}"
    "Bookkeeping of super-globals"
    (should
     (equal
      (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-bookkeeping) t)
-     (list (list (list 30 35) 1) (list (list 61 67) 1) (list (list 93 101) 1) 
(list (list 127 136) 1) (list (list 162 171) 1) (list (list 197 205) 1) (list 
(list 231 239) 1) (list (list 265 272) 1) (list (list 298 303) 1)))))
+     (list (list (list 30 35) 1) (list (list 61 67) 1) (list (list 93 101) 1) 
(list (list 127 136) 1) (list (list 162 171) 1) (list (list 197 205) 1) (list 
(list 231 239) 1) (list (list 265 272) 1) (list (list 298 303) 1) (list (list 
329 334) 1) (list (list 360 365) 1)  (list (list 391 414) 1)))))
 
   (phps-mode-test--with-buffer
    "<?php\n\nnamespace myNamespaceA {\n    $var = 123;\n    class myClassA {\n 
       private $var2 = 123;\n        function myFunctionA($var3) {\n            
$var4 = 123;\n            if ($var) {\n                echo 'Miss';\n           
 }\n            if ($var2) {\n                echo 'Miss';\n            }\n     
       if ($var3) {\n                echo 'Hit';\n            }\n            if 
($var4) {\n                echo 'Hit';\n            }\n        }\n\n        
function myFuncti [...]



reply via email to

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