branch: externals/phps-mode commit dd80d2797a53c35a53f0412bf10d2483b514571b Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Started work on detecting doc comment blocks --- phps-lexer.el | 15 +++++++++++---- phps-test-lexer.el | 26 +++++++++++++++----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/phps-lexer.el b/phps-lexer.el index 387f306..bb4c98f 100644 --- a/phps-lexer.el +++ b/phps-lexer.el @@ -1271,11 +1271,13 @@ ANY_CHAR' (start-parenthesis-level 0) (start-inline-function-level 0) (start-token-number nil) + (start-in-doc-comment nil) (end-in-scripting nil) (end-brace-level 0) (end-parenthesis-level 0) (end-inline-function-level 0) (end-token-number nil) + (end-in-doc-comment nil) (found-line-tokens nil)) (catch 'stop-iteration (dolist (item phps-mode/lexer-tokens) @@ -1293,15 +1295,17 @@ ANY_CHAR' (<= end line-end)) (setq found-line-tokens t)) - ;; When start of token is equal or less to current point + ;; When end of token is equal or less to current point (when (<= end position) (when (null start-token-number) (setq start-token-number -1)) (setq start-token-number (+ start-token-number 1)) + (setq start-in-doc-comment nil) (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 t)) ("}" (setq start-brace-level (- start-brace-level 1))) ("{" (setq start-brace-level (+ start-brace-level 1))) ("(" (setq start-parenthesis-level (+ start-parenthesis-level 1))) @@ -1313,10 +1317,12 @@ ANY_CHAR' (when (null end-token-number) (setq end-token-number -1)) (setq end-token-number (+ end-token-number 1)) + (setq end-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 end-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))) @@ -1324,9 +1330,10 @@ ANY_CHAR' (_))) ))) - (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)))) + (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 start-in-doc-comment) (list end-in-scripting end-brace-level end-parenthesis-level end-inline-function-level end-token-number end-in-doc-comment)))) ;; (message "data: %s" data) data)))) diff --git a/phps-test-lexer.el b/phps-test-lexer.el index 8eb8ed3..1bafd80 100644 --- a/phps-test-lexer.el +++ b/phps-test-lexer.el @@ -274,54 +274,58 @@ (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) (list t 1 0 0 6)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 5)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 nil)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 nil)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 5)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 5)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 17)) (phps-mode/lexer-get-point-data)))) + (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) (list t 2 0 0 13)) (phps-mode/lexer-get-point-data)))) + (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) (list t 1 0 0 14)) (phps-mode/lexer-get-point-data)))) + (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) (list nil 0 0 0 17)) (phps-mode/lexer-get-point-data)))) + (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)))) )