branch: externals/phps-mode commit 70f2d4694a59aa487886aa0dd4ce4048391c0c83 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Fixed lexer issue with multiple expressions inside double-quoted string --- phps-mode-lexer.el | 27 +++++++++++---------------- phps-mode-test-lexer.el | 4 ++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el index b894087..9733cc5 100644 --- a/phps-mode-lexer.el +++ b/phps-mode-lexer.el @@ -148,10 +148,10 @@ "Characters not starting a label.") (defvar phps-mode-lexer-WHITESPACE "[ \n\r\t]+" - "Whitespace.") + "White-space.") (defvar phps-mode-lexer-TABS_AND_SPACES "[ \t]*" - "Tabs and whitespaces.") + "Tabs and white-spaces.") (defvar phps-mode-lexer-TOKENS "[][;\\:,\.()|^&+-/*=%!~\\$<>?@]" "Tokens.") @@ -176,14 +176,13 @@ (defun phps-mode-lexer-yy_push_state (new-state) "Add NEW-STATE to stack and then begin state." (push phps-mode-lexer-STATE phps-mode-lexer-state_stack) - ;; (message "Added state %s to stack" old-state) + ;; (message "Added state %s to stack begun state %s" phps-mode-lexer-STATE new-state) (phps-mode-lexer-BEGIN new-state)) (defun phps-mode-lexer-yy_pop_state () "Pop current state from stack." (let ((old-state (pop phps-mode-lexer-state_stack))) ;; (message "Going back to poppped state %s" old-state) - ;; (message "Ended state %s, going back to %s" old-state new-state) (if old-state (phps-mode-lexer-BEGIN old-state) (display-warning "phps-mode" "PHPs Lexer Error - Going back to nil?")) @@ -721,10 +720,11 @@ ((looking-at "}") (when phps-mode-lexer-state_stack - (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)) + ;; (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)) + ;; (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) @@ -997,12 +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)) + ;; (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) @@ -1018,17 +1018,12 @@ (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) + ;; (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 diff --git a/phps-mode-test-lexer.el b/phps-mode-test-lexer.el index 3292197..685c954 100644 --- a/phps-mode-test-lexer.el +++ b/phps-mode-test-lexer.el @@ -271,9 +271,9 @@ (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) + (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))))) + '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 12) (T_OBJECT_OPERATOR 12 . 14) (T_STRING 14 . 17) ("(" 17 . 18) (T_VARIABLE 18 . 25) ("[" 25 . 26) (T_CONSTANT_ENCAPSED_STRING 26 . 33) ("]" 33 . 34) ("[" 34 . 35) (T_CONSTANT_ENCAPSED_STRING 35 . 46) ("]" 46 . 47) ("," 47 . 48) (T_ARRAY 49 . 54) ("(" 54 . 55) (T_CONSTANT_ENCAPSED_STRING 55 . 67) (T_DOUBLE_ARROW 68 . 70) ("\"" 71 . 72) (T_ENCAPSED_AND_WHITESPACE 72 . 72) (T_CURLY_OPEN 72 . 73) (T_VARIABLE 73 . 79) ("[" 79 . 80) (T_C [...] ;; TODO Test object properties inside heredoc, nowdocs strings