branch: externals/phps-mode commit a7244384cf8b403235b7a1ed51888eadad7b1afa Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Handled lexing with empty single and double quote string --- phps-lexer.el | 39 ++++++++++++++++++++++----------------- phps-test-lexer.el | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/phps-lexer.el b/phps-lexer.el index 2f104fc..af9db86 100644 --- a/phps-lexer.el +++ b/phps-lexer.el @@ -831,13 +831,17 @@ (if string-start (progn ;; (message "Single quoted string %s" (buffer-substring start string-start)) - (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ string-start 1))) + (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start string-start)) (progn - ;; Unclosed single quotes - ;; (message "Single quoted string never ends..") - (phps-mode/RETURN_TOKEN 'T_ENCAPSED_AND_WHITESPACE start (point-max)) - (phps-mode/MOVE_FORWARD (point-max)) - ))))) + ;; Handle the '' case + (if (looking-at-p "'") + (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ end 1)) + (progn + ;; Unclosed single quotes + (message "Single quoted string never ends..") + (phps-mode/RETURN_TOKEN 'T_ENCAPSED_AND_WHITESPACE start (point-max)) + (phps-mode/MOVE_FORWARD (point-max)) + ))))))) ;; Double quoted string ((looking-at "\"") @@ -862,18 +866,19 @@ (let ((double-quoted-string (buffer-substring start (+ string-start 2)))) ;; (message "Double quoted string: %s" double-quoted-string) (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ string-start 2)))) - (progn - ;; (message "Found variable after '%s'" (buffer-substring start (point))) - (phps-mode/BEGIN phps-mode/ST_DOUBLE_QUOTES) - (phps-mode/RETURN_TOKEN "\"" start (+ start 1)) - (phps-mode/RETURN_TOKEN 'T_ENCAPSED_AND_WHITESPACE (+ start 1) string-start) - ) - )) + (progn + ;; (message "Found variable after '%s'" (buffer-substring start (point))) + (phps-mode/BEGIN phps-mode/ST_DOUBLE_QUOTES) + (phps-mode/RETURN_TOKEN "\"" start (+ start 1)) + (phps-mode/RETURN_TOKEN 'T_ENCAPSED_AND_WHITESPACE (+ start 1) string-start)))) (progn - ;; (message "Found no ending quote, skipping to end") - (phps-mode/RETURN_TOKEN 'T_ERROR start (point-max)) - (phps-mode/MOVE_FORWARD (point-max)) - ))))) + ;; Handle the "" case + (if (looking-at-p "\"") + (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ end 1)) + (progn + ;; (message "Found no ending quote, skipping to end") + (phps-mode/RETURN_TOKEN 'T_ERROR start (point-max)) + (phps-mode/MOVE_FORWARD (point-max))))))))) ((looking-at "[`]") ;; (message "Begun backquote at %s-%s" (match-beginning 0) (match-end 0)) diff --git a/phps-test-lexer.el b/phps-test-lexer.el index 314d47f..efdb9af 100644 --- a/phps-test-lexer.el +++ b/phps-test-lexer.el @@ -100,6 +100,31 @@ "Run test for simple tokens." (phps-mode/with-test-buffer + "<?php echo $var = array('');" + (let* ((tokens phps-mode/lexer-tokens) + (string-tokens (phps-mode/token-stream-to-string tokens))) + (should (equal string-tokens " T_OPEN_TAG T_ECHO T_VARIABLE = T_ARRAY ( T_CONSTANT_ENCAPSED_STRING ) ;")))) + + (phps-mode/with-test-buffer + "<?php echo $var = array(\"\");" + (let* ((tokens phps-mode/lexer-tokens) + (string-tokens (phps-mode/token-stream-to-string tokens))) + (should (equal string-tokens " T_OPEN_TAG T_ECHO T_VARIABLE = T_ARRAY ( T_CONSTANT_ENCAPSED_STRING ) ;")))) + + (phps-mode/with-test-buffer + "<?php echo $var = array('abc' => '123');" + (let* ((tokens phps-mode/lexer-tokens) + (string-tokens (phps-mode/token-stream-to-string tokens))) + (should (equal string-tokens " T_OPEN_TAG T_ECHO T_VARIABLE = T_ARRAY ( T_CONSTANT_ENCAPSED_STRING T_DOUBLE_ARROW T_CONSTANT_ENCAPSED_STRING ) ;")))) + + ;; TODO Fix this + (phps-mode/with-test-buffer + "<?php echo isset($backtrace[1]['file']) ? 'yes' : 'no'; " + (let* ((tokens phps-mode/lexer-tokens) + (string-tokens (phps-mode/token-stream-to-string tokens))) + (should (equal string-tokens " T_OPEN_TAG T_ECHO T_ISSET ( T_VARIABLE TODO HERE")))) + + (phps-mode/with-test-buffer "<?php $var EXIT die function return yield from yield try catch finally throw if elseif endif else while endwhile do for endfor foreach endforeach declare enddeclare instanceof as switch endswitch case default break continue goto echo print class interface trait extends implements :: \\ ... ?? new clone var (int) (integer) (real) (double) (float) (string) (binary) (array) (object) (boolean) (bool) (unset) eval include include_once require require_once namespace use insteadof global is [...] (let* ((tokens phps-mode/lexer-tokens) (string-tokens (phps-mode/token-stream-to-string tokens)))