branch: externals/phps-mode
commit e6a89441947ce8143fd44940f9701c1fd9924228
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Started work on a lexer bug with expressions inside double quoted strings
---
phps-mode-lexer.el | 28 +++++++++++++++++++---------
phps-mode-test-lexer.el | 7 +++++++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index 0581bd4..b894087 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -721,9 +721,10 @@
((looking-at "}")
(when phps-mode-lexer-state_stack
- ;; (message "State stack %s" phps-mode-lexer-state_stack)
- ;; (message "popping state from } %s" (length
phps-mode-lexer-state_stack))
- (phps-mode-lexer-yy_pop_state))
+ (message "State stack %s" phps-mode-lexer-state_stack)
+ (message "popping state from } %s at %s-%s" (length
phps-mode-lexer-state_stack) (match-beginning 0) (match-end 0))
+ (phps-mode-lexer-yy_pop_state)
+ (message "New state: %s" phps-mode-lexer-STATE))
(phps-mode-lexer-RETURN_TOKEN "}" (match-beginning 0) (match-end 0)))
((looking-at phps-mode-lexer-BNUM)
@@ -996,11 +997,12 @@
((looking-at "{\\$")
(phps-mode-lexer-yy_push_state phps-mode-lexer-ST_IN_SCRIPTING)
+ (message "Starting ST_IN_SCRIPTING from double-quoted string at %s-%s"
(match-beginning 0) (- (match-end 0) 1))
(phps-mode-lexer-RETURN_TOKEN 'T_CURLY_OPEN (match-beginning 0) (-
(match-end 0) 1)))
((looking-at "[\"]")
(phps-mode-lexer-BEGIN phps-mode-lexer-ST_IN_SCRIPTING)
- ;; (message "Ended double-quote at %s" (match-beginning 0))
+ (message "Ended double-quote at %s" (match-beginning 0))
(phps-mode-lexer-RETURN_TOKEN "\"" (match-beginning 0) (match-end 0)))
((looking-at phps-mode-lexer-ANY_CHAR)
@@ -1010,16 +1012,23 @@
(let* ((end (- (match-end 0) 1))
(double-quoted-string (buffer-substring-no-properties start
end)))
;; Do we find variable inside quote?
- (if (or (string-match (concat "\\$" phps-mode-lexer-LABEL)
double-quoted-string)
- (string-match (concat "\\${" phps-mode-lexer-LABEL)
double-quoted-string)
- (string-match (concat "{\\$" phps-mode-lexer-LABEL)
double-quoted-string))
+ (if (or (string-match (concat "\\${" phps-mode-lexer-LABEL)
double-quoted-string)
+ (string-match (concat "{\\$" phps-mode-lexer-LABEL)
double-quoted-string)
+ (string-match (concat "\\$" phps-mode-lexer-LABEL)
double-quoted-string))
(progn
(let ((variable-start (+ start (match-beginning 0))))
+
+ (when (or (string-match (concat "\\${"
phps-mode-lexer-LABEL) double-quoted-string)
+ (string-match (concat "{\\$"
phps-mode-lexer-LABEL) double-quoted-string))
+ (setq variable-start (1- variable-start))
+ (message "Decreased index with one"))
+
+ (message "Found starting expression inside double-quoted
string at: %s %s" start variable-start)
(phps-mode-lexer-RETURN_TOKEN
'T_CONSTANT_ENCAPSED_STRING start variable-start)
))
(progn
(phps-mode-lexer-RETURN_TOKEN 'T_CONSTANT_ENCAPSED_STRING
start end)
- ;; (message "Found end of quote at %s-%s, moving ahead after
'%s'" start end (buffer-substring-no-properties start end))
+ (message "Found end of quote at %s-%s, moving ahead after
'%s'" start end (buffer-substring-no-properties start end))
)))
(progn
;; "Found no end of double-quoted region
@@ -1180,7 +1189,8 @@ ANY_CHAR'
((looking-at (concat phps-mode-lexer-LABEL "[\\[}]"))
(let ((start (match-beginning 0))
- (end (- (match-end 0) 1)))
+ (end (- (match-end 0) 1)))
+ (message "Stopped here")
(phps-mode-lexer-yy_pop_state)
(phps-mode-lexer-yy_push_state phps-mode-lexer-ST_IN_SCRIPTING)
(phps-mode-lexer-RETURN_TOKEN 'T_STRING_VARNAME start end)))
diff --git a/phps-mode-test-lexer.el b/phps-mode-test-lexer.el
index 7c41d7e..3292197 100644
--- a/phps-mode-test-lexer.el
+++ b/phps-mode-test-lexer.el
@@ -268,6 +268,13 @@
(should (equal phps-mode-lexer-tokens
'((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 12) (T_OBJECT_OPERATOR
12 . 14) (T_STRING 14 . 21) ("(" 21 . 22) ("\"" 22 . 23)
(T_ENCAPSED_AND_WHITESPACE 23 . 47) (T_VARIABLE 47 . 52) (T_OBJECT_OPERATOR 52
. 54) (T_STRING 54 . 59) (T_CONSTANT_ENCAPSED_STRING 59 . 72) ("\"" 72 . 73)
("." 73 . 74) (T_VARIABLE 74 . 77) ("." 77 . 78) (T_CONSTANT_ENCAPSED_STRING 78
. 81) (")" 81 . 82) (";" 82 . 83) (";" 84 . 86) (T_CLOSE_TAG 84 . 86)))))
+ (phps-mode-test-with-buffer
+ "<?php $this->add($option['style']['selectors'], array('background' =>
\"{$value['color']} url('{$value['image']}')\"));"
+ "Complex tokens with tokens inside double-quoted string"
+ ;; (message "Tokens 2: %s" phps-mode-lexer-tokens)
+ (should (equal phps-mode-lexer-tokens
+ '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 12) (T_OBJECT_OPERATOR
12 . 14) (T_STRING 14 . 21) ("(" 21 . 22) ("\"" 22 . 23)
(T_ENCAPSED_AND_WHITESPACE 23 . 47) (T_VARIABLE 47 . 52) (T_OBJECT_OPERATOR 52
. 54) (T_STRING 54 . 59) (T_CONSTANT_ENCAPSED_STRING 59 . 72) ("\"" 72 . 73)
("." 73 . 74) (T_VARIABLE 74 . 77) ("." 77 . 78) (T_CONSTANT_ENCAPSED_STRING 78
. 81) (")" 81 . 82) (";" 82 . 83) (";" 84 . 86) (T_CLOSE_TAG 84 . 86)))))
+
;; TODO Test object properties inside heredoc, nowdocs strings
)