From f31727165c11481a79bff35b83059433fe9d9c2f Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 9 Nov 2020 05:08:57 +0900 Subject: [PATCH 01/12] Add php-mode-use-php7-syntax-table for PHP7 compatible # syntax --- lisp/php-mode.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 1b88a8a7..8be8c7ac 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -318,6 +318,12 @@ In that case set to `NIL'." :tag "PHP Mode Enable Project Local Variable" :type 'boolean) +(defcustom php-mode-use-php7-syntax-table t + "When set to `T', use a syntax table compatible with PHP 7." + :group 'php-mode + :tag "PHP Mode Enable Project Local Variable" + :type 'boolean) + (defconst php-mode-cc-vertion (eval-when-compile c-version)) From a741209d2bf182d8f94155f2ef35d2d9f6cb5b52 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 9 Nov 2020 05:11:59 +0900 Subject: [PATCH 02/12] Modify syntax entry when php-mode-use-php7-syntax-table --- lisp/php-mode.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 8be8c7ac..59f5a384 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -1127,7 +1127,6 @@ After setting the stylevars run hooks according to STYLENAME (modify-syntax-entry ?_ "_" table) (modify-syntax-entry ?` "\"" table) (modify-syntax-entry ?\" "\"" table) - (modify-syntax-entry ?# "< b" table) (modify-syntax-entry ?\n "> b" table) (modify-syntax-entry ?$ "_" table) table)) @@ -1181,6 +1180,9 @@ After setting the stylevars run hooks according to STYLENAME ;; PHP vars are case-sensitive (setq case-fold-search t) + (when php-mode-use-php7-syntax-table + (modify-syntax-entry ?# "< b" php-mode-syntax-table)) + (when php-mode-enable-project-local-variable (add-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay t t)) From 3beeb574248c0a5e59a74837958f560e13bc123e Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 9 Nov 2020 05:15:20 +0900 Subject: [PATCH 03/12] Separate php-syntax-propertize-function and add # line comment --- lisp/php-mode.el | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 59f5a384..9be2f1ca 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -985,18 +985,43 @@ this ^ lineup" (string-match "\\_<.+?\\_>" heredoc-start) (concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W")) +(defvar php-syntax-propertize-functions + '(php-syntax-propertize-heredoc + php-syntax-propertize-quotes-in-comment + php-syntax-propertize-hash-line-comment) + "Syntax propertize functions for PHP script.") + (defun php-syntax-propertize-function (start end) "Apply propertize rules from START to END." - (goto-char start) + (dolist (propertizer php-syntax-propertize-functions) + (goto-char start) + (funcall propertizer start end))) + +(defun php-syntax-propertize-heredoc (_start end) + "Apply propertize Heredoc and Nowdoc from START to END." (while (and (< (point) end) (re-search-forward php-heredoc-start-re end t)) - (php-heredoc-syntax)) - (goto-char start) + (php-heredoc-syntax))) + +(defun php-syntax-propertize-quotes-in-comment (_start end) + "Apply propertize quotes (' and \") from START to END." (while (re-search-forward "['\"]" end t) (when (php-in-comment-p) (c-put-char-property (match-beginning 0) 'syntax-table (string-to-syntax "_"))))) +(defun php-syntax-propertize-hash-line-comment (_start end) + "Apply propertize # comment (without PHP8 Attributes) from START to END." + (unless php-mode-use-php7-syntax-table + (while (< (point) (min end (point-max))) + (let ((line-end (line-end-position))) + (when (and (search-forward "#" line-end t) + (not (php-in-string-or-comment-p)) + (not (looking-at "[[]"))) + (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "<")) + (c-put-char-property line-end 'syntax-table (string-to-syntax ">"))) + (move-beginning-of-line 2))))) + (defun php-heredoc-syntax () "Mark the boundaries of searched heredoc." (goto-char (match-beginning 0)) From 7c6717c4af97c812624a7399cef93fa86290c4be Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Nov 2020 13:04:41 +0900 Subject: [PATCH 04/12] Fix infinite loop while php-syntax-propertize-hash-line-comment in last line --- lisp/php-mode.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 9be2f1ca..4338f872 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -1013,14 +1013,17 @@ this ^ lineup" (defun php-syntax-propertize-hash-line-comment (_start end) "Apply propertize # comment (without PHP8 Attributes) from START to END." (unless php-mode-use-php7-syntax-table - (while (< (point) (min end (point-max))) - (let ((line-end (line-end-position))) + (let (line-end in-last-line) + (while (and (< (point) (min end (point-max))) + (not in-last-line)) + (setq line-end (line-end-position)) (when (and (search-forward "#" line-end t) (not (php-in-string-or-comment-p)) (not (looking-at "[[]"))) (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "<")) (c-put-char-property line-end 'syntax-table (string-to-syntax ">"))) - (move-beginning-of-line 2))))) + (move-beginning-of-line 2) + (setq in-last-line (>= line-end (point))))))) (defun php-heredoc-syntax () "Mark the boundaries of searched heredoc." From 964aa530ecc72bc24bcdeb91271381619a80eea0 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Nov 2020 13:07:15 +0900 Subject: [PATCH 05/12] The # following [] is not a comment and is excluded from comment-start-skip --- lisp/php-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 4338f872..a82f0a1f 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -1184,7 +1184,7 @@ After setting the stylevars run hooks according to STYLENAME (setq-local comment-start "// ") (setq-local comment-start-skip (eval-when-compile - (rx (group (or (: "#") + (rx (group (or (: "#" (not (any "["))) (: "/" (+ "/")) (: "/*"))) (* (syntax whitespace))))) From f8f018ea52dae0584649b5bc6a16cbd9b3fe0fb0 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Nov 2020 14:11:00 +0900 Subject: [PATCH 06/12] Do not set the comment termination property --- lisp/php-mode.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index a82f0a1f..f7607483 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -1020,8 +1020,7 @@ this ^ lineup" (when (and (search-forward "#" line-end t) (not (php-in-string-or-comment-p)) (not (looking-at "[[]"))) - (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "<")) - (c-put-char-property line-end 'syntax-table (string-to-syntax ">"))) + (c-put-char-property (1- (point)) 'syntax-table (string-to-syntax "< b"))) (move-beginning-of-line 2) (setq in-last-line (>= line-end (point))))))) From e74b664ebd8b65244d0aae5f90a5d9d9372971af Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Nov 2020 14:16:51 +0900 Subject: [PATCH 07/12] Set php-mode-use-php7-syntax-table to NIL as default --- lisp/php-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index f7607483..2b0ac4cb 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -318,7 +318,7 @@ In that case set to `NIL'." :tag "PHP Mode Enable Project Local Variable" :type 'boolean) -(defcustom php-mode-use-php7-syntax-table t +(defcustom php-mode-use-php7-syntax-table nil "When set to `T', use a syntax table compatible with PHP 7." :group 'php-mode :tag "PHP Mode Enable Project Local Variable" From 532788a05a88e4e5d6b0ec0e66168c5adbd48bd1 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Mon, 23 Nov 2020 14:25:44 +0900 Subject: [PATCH 08/12] Swap order of propertize comment --- lisp/php-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 2b0ac4cb..7521cd17 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -987,8 +987,8 @@ this ^ lineup" (defvar php-syntax-propertize-functions '(php-syntax-propertize-heredoc - php-syntax-propertize-quotes-in-comment - php-syntax-propertize-hash-line-comment) + php-syntax-propertize-hash-line-comment + php-syntax-propertize-quotes-in-comment) "Syntax propertize functions for PHP script.") (defun php-syntax-propertize-function (start end) From 1fd7fd8b4d09c7dff97a4d378a29403aefe7a7c7 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Tue, 5 Jan 2021 02:33:25 +0900 Subject: [PATCH 09/12] Fix Atributes test cases --- tests/8.0/attribute/class.php | 22 ++++++++++++++++++++++ tests/8.0/attribute/function.php | 10 +++++----- 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 tests/8.0/attribute/class.php diff --git a/tests/8.0/attribute/class.php b/tests/8.0/attribute/class.php new file mode 100644 index 00000000..4f2bf76e --- /dev/null +++ b/tests/8.0/attribute/class.php @@ -0,0 +1,22 @@ +> +#[ExampleAttribute] function f1() { } -<> -<> -<> +#[WithoutArgument] +#[SingleArgument(0)] +#[FewArguments('Hello', 'World')] function foo() {} -<><><> +#[WithoutArgument]#[SingleArgument(0)]#[FewArguments('Hello', 'World')] function bar() {} From 44d2924e64531b17876fcea45a43a7af9910a0eb Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Thu, 11 Mar 2021 02:04:14 +0900 Subject: [PATCH 10/12] Fix file last newline --- tests/8.1/enum.php.faces | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/8.1/enum.php.faces b/tests/8.1/enum.php.faces index 2a1b66f5..d21c2bd2 100644 --- a/tests/8.1/enum.php.faces +++ b/tests/8.1/enum.php.faces @@ -82,4 +82,4 @@ }; } } -")) \ No newline at end of file +")) From 70d9ccdedc701c1039da4f25f7319f967938e95c Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Thu, 11 Mar 2021 02:05:23 +0900 Subject: [PATCH 11/12] Add test cases for PHP 8.0 Attributes --- tests/8.0/attribute/class.php.faces | 72 +++++++++++++++++++++++++ tests/8.0/attribute/function.php.faces | 43 +++++++++++++++ tests/8.0/attribute/function2.php | 8 +++ tests/8.0/attribute/function2.php.faces | 23 ++++++++ tests/php-mode-test.el | 6 +++ 5 files changed, 152 insertions(+) create mode 100644 tests/8.0/attribute/class.php.faces create mode 100644 tests/8.0/attribute/function.php.faces create mode 100644 tests/8.0/attribute/function2.php create mode 100644 tests/8.0/attribute/function2.php.faces diff --git a/tests/8.0/attribute/class.php.faces b/tests/8.0/attribute/class.php.faces new file mode 100644 index 00000000..a4381657 --- /dev/null +++ b/tests/8.0/attribute/class.php.faces @@ -0,0 +1,72 @@ +;; -*- mode: emacs-lisp -*- +((" Date: Thu, 11 Mar 2021 02:09:06 +0900 Subject: [PATCH 12/12] Add comment to php-mode-test for generate .faces files --- tests/php-mode-test.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/php-mode-test.el b/tests/php-mode-test.el index 1abfd5c2..c53da223 100644 --- a/tests/php-mode-test.el +++ b/tests/php-mode-test.el @@ -684,4 +684,15 @@ Meant for `php-mode-test-issue-503'." (with-php-mode-test ("lang/errorcontrol.php" :faces t)) (with-php-mode-test ("lang/magical-constants/echo.php" :faces t))) +;; For developers: How to make .faces list file. +;; +;; 1. Press `M-x eval-buffer' in this file bufffer. +;; 2. Copy follows code snippet: +;; (setq x (php-mode-test--buffer-face-list (current-buffer))) +;; 3. Visit target buffer of testing PHP file. +;; 4. Press `M-:' (or `M-x eval-expression') and yank killed the code snippet. +;; 5. Press `M-x ielm' and input `x' and RET key. +;; 6. Kill output list and yank list to .faces file. +;; 7. Execute `make test' in shell. + ;;; php-mode-test.el ends here