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

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

[elpa] externals/phps-mode 67f9a7a 057/405: Moved lexer-get-point-data t


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 67f9a7a 057/405: Moved lexer-get-point-data to functions
Date: Sat, 13 Jul 2019 09:59:42 -0400 (EDT)

branch: externals/phps-mode
commit 67f9a7a235eb1f78a75e18b378ce9a08fb87178d
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Moved lexer-get-point-data to functions
---
 phps-functions.el      | 81 ++++++++++++++++++++++++++++++++++++++++++++++++--
 phps-lexer.el          | 76 ----------------------------------------------
 phps-test-functions.el | 68 ++++++++++++++++++++++++++++++++++++++++++
 phps-test-lexer.el     | 67 -----------------------------------------
 4 files changed, 146 insertions(+), 146 deletions(-)

diff --git a/phps-functions.el b/phps-functions.el
index 85efa86..03b1119 100644
--- a/phps-functions.el
+++ b/phps-functions.el
@@ -39,13 +39,11 @@
 (defvar phps-mode/buffer-changes--start nil
   "Start of buffer changes, nil if none.")
 
-(autoload 'phps-mode/lexer-get-point-data "phps-lexer")
-
 ;; TODO Should also format white-space inside the line, i.e. after function 
declarations?
 ;; TODO Should indent doc blocks with 1 space
 (defun phps-mode/indent-line ()
   "Indent line."
-  (let ((data (phps-mode/lexer-get-point-data)))
+  (let ((data (phps-mode/get-point-data)))
     (let* ((start (nth 0 data))
            (end (nth 1 data))
            (in-scripting (nth 0 start)))
@@ -113,6 +111,83 @@
     ;; (message "phps-mode/after-change-functions %s %s %s" start stop length)
     ))
 
+(defun phps-mode/get-point-data ()
+  "Return information about point in tokens."
+  ;; (message "Point: %s in %s" (point) phps-mode/lexer-tokens)
+  (when (boundp 'phps-mode/lexer-tokens)
+    (save-excursion
+      (beginning-of-line)
+      (let ((position (point))
+            (line-end (line-end-position))
+            (start-in-scripting nil)
+            (start-brace-level 0)
+            (start-parenthesis-level 0)
+            (start-inline-function-level 0)
+            (start-token-number nil)
+            (end-in-scripting nil)
+            (end-brace-level 0)
+            (end-parenthesis-level 0)
+            (end-inline-function-level 0)
+            (end-token-number nil)
+            (line-in-doc-comment nil)
+            (found-line-tokens nil))
+        (catch 'stop-iteration
+          (dolist (item phps-mode/lexer-tokens)
+            (let ((token (car item))
+                  (token-start (car (cdr item)))
+                  (token-end (cdr (cdr item))))
+              ;; (message "Token: %s Start: %s End: %s Item: %s" token start 
end item)
+
+              (when (> token-start line-end)
+                ;; (message "Stopping iteration at: %s %s" start position)
+                (throw 'stop-iteration nil))
+
+              (when (and (not found-line-tokens)
+                         (>= token-start position)
+                         (<= token-end line-end))
+                (setq found-line-tokens t))
+
+              ;; When end of token is equal or less to current point
+              (when (<= token-end position)
+                (when (null start-token-number)
+                  (setq start-token-number -1))
+                (setq start-token-number (+ start-token-number 1))
+                (pcase token
+                  ('T_OPEN_TAG (setq start-in-scripting t))
+                  ('T_OPEN_TAG_WITH_ECHO (setq start-in-scripting t))
+                  ('T_CLOSE_TAG (setq start-in-scripting nil))
+                  ('T_DOC_COMMENT (setq line-in-doc-comment nil))
+                  ("}" (setq start-brace-level (- start-brace-level 1)))
+                  ("{" (setq start-brace-level (+ start-brace-level 1)))
+                  ("(" (setq start-parenthesis-level (+ 
start-parenthesis-level 1)))
+                  (")" (setq start-parenthesis-level (- 
start-parenthesis-level 1)))
+                  (_)))
+
+              ;; When start of token is equal or less to end of curent line
+              (when (<= token-start line-end)
+                (when (null end-token-number)
+                  (setq end-token-number -1))
+                (setq end-token-number (+ end-token-number 1))
+                (setq line-in-doc-comment nil)
+                (pcase token
+                  ('T_OPEN_TAG (setq end-in-scripting t))
+                  ('T_OPEN_TAG_WITH_ECHO (setq end-in-scripting t))
+                  ('T_CLOSE_TAG (setq end-in-scripting nil))
+                  ('T_DOC_COMMENT (setq line-in-doc-comment t))
+                  ("}" (setq end-brace-level (- end-brace-level 1)))
+                  ("{" (setq end-brace-level (+ end-brace-level 1)))
+                  ("(" (setq end-parenthesis-level (+ end-parenthesis-level 
1)))
+                  (")" (setq end-parenthesis-level (- end-parenthesis-level 
1)))
+                  (_)))
+              
+              )))
+        (when (not found-line-tokens)
+          (setq start-token-number nil)
+          (setq end-token-number nil))
+        (let ((data (list (list start-in-scripting start-brace-level 
start-parenthesis-level start-inline-function-level start-token-number 
line-in-doc-comment) (list end-in-scripting end-brace-level 
end-parenthesis-level end-inline-function-level end-token-number 
line-in-doc-comment))))
+          ;; (message "data: %s" data)
+          data)))))
+
 (defun phps-mode/functions-init ()
   "PHP specific init-cleanup routines."
 
diff --git a/phps-lexer.el b/phps-lexer.el
index 3662d5e..88d65b3 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -1259,82 +1259,6 @@ ANY_CHAR'
 
    ))
 
-(defun phps-mode/lexer-get-point-data()
-  "Return information about point in tokens."
-  ;; (message "Point: %s in %s" (point) phps-mode/lexer-tokens)
-  (save-excursion
-    (beginning-of-line)
-    (let ((position (point))
-          (line-end (line-end-position))
-          (start-in-scripting nil)
-          (start-brace-level 0)
-          (start-parenthesis-level 0)
-          (start-inline-function-level 0)
-          (start-token-number nil)
-          (end-in-scripting nil)
-          (end-brace-level 0)
-          (end-parenthesis-level 0)
-          (end-inline-function-level 0)
-          (end-token-number nil)
-          (line-in-doc-comment nil)
-          (found-line-tokens nil))
-      (catch 'stop-iteration
-        (dolist (item phps-mode/lexer-tokens)
-          (let ((token (car item))
-                (token-start (car (cdr item)))
-                (token-end (cdr (cdr item))))
-            ;; (message "Token: %s Start: %s End: %s Item: %s" token start end 
item)
-
-            (when (> token-start line-end)
-              ;; (message "Stopping iteration at: %s %s" start position)
-              (throw 'stop-iteration nil))
-
-            (when (and (not found-line-tokens)
-                       (>= token-start position)
-                       (<= token-end line-end))
-              (setq found-line-tokens t))
-
-            ;; When end of token is equal or less to current point
-            (when (<= token-end position)
-              (when (null start-token-number)
-                (setq start-token-number -1))
-              (setq start-token-number (+ start-token-number 1))
-              (pcase token
-                ('T_OPEN_TAG (setq start-in-scripting t))
-                ('T_OPEN_TAG_WITH_ECHO (setq start-in-scripting t))
-                ('T_CLOSE_TAG (setq start-in-scripting nil))
-                ('T_DOC_COMMENT (setq start-in-doc-comment nil))
-                ("}" (setq start-brace-level (- start-brace-level 1)))
-                ("{" (setq start-brace-level (+ start-brace-level 1)))
-                ("(" (setq start-parenthesis-level (+ start-parenthesis-level 
1)))
-                (")" (setq start-parenthesis-level (- start-parenthesis-level 
1)))
-                (_)))
-
-            ;; When start of token is equal or less to end of curent line
-            (when (<= token-start line-end)
-              (when (null end-token-number)
-                (setq end-token-number -1))
-              (setq end-token-number (+ end-token-number 1))
-              (setq line-in-doc-comment nil)
-              (pcase token
-                ('T_OPEN_TAG (setq end-in-scripting t))
-                ('T_OPEN_TAG_WITH_ECHO (setq end-in-scripting t))
-                ('T_CLOSE_TAG (setq end-in-scripting nil))
-                ('T_DOC_COMMENT (setq line-in-doc-comment t))
-                ("}" (setq end-brace-level (- end-brace-level 1)))
-                ("{" (setq end-brace-level (+ end-brace-level 1)))
-                ("(" (setq end-parenthesis-level (+ end-parenthesis-level 1)))
-                (")" (setq end-parenthesis-level (- end-parenthesis-level 1)))
-                (_)))
-            
-            )))
-      (when (not found-line-tokens)
-        (setq start-token-number nil)
-        (setq end-token-number nil))
-      (let ((data (list (list start-in-scripting start-brace-level 
start-parenthesis-level start-inline-function-level start-token-number 
line-in-doc-comment) (list end-in-scripting end-brace-level 
end-parenthesis-level end-inline-function-level end-token-number 
line-in-doc-comment))))
-        ;; (message "data: %s" data)
-        data))))
-
 ;; TODO Need to store lexer state and stack at each changing point of buffer 
to be able to rewind lexer
 (defun phps-mode/lex--SETUP (start end)
   "Just prepare other lexers for lexing region START to END."
diff --git a/phps-test-functions.el b/phps-test-functions.el
index ae9d11d..a79babb 100644
--- a/phps-test-functions.el
+++ b/phps-test-functions.el
@@ -39,6 +39,7 @@
 
 (autoload 'phps-mode/with-test-buffer "phps-test")
 (autoload 'phps-mode/indent-line "phps-functions")
+(autoload 'phps-mode/get-point-data "phps-functions")
 (autoload 'should "ert")
 
 (defun phps-mode/test-indent-line ()
@@ -108,10 +109,77 @@
 
   )
 
+(defun phps-mode/test-functions--get-point-data ()
+  "Return information about point in tokens."
+
+  (phps-mode/with-test-buffer
+   "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function 
__construct() {\n\t\texit;\n\t}\n}\n"
+   (goto-char 35)
+   (should (equal (list (list t 0 0 0 3 nil) (list t 1 0 0 6 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
+   (goto-char 15)
+   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 5 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php echo $title; ?>\n</title><body>Bla 
bla</body></html>"
+   (goto-char 50)
+   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 nil nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title></title><body>Bla bla</body></html>"
+   (goto-char 15)
+   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 nil nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
+   (goto-char 30)
+   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 5 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
+   (goto-char 50)
+   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 5 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php if ($myCondition) { \n   if ($mySeconCondition) { 
echo $title; } } ?></title><body>Bla bla</body></html>"
+   ;; (message "Tokens: %s" phps-mode/lexer-tokens)
+   (goto-char 48)
+   (should (equal (list (list t 1 0 0 5 nil) (list nil 0 0 0 17 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) {\n 
echo $title;\n} } ?></title><body>Bla bla</body></html>"
+   (goto-char 72)
+   (should (equal (list (list t 2 0 0 10 nil) (list t 2 0 0 13 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n}\n}\n ?></title><body>Bla bla</body></html>"
+   (goto-char 84)
+   (should (equal (list (list t 2 0 0 13 nil) (list t 1 0 0 14 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) { echo 
$title; } } ?></title><body>Bla bla</body></html>"
+   (goto-char 100)
+   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 17 nil)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<?php /**\n * My first line\n * My second line\n **/"
+   (goto-char 20)
+   (should (equal (list (list t 0 0 0 nil t) (list t 0 0 0 nil t)) 
(phps-mode/get-point-data))))
+
+  (phps-mode/with-test-buffer
+   "<?php /**\n * My first line\n * My second line\n **/"
+   (goto-char 10)
+   (should (equal (list (list nil 0 0 0 nil t) (list t 0 0 0 1 t)) 
(phps-mode/get-point-data))))
+
+  )
+
 ;; TODO Add tests for all examples here: https://www.php-fig.org/psr/psr-2/
 
 (defun phps-mod/test-functions ()
   "Run test for functions."
+  (phps-mode/test-functions--get-point-data)
   (phps-mode/test-indent-line))
 
 (phps-mod/test-functions)
diff --git a/phps-test-lexer.el b/phps-test-lexer.el
index e359037..d152f6c 100644
--- a/phps-test-lexer.el
+++ b/phps-test-lexer.el
@@ -268,72 +268,6 @@
 
   )
 
-(defun phps-mode/test-lexer--get-point-data ()
-  "Return information about point in tokens."
-
-  (phps-mode/with-test-buffer
-   "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function 
__construct() {\n\t\texit;\n\t}\n}\n"
-   (goto-char 35)
-   (should (equal (list (list t 0 0 0 3 nil) (list t 1 0 0 6 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
-   (goto-char 15)
-   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 5 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php echo $title; ?>\n</title><body>Bla 
bla</body></html>"
-   (goto-char 50)
-   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 nil nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title></title><body>Bla bla</body></html>"
-   (goto-char 15)
-   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 nil nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
-   (goto-char 30)
-   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 5 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
-   (goto-char 50)
-   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 5 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php if ($myCondition) { \n   if ($mySeconCondition) { 
echo $title; } } ?></title><body>Bla bla</body></html>"
-   ;; (message "Tokens: %s" phps-mode/lexer-tokens)
-   (goto-char 48)
-   (should (equal (list (list t 1 0 0 5 nil) (list nil 0 0 0 17 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) {\n 
echo $title;\n} } ?></title><body>Bla bla</body></html>"
-   (goto-char 72)
-   (should (equal (list (list t 2 0 0 10 nil) (list t 2 0 0 13 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n}\n}\n ?></title><body>Bla bla</body></html>"
-   (goto-char 84)
-   (should (equal (list (list t 2 0 0 13 nil) (list t 1 0 0 14 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) { echo 
$title; } } ?></title><body>Bla bla</body></html>"
-   (goto-char 100)
-   (should (equal (list (list nil 0 0 0 nil nil) (list nil 0 0 0 17 nil)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<?php /**\n * My first line\n * My second line\n **/"
-   (goto-char 20)
-   (should (equal (list (list t 0 0 0 nil t) (list t 0 0 0 nil t)) 
(phps-mode/lexer-get-point-data))))
-
-  (phps-mode/with-test-buffer
-   "<?php /**\n * My first line\n * My second line\n **/"
-   (goto-char 10)
-   (should (equal (list (list nil 0 0 0 nil t) (list t 0 0 0 1 t)) 
(phps-mode/lexer-get-point-data))))
-
-  )
-
 (defun phps-mode/test-lexer ()
   "Run test for lexer."
   ;; (message "-- Running all tests for lexer... --\n")
@@ -343,7 +277,6 @@
   (phps-mode/test-lexer--complex-tokens)
   (phps-mode/test-lexer--namespaces)
   (phps-mode/test-lexer--errors)
-  (phps-mode/test-lexer--get-point-data)
   ;; (message "\n-- Ran all tests for lexer. --")
   )
 



reply via email to

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