branch: externals/phps-mode commit c040358b555a1e157b055da5c7a1b7e08d2718ae Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Point lexer token information makes more sense --- phps-lexer.el | 28 ++++++++++++++++++++-------- phps-test-lexer.el | 18 ++++++++++++++---- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/phps-lexer.el b/phps-lexer.el index 39d745e..42ab914 100644 --- a/phps-lexer.el +++ b/phps-lexer.el @@ -1268,24 +1268,33 @@ ANY_CHAR' (start-brace-level 0) (start-parenthesis-level 0) (start-inline-function-level 0) - (start-token-number -1) + (start-token-number nil) (end-in-scripting nil) (end-brace-level 0) (end-parenthesis-level 0) (end-inline-function-level 0) - (end-token-number -1)) + (end-token-number nil) + (found-line-tokens nil)) (catch 'stop-iteration (dolist (item phps-mode/lexer-tokens) (let ((token (car item)) - (start (car (cdr item)))) + (start (car (cdr item))) + (end (cdr (cdr item)))) ;; (message "Token: %s Start: %s End: %s Item: %s" token start end item) (when (> start line-end) ;; (message "Stopping iteration at: %s %s" start position) (throw 'stop-iteration nil)) + (when (and (not found-line-tokens) + (>= start position) + (<= end line-end)) + (setq found-line-tokens t)) + ;; When start of token is equal or less to current point - (when (< start position) + (when (<= 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)) @@ -1298,7 +1307,9 @@ ANY_CHAR' (_))) ;; When start of token is equal or less to end of curent line - (when (< start line-end) + (when (<= start line-end) + (when (null end-token-number) + (setq end-token-number -1)) (setq end-token-number (+ end-token-number 1)) (pcase token ('T_OPEN_TAG (setq end-in-scripting t)) @@ -1311,10 +1322,11 @@ ANY_CHAR' (_))) ))) - (let ((data (list (list start-in-scripting start-brace-level start-parenthesis-level start-inline-function-level start-token-number) (list end-in-scripting end-brace-level end-parenthesis-level end-inline-function-level end-token-number)))) + (let ((data (list (list start-in-scripting start-brace-level start-parenthesis-level start-inline-function-level nil) (list end-in-scripting end-brace-level end-parenthesis-level end-inline-function-level nil)))) + (when found-line-tokens + (setq data (list (list start-in-scripting start-brace-level start-parenthesis-level start-inline-function-level start-token-number) (list end-in-scripting end-brace-level end-parenthesis-level end-inline-function-level end-token-number)))) ;; (message "data: %s" data) - data) - ))) + data)))) (defun phps-mode/lex--SETUP (start end) "Just prepare other lexers for lexing region START to END." diff --git a/phps-test-lexer.el b/phps-test-lexer.el index 0897a08..8eb8ed3 100644 --- a/phps-test-lexer.el +++ b/phps-test-lexer.el @@ -279,17 +279,27 @@ (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 -1) (list nil 0 0 0 5)) (phps-mode/lexer-get-point-data)))) + (should (equal (list (list nil 0 0 0 nil) (list nil 0 0 0 5)) (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) (list nil 0 0 0 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) (list nil 0 0 0 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 -1) (list nil 0 0 0 5)) (phps-mode/lexer-get-point-data)))) + (should (equal (list (list nil 0 0 0 nil) (list nil 0 0 0 5)) (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 -1) (list nil 0 0 0 5)) (phps-mode/lexer-get-point-data)))) + (should (equal (list (list nil 0 0 0 nil) (list nil 0 0 0 5)) (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>" @@ -311,7 +321,7 @@ "<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 -1) (list nil 0 0 0 17)) (phps-mode/lexer-get-point-data)))) + (should (equal (list (list nil 0 0 0 nil) (list nil 0 0 0 17)) (phps-mode/lexer-get-point-data)))) )