[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode a724438 010/405: Handled lexing with empty si
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode a724438 010/405: Handled lexing with empty single and double quote string |
Date: |
Sat, 13 Jul 2019 09:59:29 -0400 (EDT) |
branch: externals/phps-mode
commit a7244384cf8b403235b7a1ed51888eadad7b1afa
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
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)))
- [elpa] branch externals/phps-mode created (now f5c2072), Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7d0cd36 002/405: Updated goals, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dd8d800 004/405: Using coloring overlay for comments as well, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c64b3b4 008/405: More work on lexer tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a724438 010/405: Handled lexing with empty single and double quote string,
Stefan Monnier <=
- [elpa] externals/phps-mode 5a6a96b 012/405: Added another test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b3a6308 015/405: Added hook for resetting lexer variables, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ce656a5 006/405: More general cleaning up, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f3205d5 011/405: Fixed lexing of basic tokens, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 31ca9d5 007/405: More cleaning up, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 79040dc 005/405: Some cleaning up, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 394f7ae 017/405: Fixed issue with empty strings before non-empty strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 41c4fbb 009/405: Lexer unit tests now working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode be078dc 020/405: Updated readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c4a8ca5 016/405: Free lexer tokens does not have properties anymore, Stefan Monnier, 2019/07/13