[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode e6a8944 241/405: Started work on a lexer bug
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode e6a8944 241/405: Started work on a lexer bug with expressions inside double quoted strings |
Date: |
Sat, 13 Jul 2019 10:00:23 -0400 (EDT) |
branch: externals/phps-mode
commit e6a89441947ce8143fd44940f9701c1fd9924228
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
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
)
- [elpa] externals/phps-mode b2338cd 223/405: All tests for indentation passes, (continued)
- [elpa] externals/phps-mode b2338cd 223/405: All tests for indentation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a4b98e 215/405: More work on algorithm description, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9031c3a 211/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6105e5d 226/405: Added a new failing test for indetation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5f445cd 229/405: Fixed indentation for while expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode eb0ee5e 236/405: Updated README with imenu-support, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 811c499 220/405: New algorithm now works for switch, case syntax, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d2e5a03 228/405: Updated indentation algorithm document and README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1aa0f90 238/405: Typo in README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode da1cfd5 231/405: Adding failing lexer test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e6a8944 241/405: Started work on a lexer bug with expressions inside double quoted strings,
Stefan Monnier <=
- [elpa] externals/phps-mode 0c49d6d 243/405: Removed debugging output, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 95ac15a 245/405: Imenu index now handles class extends and implements, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 67233ef 213/405: Fixed indent algorithm for multi-line strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 36a4b64 222/405: Added lost test for token-less lines again, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 70f2d46 242/405: Fixed lexer issue with multiple expressions inside double-quoted string, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0286660 224/405: Indentation passes new tests for concatenated strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f05d40a 230/405: Tests for lexer passes again after close_tag modification, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1bc5713 227/405: New tests for concatenation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c71a97d 178/405: Started on refactored indentation calculation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8bb3918 249/405: Clean-up of unit test logging, Stefan Monnier, 2019/07/13