branch: externals/phps-mode commit 2b167f3393e6e694f284e493b5df9721edc19b8a Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Fixes for parsing start and end --- phps-mode-parser.el | 39 ++++++++++++++++++++++++++++++--------- test/phps-mode-test-parser.el | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/phps-mode-parser.el b/phps-mode-parser.el index 2471a8c..19f2430 100644 --- a/phps-mode-parser.el +++ b/phps-mode-parser.el @@ -72,25 +72,46 @@ (phps-mode-lexer--re2c) (let ((first (car (nreverse phps-mode-lexer--generated-new-tokens)))) - (when (and - (not first) - (not (equal index semantic-lex-end-point))) + (message "first: %S" first) + + (cond + + ;; Lexer has moved forward - lex again + ((and + (not first) + (not (equal index semantic-lex-end-point))) (setq phps-mode-parser-lex-analyzer--index semantic-lex-end-point) (setq first - (funcall phps-mode-parser-lex-analyzer--function phps-mode-parser-lex-analyzer--index))) - - (when (or - (equal (car first) 'T_OPEN_TAG) - (equal (car first) 'T_OPEN_TAG_WITH_ECHO)) + (funcall + phps-mode-parser-lex-analyzer--function + phps-mode-parser-lex-analyzer--index))) + + ;; Skip open and close tag + ((or + (equal (car first) 'T_OPEN_TAG) + (equal (car first) 'T_CLOSE_TAG)) (setq phps-mode-parser-lex-analyzer--index (cdr (cdr first))) (setq first - (funcall phps-mode-parser-lex-analyzer--function phps-mode-parser-lex-analyzer--index))) + (funcall + phps-mode-parser-lex-analyzer--function + phps-mode-parser-lex-analyzer--index))) + + ;; Open tag with echo is replaced with echo + ((equal (car first) 'T_OPEN_TAG_WITH_ECHO) + (setf + (car first) + 'T_ECHO) + (setq + phps-mode-parser-lex-analyzer--index + (cdr (cdr first)))) + + ) first)))) "The lex-analyzer function.") diff --git a/test/phps-mode-test-parser.el b/test/phps-mode-test-parser.el index dc3f65a..f219182 100644 --- a/test/phps-mode-test-parser.el +++ b/test/phps-mode-test-parser.el @@ -78,6 +78,25 @@ '(80 459 466 411 333 332 154 102 79) (phps-mode-parser-parse))))) +(phps-mode-test-parser--buffer-contentes + "<? echo 'hello'; ?>" + "Basic echo test 2 with short open tag" + (lambda() + (should + (equal + '(80 459 466 411 333 332 154 102 79) + (phps-mode-parser-parse))))) + + (phps-mode-test-parser--buffer-contentes + "<?= 'hello';" + "Basic echo test 3 with open tag with echo" + (lambda() + (should + (equal + '(80 459 466 411 156 102 79) + (phps-mode-parser-parse))))) + + (message "\n-- Ran all tests for parser. --")) (phps-mode-test-parser)