[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 552eada 264/405: Tuning of incremental logic
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 552eada 264/405: Tuning of incremental logic |
Date: |
Sat, 13 Jul 2019 10:00:29 -0400 (EDT) |
branch: externals/phps-mode
commit 552eadac92e2ef37f2d6cec53fd0a90b09c017b6
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Tuning of incremental logic
---
phps-mode-functions.el | 8 ++++++++
phps-mode-lexer.el | 29 +++++++++++------------------
phps-mode-test-integration.el | 17 +++++++----------
3 files changed, 26 insertions(+), 28 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 7b4b935..69d302e 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -48,6 +48,14 @@
;; TODO Add support for automatic parenthesis, bracket, square-bracket,
single-quote and double-quote encapsulations
+(defun phps-mode-functions-get-buffer-changes-start ()
+ "Get buffer change start."
+ phps-mode-functions-buffer-changes-start)
+
+(defun phps-mode-functions-reset-buffer-changes-start ()
+ "Reset buffer change start."
+ (setq phps-mode-functions-buffer-changes-start nil))
+
(defun phps-mode-functions-process-current-buffer ()
"Process current buffer, generate indentations and Imenu."
(unless phps-mode-functions-processed-buffer
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index 44c60c8..4aae63a 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -36,6 +36,9 @@
;;; Code:
+(autoload 'phps-mode-function-get-buffer-changes-start "phps-mode-functions")
+(autoload 'phps-mode-functions-reset-buffer-changes-start
"phps-mode-functions")
+
(require 'semantic)
(require 'semantic/lex)
@@ -1284,18 +1287,11 @@ ANY_CHAR'
phps-mode-functions-processed-buffer)
(setq phps-mode-functions-processed-buffer nil))
- ;; TODO Delete all overlays after point of change if it's incremental
-
;; Does lexer start from the beginning of buffer?
(when (and (eq start 1)
end)
(delete-all-overlays)
- ;; Rest buffer changes flag
- (when (and (boundp 'phps-mode-lexer-buffer-changes--start)
- phps-mode-lexer-buffer-changes--start)
- (setq phps-mode-lexer-buffer-changes--start nil))
-
(setq phps-mode-lexer-states nil)
(phps-mode-lexer-BEGIN phps-mode-lexer-ST_INITIAL)))
@@ -1351,16 +1347,16 @@ ANY_CHAR'
new-tokens))
(defun phps-mode-lexer-run-incremental ()
- "Run incremental lexer based on `phps-mode-lexer-buffer-changes-start'."
- (when (and (boundp 'phps-mode-functions-buffer-changes-start)
- phps-mode-functions-buffer-changes-start
+ "Run incremental lexer based on
`(phps-mode-functions-get-buffer-changes-start)'."
+ (when (and (phps-mode-functions-get-buffer-changes-start)
phps-mode-lexer-states)
(let ((state nil)
(state-stack nil)
(new-states '())
(states (nreverse phps-mode-lexer-states))
- (change-start phps-mode-functions-buffer-changes-start)
+ (change-start (phps-mode-functions-get-buffer-changes-start))
(previous-token-start nil)
+ (previous-token-end nil)
(tokens phps-mode-lexer-tokens))
;; (message "Looking for state to rewind to for %s in stack %s"
change-start states)
@@ -1374,6 +1370,7 @@ ANY_CHAR'
(setq state (nth 2 state-object))
(setq state-stack (nth 3 state-object))
(setq previous-token-start start)
+ (setq previous-token-end end)
(push state-object new-states))
(when (> start change-start)
(throw 'stop-iteration nil)))))
@@ -1386,13 +1383,13 @@ ANY_CHAR'
(catch 'stop-iteration
(dolist (token tokens)
(let ((start (car (cdr token))))
- (if (< start previous-token-start)
+ (if (< start previous-token-end)
(push token old-tokens)
(throw 'stop-iteration nil)))))
(setq old-tokens (nreverse old-tokens))
;; Delete all overlays from point of change to end of buffer
- (dolist (overlay (overlays-in previous-token-start (point-max)))
+ (dolist (overlay (overlays-in previous-token-end (point-max)))
(delete-overlay overlay))
(let* ((new-tokens (semantic-lex previous-token-start (point-max)))
@@ -1410,7 +1407,7 @@ ANY_CHAR'
))
;; (display-warning "phps-mode" (format "Found no state to rewind to
for %s in stack %s, buffer point max: %s" change-start states (point-max)))
(phps-mode-lexer-run)))
- (setq phps-mode-functions-buffer-changes-start nil)))
+ (phps-mode-functions-reset-buffer-changes-start)))
(define-lex phps-mode-lexer-tags-lexer
"Lexer that handles PHP buffers."
@@ -1430,14 +1427,10 @@ ANY_CHAR'
(defun phps-mode-lexer-init ()
"Initialize lexer."
-
(when (boundp 'phps-mode-syntax-table)
(setq semantic-lex-syntax-table phps-mode-syntax-table))
-
(setq semantic-lex-analyzer #'phps-mode-lexer-tags-lexer)
-
(add-hook 'semantic-lex-reset-functions #'phps-mode-lexer-setup)
-
(phps-mode-lexer-run))
(provide 'phps-mode-lexer)
diff --git a/phps-mode-test-integration.el b/phps-mode-test-integration.el
index 4d37fcb..a6fc0cc 100644
--- a/phps-mode-test-integration.el
+++ b/phps-mode-test-integration.el
@@ -33,7 +33,9 @@
(autoload 'phps-mode-functions-indent-line "phps-mode-functions")
(autoload 'phps-mode-functions-get-lines-indent "phps-mode-functions")
(autoload 'phps-mode-functions-get-imenu "phps-mode-functions")
+(autoload 'phps-mode-functions-get-buffer-changes-start "phps-mode-functions")
(autoload 'phps-mode-test-hash-to-list "phps-mode-test")
+(autoload 'phps-mode-lexer-get-tokens "phps-mode-lexer")
(autoload 'should "ert")
(defun phps-mode-test-integration-incremental ()
@@ -44,10 +46,8 @@
"Integration-test for regular PHP with namespaces, classes and functions"
;; Tokens
- (when (and (boundp 'phps-mode-lexer-tokens)
- phps-mode-lexer-tokens)
- ;; (message "Tokens %s" phps-mode-lexer-tokens)
- (should (equal phps-mode-lexer-tokens '((T_OPEN_TAG 1 . 7) (T_NAMESPACE 7
. 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) (T_STRING 41 . 48)
("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) (T_STRING 79 . 89) ("("
89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 118)
(T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144) ("}" 149
. 150) ("}" 151 . 152)))))
+ ;; (message "Tokens %s" phps-mode-lexer-tokens)
+ (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7)
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40)
(T_STRING 41 . 48) ("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78)
(T_STRING 79 . 89) ("(" 89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 .
118) (T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144)
("}" 149 . 150) ("}" 151 . 152))))
;; Indentation
(should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (2
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (1 0)) (11 (0 0)))
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))
@@ -60,17 +60,14 @@
(insert "\n\n public function myFunctionB()\n {\n
echo 'my second statement';\n }\n")
;; Verify stored point of change
- (when (boundp 'phps-mode-functions-buffer-changes-start)
- (should (equal phps-mode-functions-buffer-changes-start 144)))
+ (should (equal (phps-mode-functions-get-buffer-changes-start) 144))
;; Run incremental lexer
(phps-mode-lexer-run-incremental)
;; Tokens
- (when (and (boundp 'phps-mode-lexer-tokens)
- phps-mode-lexer-tokens)
- ;; (message "Tokens %s" phps-mode-lexer-tokens)
- (should (equal phps-mode-lexer-tokens '((T_OPEN_TAG 1 . 7) (T_NAMESPACE 7
. 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) (T_STRING 41 . 48)
("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) (T_STRING 79 . 89) ("("
89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 118)
(T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144)
(T_PUBLIC 154 . 160) (T_FUNCTION 161 . 169) (T_STRING 170 . 181) ("(" 181 .
182) (")" 182 . 183) ("{" 192 . 193) (T_ECHO 206 . 210 [...]
+ ;; (message "Tokens %s" (phps-mode-lexer-get-tokens))
+ (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7)
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40)
(T_STRING 41 . 48) ("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78)
(T_STRING 79 . 89) ("(" 89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 .
118) (T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) (";" 133 . 134)
("}" 143 . 144) (T_PUBLIC 154 . 160) (T_FUNCTION 161 . 169) (T_STRING 170 .
181) ("(" 181 . 182) (")" 182 . 183) ("{" 192 . 19 [...]
;; Indentation
;; (message "indent: %s" (phps-mode-test-hash-to-list
(phps-mode-functions-get-lines-indent)))
- [elpa] externals/phps-mode aa0c23d 263/405: Updated font-locks for token color syntax, (continued)
- [elpa] externals/phps-mode aa0c23d 263/405: Updated font-locks for token color syntax, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b86dd54 262/405: Indentation now supports new lexer token T_INLINE HTML, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2c8f28c 275/405: Added docstrings to variables, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c9f0254 271/405: Fixed some minor flycheck complains in lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 68ef657 280/405: Removed debugging output from unit tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 40bffbc 265/405: Added syntax coloring for [ )( ,, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9deb882 266/405: Added syntax coloring for ? ! < > :, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 969a4d1 278/405: Fixed syntax for coalesce assignment operator, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode bd08a00 277/405: Added unit test for COALESCING EQUAL token, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a49ce7d 272/405: Added TODO item for lexer to better match re2c, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 552eada 264/405: Tuning of incremental logic,
Stefan Monnier <=
- [elpa] externals/phps-mode 6cb1d5a 261/405: Added T_INLINE_HTML lexer token, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d6caab9 269/405: Added support for coalesce_equal token and made lexer structure more similar to re2c, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d51a2c4 276/405: Lexer grammar used same logic as PHP language scanner, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1e3537c 268/405: Re-factored lexer to be more similar to re2c, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9748853 267/405: Merged all lexer analysis into one to better match re2c lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode bfeaa74 273/405: Started with changing lexer syntax to be more alike re2c, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 73b8b4d 297/405: More work on concatenation and assignment indent, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 81c7179 293/405: Fixed indentation bug with assignment of square array in function argument, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 419a812 298/405: More work on debugging indentation with assignment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ed36115 288/405: Added TODO item for indentation, Stefan Monnier, 2019/07/13