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

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

[elpa] externals/phps-mode 91b425f 73/96: Update of parsers lex-analyzer


From: Christian Johansson
Subject: [elpa] externals/phps-mode 91b425f 73/96: Update of parsers lex-analyzer function to not depend on lexer buffer
Date: Fri, 29 Oct 2021 11:14:53 -0400 (EDT)

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

    Update of parsers lex-analyzer function to not depend on lexer buffer
---
 phps-mode-automation-grammar.el | 225 ++++++++++++++--------------
 phps-mode-parser.el             | 319 ++++++++++++++++++++--------------------
 2 files changed, 268 insertions(+), 276 deletions(-)

diff --git a/phps-mode-automation-grammar.el b/phps-mode-automation-grammar.el
index 654cc7d..2d160e6 100644
--- a/phps-mode-automation-grammar.el
+++ b/phps-mode-automation-grammar.el
@@ -70,7 +70,9 @@
 (defvar
   phps-mode-automation-grammar--lex-analyzer-reset-function
   (lambda()
-    (progn
+    (let ((generated-tokens-p)
+          (generated-tokens-list))
+
       ;; Create lexer buffer if none exists
       (unless (get-buffer "*PHPs Lexer*")
         (generate-new-buffer "*PHPs Lexer*")
@@ -118,130 +120,123 @@
                  index
                  semantic-lex-end-point)
                 (goto-char index))))
-          (setq-local
-           phps-mode-parser-tokens
+          (setq
+           generated-tokens-p
+           t)
+          (setq
+           generated-tokens-list
            (reverse
-            phps-mode-lexer--generated-tokens))
+            phps-mode-lexer--generated-tokens))))
 
-          ;; Reset buffer-index to token-list-index connections
-          (setq-local
-           phps-mode-parser-position
-           nil)))
+      (when generated-tokens-p
+        (setq-local
+         phps-mode-parser-tokens
+         generated-tokens-list))
 
-      ))
+      ;; Reset buffer-index to token-list-index connections
+      (setq-local
+       phps-mode-parser-position
+       nil)))
   "The reset function.")
 
 (defvar
   phps-mode-automation-grammar--lex-analyzer-function
   (lambda (buffer-index)
-    (progn
+    (let ((token-list-index))
+      (if (and
+           phps-mode-parser-position
+           (= (car (car phps-mode-parser-position)) buffer-index))
+          (progn
+            (setq
+             token-list-index
+             (car (cdr (car phps-mode-parser-position)))))
+
+        ;; Search from last requested index and forward until
+        ;; we find a token starting at or after buffer-index and
+        ;; use this as buffer-index, save buffer-index to
+        ;; token-list-index connection
+        (let ((previous-token-list-index 0))
+          (when (and
+                 phps-mode-parser-position
+                 (< (car (car phps-mode-parser-position)) buffer-index))
+            (setq
+             previous-token-list-index
+             (car (cdr (car phps-mode-parser-position)))))
+
+          (let ((temp-token-list-index
+                 previous-token-list-index)
+                (token-list-size
+                 (length
+                  phps-mode-parser-tokens))
+                (continue t))
+            (while (and
+                    continue
+                    (<
+                     temp-token-list-index
+                     token-list-size))
+              (let ((token
+                     (nth
+                      temp-token-list-index
+                      phps-mode-parser-tokens)))
+
+                ;; When token starts at cursor we found correct index
+                ;; Save it
+                (when (= (car (cdr token)) buffer-index)
+                  (let ((token-type (car token)))
+                    (push
+                     (list
+                      buffer-index
+                      temp-token-list-index)
+                     phps-mode-parser-position)
+                    (unless (or
+                             (equal token-type 'T_OPEN_TAG)
+                             (equal token-type 'T_CLOSE_TAG)
+                             (equal token-type 'T_DOC_COMMENT)
+                             (equal token-type 'T_COMMENT))
+                      (setq
+                       token-list-index
+                       temp-token-list-index)
+                      (setq
+                       continue
+                       nil))))
+
+                ;; When token starts after cursor, flag move of cursor
+                ;; Save it
+                (when (> (car (cdr token)) buffer-index)
+                  (let ((token-type (car token)))
+                    (push
+                     (list
+                      (car (cdr token))
+                      temp-token-list-index)
+                     phps-mode-parser-position)
+                    (unless (or
+                             (equal token-type 'T_OPEN_TAG)
+                             (equal token-type 'T_CLOSE_TAG)
+                             (equal token-type 'T_DOC_COMMENT)
+                             (equal token-type 'T_COMMENT))
+                      (setq-local
+                       phps-mode-parser-lex-analyzer--move-to-index-flag
+                       (car (cdr token)))
+                      (setq
+                       continue
+                       nil))))
 
-      ;; Create lexer buffer if none exists
-      (unless (get-buffer "*PHPs Lexer*")
-        (generate-new-buffer "*PHPs Lexer*")
-        (let ((old-buffer
-               (buffer-substring-no-properties
-                (point-min)
-                (point-max))))
-          (with-current-buffer "*PHPs Lexer*"
-            (insert old-buffer))))
-      
-      (with-current-buffer "*PHPs Lexer*"
-        (let ((token-list-index))
-          (if (and
-               phps-mode-parser-position
-               (= (car (car phps-mode-parser-position)) buffer-index))
-              (progn
                 (setq
-                 token-list-index
-                 (car (cdr (car phps-mode-parser-position)))))
-
-            ;; Search from last requested index and forward until
-            ;; we find a token starting at or after buffer-index and
-            ;; use this as buffer-index, save buffer-index to
-            ;; token-list-index connection
-            (let ((previous-token-list-index 0))
-              (when (and
-                     phps-mode-parser-position
-                     (< (car (car phps-mode-parser-position)) buffer-index))
-                (setq
-                 previous-token-list-index
-                 (car (cdr (car phps-mode-parser-position)))))
-
-              (let ((temp-token-list-index
-                     previous-token-list-index)
-                    (token-list-size
-                     (length
-                      phps-mode-parser-tokens))
-                    (continue t))
-                (while (and
-                        continue
-                        (<
-                         temp-token-list-index
-                         token-list-size))
-                  (let ((token
-                         (nth
-                          temp-token-list-index
-                          phps-mode-parser-tokens)))
-
-                    ;; When token starts at cursor we found correct index
-                    ;; Save it
-                    (when (= (car (cdr token)) buffer-index)
-                      (let ((token-type (car token)))
-                        (push
-                         (list
-                          buffer-index
-                          temp-token-list-index)
-                         phps-mode-parser-position)
-                        (unless (or
-                                 (equal token-type 'T_OPEN_TAG)
-                                 (equal token-type 'T_CLOSE_TAG)
-                                 (equal token-type 'T_DOC_COMMENT)
-                                 (equal token-type 'T_COMMENT))
-                          (setq
-                           token-list-index
-                           temp-token-list-index)
-                          (setq
-                           continue
-                           nil))))
-
-                    ;; When token starts after cursor, flag move of cursor
-                    ;; Save it
-                    (when (> (car (cdr token)) buffer-index)
-                      (let ((token-type (car token)))
-                        (push
-                         (list
-                          (car (cdr token))
-                          temp-token-list-index)
-                         phps-mode-parser-position)
-                        (unless (or
-                                 (equal token-type 'T_OPEN_TAG)
-                                 (equal token-type 'T_CLOSE_TAG)
-                                 (equal token-type 'T_DOC_COMMENT)
-                                 (equal token-type 'T_COMMENT))
-                          (setq-local
-                           phps-mode-parser-lex-analyzer--move-to-index-flag
-                           (car (cdr token)))
-                          (setq
-                           continue
-                           nil))))
-
-                    (setq
-                     temp-token-list-index
-                     (1+ temp-token-list-index))
-                    )))))
-
-          (when
-              token-list-index
-            (let ((token
-                   (nth
-                    token-list-index
-                    phps-mode-parser-tokens)))
-              (when (equal (car token) 'T_OPEN_TAG_WITH_ECHO)
-                (setf
-                 (car token)
-                 'T_ECHO))
-              token))))))
+                 temp-token-list-index
+                 (1+ temp-token-list-index))
+                )))))
+
+      (when
+          token-list-index
+        (let ((token
+               (nth
+                token-list-index
+                phps-mode-parser-tokens)))
+          (when (equal (car token) 'T_OPEN_TAG_WITH_ECHO)
+            (setf
+             (car token)
+             'T_ECHO))
+          token))))
   "The custom lex-analyzer.")
 
 (defvar
diff --git a/phps-mode-parser.el b/phps-mode-parser.el
index bbf3ca4..b9db0b6 100644
--- a/phps-mode-parser.el
+++ b/phps-mode-parser.el
@@ -103,176 +103,173 @@
 (defvar
   phps-mode-parser-lex-analyzer--function
   (lambda (buffer-index)
+    (let ((token-list-index))
+      (if (and
+           phps-mode-parser-position
+           (= (car (car phps-mode-parser-position)) buffer-index))
+          (progn
+            (setq
+             token-list-index
+             (car (cdr (car phps-mode-parser-position)))))
+
+        ;; Search from last requested index and forward until
+        ;; we find a token starting at or after buffer-index and
+        ;; use this as buffer-index, save buffer-index to
+        ;; token-list-index connection
+        (let ((previous-token-list-index 0))
+          (when (and
+                 phps-mode-parser-position
+                 (< (car (car phps-mode-parser-position)) buffer-index))
+            (setq
+             previous-token-list-index
+             (car (cdr (car phps-mode-parser-position)))))
+
+          (let ((temp-token-list-index
+                 previous-token-list-index)
+                (token-list-size
+                 (length
+                  phps-mode-parser-tokens))
+                (continue t))
+            (while (and
+                    continue
+                    (<
+                     temp-token-list-index
+                     token-list-size))
+              (let ((token
+                     (nth
+                      temp-token-list-index
+                      phps-mode-parser-tokens)))
+
+                ;; When token starts at cursor we found correct index
+                ;; Save it
+                (when (= (car (cdr token)) buffer-index)
+                  (let ((token-type (car token)))
+                    (push
+                     (list
+                      buffer-index
+                      temp-token-list-index)
+                     phps-mode-parser-position)
+                    (unless (or
+                             (equal token-type 'T_OPEN_TAG)
+                             (equal token-type 'T_CLOSE_TAG)
+                             (equal token-type 'T_DOC_COMMENT)
+                             (equal token-type 'T_COMMENT))
+                      (setq
+                       token-list-index
+                       temp-token-list-index)
+                      (setq
+                       continue
+                       nil))))
+
+                ;; When token starts after cursor, flag move of cursor
+                ;; Save it
+                (when (> (car (cdr token)) buffer-index)
+                  (let ((token-type (car token)))
+                    (push
+                     (list
+                      (car (cdr token))
+                      temp-token-list-index)
+                     phps-mode-parser-position)
+                    (unless (or
+                             (equal token-type 'T_OPEN_TAG)
+                             (equal token-type 'T_CLOSE_TAG)
+                             (equal token-type 'T_DOC_COMMENT)
+                             (equal token-type 'T_COMMENT))
+                      (setq-local
+                       phps-mode-parser-lex-analyzer--move-to-index-flag
+                       (car (cdr token)))
+                      (setq
+                       continue
+                       nil))))
 
-    ;; Create lexer buffer if none exists
-    (unless (get-buffer "*PHPs Lexer*")
-      (generate-new-buffer "*PHPs Lexer*")
-      (let ((old-buffer
-             (buffer-substring-no-properties
-              (point-min)
-              (point-max))))
-        (with-current-buffer "*PHPs Lexer*"
-          (insert old-buffer))))
-    
-    (with-current-buffer "*PHPs Lexer*"
-      (let ((token-list-index))
-        (if (and
-             phps-mode-parser-position
-             (= (car (car phps-mode-parser-position)) buffer-index))
-            (progn
-              (setq
-               token-list-index
-               (car (cdr (car phps-mode-parser-position)))))
-
-          ;; Search from last requested index and forward until
-          ;; we find a token starting at or after buffer-index and
-          ;; use this as buffer-index, save buffer-index to
-          ;; token-list-index connection
-          (let ((previous-token-list-index 0))
-            (when (and
-                   phps-mode-parser-position
-                   (< (car (car phps-mode-parser-position)) buffer-index))
-              (setq
-               previous-token-list-index
-               (car (cdr (car phps-mode-parser-position)))))
-
-            (let ((temp-token-list-index
-                   previous-token-list-index)
-                  (token-list-size
-                   (length
-                    phps-mode-parser-tokens))
-                  (continue t))
-              (while (and
-                      continue
-                      (<
-                       temp-token-list-index
-                       token-list-size))
-                (let ((token
-                       (nth
-                        temp-token-list-index
-                        phps-mode-parser-tokens)))
-
-                  ;; When token starts at cursor we found correct index
-                  ;; Save it
-                  (when (= (car (cdr token)) buffer-index)
-                    (let ((token-type (car token)))
-                      (push
-                       (list
-                        buffer-index
-                        temp-token-list-index)
-                       phps-mode-parser-position)
-                      (unless (or
-                               (equal token-type 'T_OPEN_TAG)
-                               (equal token-type 'T_CLOSE_TAG)
-                               (equal token-type 'T_DOC_COMMENT)
-                               (equal token-type 'T_COMMENT))
-                        (setq
-                         token-list-index
-                         temp-token-list-index)
-                        (setq
-                         continue
-                         nil))))
-
-                  ;; When token starts after cursor, flag move of cursor
-                  ;; Save it
-                  (when (> (car (cdr token)) buffer-index)
-                    (let ((token-type (car token)))
-                      (push
-                       (list
-                        (car (cdr token))
-                        temp-token-list-index)
-                       phps-mode-parser-position)
-                      (unless (or
-                               (equal token-type 'T_OPEN_TAG)
-                               (equal token-type 'T_CLOSE_TAG)
-                               (equal token-type 'T_DOC_COMMENT)
-                               (equal token-type 'T_COMMENT))
-                        (setq-local
-                         phps-mode-parser-lex-analyzer--move-to-index-flag
-                         (car (cdr token)))
-                        (setq
-                         continue
-                         nil))))
-
-                  (setq
-                   temp-token-list-index
-                   (1+ temp-token-list-index))
-                  )))))
-
-        (when
-            token-list-index
-          (let ((token
-                 (nth
-                  token-list-index
-                  phps-mode-parser-tokens)))
-            (when (equal (car token) 'T_OPEN_TAG_WITH_ECHO)
-              (setf
-               (car token)
-               'T_ECHO))
-            token)))))
+                (setq
+                 temp-token-list-index
+                 (1+ temp-token-list-index))
+                )))))
+
+      (when
+          token-list-index
+        (let ((token
+               (nth
+                token-list-index
+                phps-mode-parser-tokens)))
+          (when (equal (car token) 'T_OPEN_TAG_WITH_ECHO)
+            (setf
+             (car token)
+             'T_ECHO))
+          token))))
   "The lex-analyzer function.")
 
 (defvar
   phps-mode-parser-lex-analyzer--reset-function
   (lambda()
-    ;; Create lexer buffer if none exists
-    (unless (get-buffer "*PHPs Lexer*")
-      (generate-new-buffer "*PHPs Lexer*")
-      (let ((old-buffer
-             (buffer-substring-no-properties
-              (point-min)
-              (point-max))))
-        (with-current-buffer "*PHPs Lexer*"
-          (insert old-buffer))))
-
-    (with-current-buffer "*PHPs Lexer*"
-      ;; Unless we have lexed the buffer
-      (unless phps-mode-parser-tokens
-        (unless phps-mode-lexer--generated-tokens
-          ;; Reset lexer
-          (setq-local
-           phps-mode-lexer--generated-tokens
-           nil)
-          (setq-local
-           phps-mode-lexer--state
-           'ST_INITIAL)
-          (setq-local
-           phps-mode-lexer--states
-           nil)
-          (setq-local
-           phps-mode-lexer--state-stack
-           nil)
-          (setq-local
-           phps-mode-lexer--heredoc-label
-           nil)
-          (setq-local
-           phps-mode-lexer--heredoc-label-stack
-           nil)
-          (setq-local
-           phps-mode-lexer--nest-location-stack
-           nil)
-          (goto-char (point-min))
-
-          ;; Run lexer on entire buffer here
-          (let ((index (point))
-                (max-index (point-max)))
-            (while (< index max-index)
-              (phps-mode-lexer--re2c)
-              (setq
-               index
-               semantic-lex-end-point)
-              (goto-char index))))
+    (let ((generated-tokens-p)
+          (generated-tokens-list))
+
+      ;; Create lexer buffer if none exists
+      (unless (get-buffer "*PHPs Lexer*")
+        (generate-new-buffer "*PHPs Lexer*")
+        (let ((old-buffer
+               (buffer-substring-no-properties
+                (point-min)
+                (point-max))))
+          (with-current-buffer "*PHPs Lexer*"
+            (insert old-buffer))))
+
+      (with-current-buffer "*PHPs Lexer*"
+        ;; Unless we have lexed the buffer
+        (unless phps-mode-parser-tokens
+          (unless phps-mode-lexer--generated-tokens
+            ;; Reset lexer
+            (setq-local
+             phps-mode-lexer--generated-tokens
+             nil)
+            (setq-local
+             phps-mode-lexer--state
+             'ST_INITIAL)
+            (setq-local
+             phps-mode-lexer--states
+             nil)
+            (setq-local
+             phps-mode-lexer--state-stack
+             nil)
+            (setq-local
+             phps-mode-lexer--heredoc-label
+             nil)
+            (setq-local
+             phps-mode-lexer--heredoc-label-stack
+             nil)
+            (setq-local
+             phps-mode-lexer--nest-location-stack
+             nil)
+            (goto-char (point-min))
+
+            ;; Run lexer on entire buffer here
+            (let ((index (point))
+                  (max-index (point-max)))
+              (while (< index max-index)
+                (phps-mode-lexer--re2c)
+                (setq
+                 index
+                 semantic-lex-end-point)
+                (goto-char index))))
+          (setq
+           generated-tokens-p
+           t)
+          (setq
+           generated-tokens-list
+           (reverse
+            phps-mode-lexer--generated-tokens))))
+
+      (when generated-tokens-p
         (setq-local
          phps-mode-parser-tokens
-         (reverse
-          phps-mode-lexer--generated-tokens))
-
-        ;; Reset buffer-index to token-list-index connections
-        (setq-local
-         phps-mode-parser-position
-         nil)))
+         generated-tokens-list))
 
-    )
+      ;; Reset buffer-index to token-list-index connections
+      (setq-local
+       phps-mode-parser-position
+       nil)))
   "The lex-analyzer reset function.")
 
 



reply via email to

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