[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 2475734 018/405: Improved logic for single qu
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 2475734 018/405: Improved logic for single quoted strings |
Date: |
Sat, 13 Jul 2019 09:59:31 -0400 (EDT) |
branch: externals/phps-mode
commit 247573451cb3e96b0f7e2cdc2b6248c55881def9
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Improved logic for single quoted strings
---
phps-lexer.el | 47 ++++++++++++++++++++++++++++------------------
sample-php-files/class.php | 1 +
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/phps-lexer.el b/phps-lexer.el
index 1e5ce6f..58c704b 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -431,6 +431,24 @@
))
+(defun phps-modex/lex--get-next-unescaped (character)
+ "Find where next un-escaped CHARACTER comes, if none is found return nil."
+ ;; (message "phps-modex/lex--get-next-unescaped(%s)" character)
+ (let ((escaped nil)
+ (pos nil))
+ (while (and (not pos)
+ (< (point) (point-max)))
+ (progn
+ ;; (message "Setting forward one %s vs %s" (point) (point-max))
+ (forward-char)
+ (if (and (not escaped)
+ (looking-at-p character))
+ (setq pos (+ (point) 1))
+ (if (looking-at-p "\\\\")
+ (setq escaped (not escaped))
+ (setq escaped nil)))))
+ pos))
+
(define-lex-analyzer phps-mode/lex--ST_IN_SCRIPTING
"<ST_IN_SCRIPTING>"
(= phps-mode/STATE phps-mode/ST_IN_SCRIPTING)
@@ -825,25 +843,18 @@
(let* ((start (match-beginning 0))
(end (match-end 0))
(data (buffer-substring-no-properties start end))
- (found nil))
- (forward-char)
- ;; Handle the '' case
- (if (looking-at-p "'")
+ (found nil)
+ (un-escaped-end (phps-modex/lex--get-next-unescaped "'")))
+ (if un-escaped-end
(progn
- ;; (message "Empty single quoted string from %s to %s" start (+
start 2))
- (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start (+ start
2))
- (forward-char))
- (let ((string-start (search-forward-regexp "[^\\\\]'" nil t)))
- (if string-start
- (progn
- ;; (message "Single quoted string %s"
(buffer-substring-no-properties start string-start))
- (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))
- ))))))
+ ;; (message "Single quoted string %s"
(buffer-substring-no-properties start un-escaped-end))
+ (phps-mode/RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING start
un-escaped-end))
+ (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 "\"")
diff --git a/sample-php-files/class.php b/sample-php-files/class.php
index 7862e0b..3fa7bf4 100644
--- a/sample-php-files/class.php
+++ b/sample-php-files/class.php
@@ -25,6 +25,7 @@ class MyClass {
$this->var = '';
}
$this->var = 'abc';
+ $this->var = '\\';
}
}
- [elpa] externals/phps-mode ce656a5 006/405: More general cleaning up, (continued)
- [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
- [elpa] externals/phps-mode 8ed0716 022/405: Started with unit tests for getting point lexer data, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode abcfd01 021/405: Started with function to gather current point data, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2475734 018/405: Improved logic for single quoted strings,
Stefan Monnier <=
- [elpa] externals/phps-mode 795053b 013/405: Lexer unit tests using start and ends as well, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 95e749e 028/405: Started with indentation function, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3202213 025/405: Added another unit test for lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode bf59f0a 023/405: More unit tests for getting point lex information, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode de771b5 019/405: Added more unit tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e3a060a 026/405: Handles script breaking single-line comments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7fa9fdb 024/405: More unit tests for lexing comments and doc comments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 64a3ca8 014/405: Modified start and end for single and double quoted strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3ea8c64 003/405: Added license, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f6e3ce4 027/405: Added another test for comments, Stefan Monnier, 2019/07/13