emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 970cd47: Improved lexing of variables with of


From: Christian Johansson
Subject: [elpa] externals/phps-mode 970cd47: Improved lexing of variables with offset in double quoted strings
Date: Tue, 15 Sep 2020 06:14:23 -0400 (EDT)

branch: externals/phps-mode
commit 970cd47da808fe12d5162dff2b8b5ec7c79ee723
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Improved lexing of variables with offset in double quoted strings
---
 Makefile                                    |  2 +-
 phps-mode-lex-analyzer.el                   | 24 +++++++++++++++++++-----
 phps-mode-lexer.el                          |  3 ++-
 test/phps-mode-test.el => phps-mode-test.el |  0
 phps-mode.el                                |  4 ++--
 test/phps-mode-test-lex-analyzer.el         |  5 +++++
 test/phps-mode-test-lexer.el                | 18 +++++++++++++-----
 7 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 4500e66..2a6e1ee 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ ifdef emacs
 endif
 EMACS_CMD := $(EMACS) -Q -batch -L . -L test/
 
-EL  := admin/phps-mode-automation.el phps-mode-flymake.el 
phps-mode-lex-analyzer.el phps-mode-lexer.el phps-mode-macros.el 
phps-mode-syntax-table.el  phps-mode-parser-grammar-macro.el phps-mode.el 
test/phps-mode-test.el test/phps-mode-test-lex-analyzer.el 
test/phps-mode-test-integration.el test/phps-mode-test-lexer.el 
test/phps-mode-test-parser.el test/phps-mode-test-syntax-table.el
+EL  := admin/phps-mode-automation.el phps-mode-flymake.el 
phps-mode-lex-analyzer.el phps-mode-lexer.el phps-mode-macros.el 
phps-mode-syntax-table.el  phps-mode-parser-grammar-macro.el phps-mode.el 
phps-mode-test.el test/phps-mode-test-lex-analyzer.el 
test/phps-mode-test-integration.el test/phps-mode-test-lexer.el 
test/phps-mode-test-parser.el test/phps-mode-test-syntax-table.el
 ELC := $(EL:.el=.elc)
 
 .PHONY: clean
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index 79d02df..5f23658 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -1501,10 +1501,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                 ;; Keep track of square bracket level
                 (when (string= token "[")
                   (setq square-bracket-level (1+ square-bracket-level)))
-                (when (and
-                       (string= token "]")
-                       (not in-double-quotes))
-                  ;; You can have stuff like this $var = "abc $b[test]"; and 
only the closing square bracket will be tokenized
+                (when (string= token "]")
                   (setq square-bracket-level (1- square-bracket-level))
                   (when first-token-on-line
                     (setq first-token-is-nesting-decrease t)))
@@ -1615,9 +1612,13 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                 (when (or (equal token 'T_CURLY_OPEN)
                           (equal token 'T_DOLLAR_OPEN_CURLY_BRACES)
                           (string= token "{"))
-                  (setq curly-bracket-level (1+ curly-bracket-level)))
+                  (setq curly-bracket-level (1+ curly-bracket-level))
+                  (phps-mode-debug-message
+                   (message "New-curly-bracket-level: %s" 
curly-bracket-level)))
                 (when (string= token "}")
                   (setq curly-bracket-level (1- curly-bracket-level))
+                  (phps-mode-debug-message
+                   (message "New-curly-bracket-level: %s" curly-bracket-level))
 
                   (when (and switch-curly-stack
                              (= (1+ curly-bracket-level) (car 
switch-curly-stack)))
@@ -1976,6 +1977,19 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                   in-return-level
                   in-object-operator-level))
 
+                (phps-mode-debug-message
+                 (message "Nesting-end: %s from (+ %s %s %s %s %s %s %s %s %s)"
+                          nesting-end
+                          round-bracket-level
+                          square-bracket-level
+                          curly-bracket-level
+                          alternative-control-structure-level
+                          in-assignment-level
+                          in-class-declaration-level
+                          in-concatenation-level
+                          in-return-level
+                          in-object-operator-level))
+
                 ;; Keep track of whether we are inside a HEREDOC or NOWDOC
                 (when (equal token 'T_START_HEREDOC)
                   (setq in-heredoc t)
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index c1990b4..d2ba03a 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -1047,7 +1047,8 @@
               phps-mode-lexer--LABEL
               "\\[")))
        (phps-mode-lexer--yy_push_state 'ST_VAR_OFFSET)
-       (phps-mode-lexer--RETURN_TOKEN 'T_VARIABLE (match-beginning 0) 
(match-end 0)))
+       (forward-char -1)
+       (phps-mode-lexer--RETURN_TOKEN 'T_VARIABLE (match-beginning 0) (- 
(match-end 0) 1)))
 
       (phps-mode-lexer--match-macro
        (and (or ST_IN_SCRIPTING ST_DOUBLE_QUOTES ST_HEREDOC ST_BACKQUOTE 
ST_VAR_OFFSET)
diff --git a/test/phps-mode-test.el b/phps-mode-test.el
similarity index 100%
rename from test/phps-mode-test.el
rename to phps-mode-test.el
diff --git a/phps-mode.el b/phps-mode.el
index 0570936..d3ec1ff 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -5,8 +5,8 @@
 ;; Author: Christian Johansson <christian@cvj.se>
 ;; Maintainer: Christian Johansson <christian@cvj.se>
 ;; Created: 3 Mar 2018
-;; Modified: 14 Sep 2020
-;; Version: 0.3.55
+;; Modified: 15 Sep 2020
+;; Version: 0.3.56
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
diff --git a/test/phps-mode-test-lex-analyzer.el 
b/test/phps-mode-test-lex-analyzer.el
index 0b8305d..032e36b 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -858,6 +858,11 @@
    ;; (message "Indent: %s" (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-lines-indent)))
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (3 0)) (6 (3 
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (3 0)) (11 (1 0)) (12 (1 0)) (13 (2 0)) 
(14 (2 0)) (15 (1 0)) (16 (0 0))) (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-lines-indent)))))
 
+  (phps-mode-test--with-buffer
+   "<?php\n$product_path = \"${filename[0]}/${filename[1]}/\";\necho 'here';\n"
+   "Double-quoted string with multiple indexed variables in it"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0))) 
(phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-lines-indent)))))
+
   )
 
 (defun phps-mode-test-lex-analyzer--indent-line ()
diff --git a/test/phps-mode-test-lexer.el b/test/phps-mode-test-lexer.el
index 07ab84f..c4a2d35 100644
--- a/test/phps-mode-test-lexer.el
+++ b/test/phps-mode-test-lexer.el
@@ -176,7 +176,7 @@
    "Long inside array offset"
    ;; (message "Tokens: %s" phps-mode-lex-analyzer--tokens)
    (should (equal phps-mode-lex-analyzer--tokens
-                  '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_VARIABLE 12 . 18) 
("[" 18 . 19) (T_CONSTANT_ENCAPSED_STRING 19 . 24) ("]" 24 . 25) (";" 25 . 26) 
(T_ECHO 27 . 31) ("\"" 32 . 33) (T_ENCAPSED_AND_WHITESPACE 33 . 36) (T_VARIABLE 
36 . 43) (T_NUM_STRING 43 . 45) ("]" 45 . 46) (T_CONSTANT_ENCAPSED_STRING 46 . 
63) ("\"" 63 . 64) (";" 64 . 65)))))
+                  '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) (T_VARIABLE 12 . 18) 
("[" 18 . 19) (T_CONSTANT_ENCAPSED_STRING 19 . 24) ("]" 24 . 25) (";" 25 . 26) 
(T_ECHO 27 . 31) ("\"" 32 . 33) (T_ENCAPSED_AND_WHITESPACE 33 . 36) (T_VARIABLE 
36 . 42) ("[" 42 . 43) (T_NUM_STRING 43 . 45) ("]" 45 . 46) 
(T_CONSTANT_ENCAPSED_STRING 46 . 63) ("\"" 63 . 64) (";" 64 . 65)))))
 
   (phps-mode-test--with-buffer
    "<?php\n/*my comment */\n/** my doc comment */"
@@ -226,7 +226,7 @@
    "<?php echo \" Hello $variable[0], how are you?\";"
    nil
    (should (equal phps-mode-lex-analyzer--tokens
-                  '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) ("\"" 12 . 13) 
(T_ENCAPSED_AND_WHITESPACE 13 . 20) (T_VARIABLE 20 . 30) (T_NUM_STRING 30 . 31) 
("]" 31 . 32) (T_CONSTANT_ENCAPSED_STRING 32 . 46) ("\"" 46 . 47) (";" 47 . 
48)))))
+                  '((T_OPEN_TAG 1 . 7) (T_ECHO 7 . 11) ("\"" 12 . 13) 
(T_ENCAPSED_AND_WHITESPACE 13 . 20) (T_VARIABLE 20 . 29) ("[" 29 . 30) 
(T_NUM_STRING 30 . 31) ("]" 31 . 32) (T_CONSTANT_ENCAPSED_STRING 32 . 46) ("\"" 
46 . 47) (";" 47 . 48)))))
 
   ;; HEREDOC
 
@@ -289,15 +289,16 @@
   ;; Backquotes
   (phps-mode-test--with-buffer
    "<?php `echo \"HELLO\"`;"
-   nil
+   "Backquote basic test"
    (should (equal phps-mode-lex-analyzer--tokens
                   '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_CONSTANT_ENCAPSED_STRING 
8 . 20) ("`" 20 . 21) (";" 21 . 22)))))
 
   (phps-mode-test--with-buffer
    "<?php `echo \"HELLO $variable or {$variable2} or ${variable3} or 
$variable[index][0] here\"`;"
-   nil
+   "Double quoted strings with mixed variables"
+   ;; (message "Tokens: %s" phps-mode-lex-analyzer--tokens)
    (should (equal phps-mode-lex-analyzer--tokens
-                  '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_CONSTANT_ENCAPSED_STRING 
8 . 20) (T_VARIABLE 20 . 29) (T_CONSTANT_ENCAPSED_STRING 29 . 33) (T_CURLY_OPEN 
33 . 34) (T_VARIABLE 34 . 44) ("}" 44 . 45) (T_CONSTANT_ENCAPSED_STRING 45 . 
49) (T_DOLLAR_OPEN_CURLY_BRACES 49 . 51) (T_STRING_VARNAME 51 . 60) ("}" 60 . 
61) (T_CONSTANT_ENCAPSED_STRING 61 . 65) (T_VARIABLE 65 . 75) (T_STRING 75 . 
80) ("]" 80 . 81) (T_CONSTANT_ENCAPSED_STRING 81 . 90) ("`" 90 . 91) (";" 91 . 
92)))))
+                  '((T_OPEN_TAG 1 . 7) ("`" 7 . 8) (T_CONSTANT_ENCAPSED_STRING 
8 . 20) (T_VARIABLE 20 . 29) (T_CONSTANT_ENCAPSED_STRING 29 . 33) (T_CURLY_OPEN 
33 . 34) (T_VARIABLE 34 . 44) ("}" 44 . 45) (T_CONSTANT_ENCAPSED_STRING 45 . 
49) (T_DOLLAR_OPEN_CURLY_BRACES 49 . 51) (T_STRING_VARNAME 51 . 60) ("}" 60 . 
61) (T_CONSTANT_ENCAPSED_STRING 61 . 65) (T_VARIABLE 65 . 74) ("[" 74 . 75) 
(T_STRING 75 . 80) ("]" 80 . 81) (T_CONSTANT_ENCAPSED_STRING 81 . 90) ("`" 90 . 
91) (";" 91 . 92)))))
 
   (phps-mode-test--with-buffer
    "<?php $wpdb->posts; ?>"
@@ -359,6 +360,13 @@
    (should (equal phps-mode-lex-analyzer--tokens
                   '((T_OPEN_TAG 1 . 7) (T_CLASS 7 . 12) (T_STRING 13 . 20) 
("{" 21 . 22) (T_FUNCTION 23 . 31) (T_STRING 32 . 42) ("(" 42 . 43) (")" 43 . 
44) ("{" 45 . 46) (T_RETURN 47 . 53) (T_CONSTANT_ENCAPSED_STRING 54 . 61) (";" 
61 . 62) ("}" 63 . 64) ("}" 64 . 65) (T_VARIABLE 66 . 72) ("=" 73 . 74) (T_NEW 
75 . 78) (T_STRING 79 . 86) ("(" 86 . 87) (")" 87 . 88) (";" 88 . 89) 
(T_VARIABLE 90 . 99) ("=" 100 . 101) (T_CONSTANT_ENCAPSED_STRING 102 . 112) 
(";" 112 . 113) (T_ECHO 114 . 118)  [...]
 
+  (phps-mode-test--with-buffer
+   "<?php\n$product_path = \"${filename[0]}/${filename[1]}/\";\n    echo 
'here';\n"
+   "String with two dollar_open_curly_braces with indexes"
+   ;; (message "Tokens: %s" phps-mode-lex-analyzer--tokens)
+   (should (equal phps-mode-lex-analyzer--tokens
+                  '((T_OPEN_TAG 1 . 7) (T_VARIABLE 7 . 20) ("=" 21 . 22) ("\"" 
23 . 24) (T_ENCAPSED_AND_WHITESPACE 24 . 24) (T_DOLLAR_OPEN_CURLY_BRACES 24 . 
26) (T_STRING_VARNAME 26 . 34) ("[" 34 . 35) (T_LNUMBER 35 . 36) ("]" 36 . 37) 
("}" 37 . 38) (T_CONSTANT_ENCAPSED_STRING 38 . 39) (T_DOLLAR_OPEN_CURLY_BRACES 
39 . 41) (T_STRING_VARNAME 41 . 49) ("[" 49 . 50) (T_LNUMBER 50 . 51) ("]" 51 . 
52) ("}" 52 . 53) (T_CONSTANT_ENCAPSED_STRING 53 . 54) ("\"" 54 . 55) (";" 55 . 
56) (T_ECHO 61 .  [...]
+
   )
 
 (defun phps-mode-test-lexer--namespaces ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]