diff --git a/php-mode.el b/php-mode.el index d8f58941..d38029a9 100644 --- a/php-mode.el +++ b/php-mode.el @@ -15,7 +15,7 @@ (defconst php-mode-version-number "1.19.1" "PHP Mode version number.") -(defconst php-mode-modified "2018-06-08" +(defconst php-mode-modified "2018-08-28" "PHP Mode build date.") ;; This file is free software; you can redistribute it and/or @@ -1698,12 +1698,21 @@ a completion list." " \\(\\sw+\\)") 1 font-lock-type-face) - ;; Highlight return types in functions and methods. - ("function.+:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face) - (")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face) + ;; Highlight the ? character for nullable return types. + ("function.+:\\s-*\\(\\?\\)\\(?:\\sw\\|\\s_\\|\\\\\\)+" 1 font-lock-type-face) + (")\\s-*:\\s-*\\(\\?\\)\\(?:\\sw\\|\\s_\\|\\\\\\)+\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face) + + ;; Highlight the ? character for nullable type hints. + ("\\(\\?\\)\\(:?\\sw\\|\\s_\\|\\\\\\)+\\s-+\\$" 1 font-lock-type-face) - ;; Highlight class names used as nullable type hints + ;; Class names without a namespace are not highlighted at all when they + ;; are used as nullable type hints or return types (both nullable and + ;; non-nullable). We have to use separate regular expressions, because + ;; we want to capture the class name as well, not just the ? character + ;; like the regexps above. ("\\?\\(\\(:?\\sw\\|\\s_\\)+\\)\\s-+\\$" 1 font-lock-type-face) + ("function.+:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)" 1 font-lock-type-face) + (")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face) )) "Detailed highlighting for PHP Mode.") diff --git a/tests/type-hints.php.faces b/tests/type-hints.php.faces index e87c66f6..ccac11cb 100644 --- a/tests/type-hints.php.faces +++ b/tests/type-hints.php.faces @@ -34,13 +34,13 @@ ("function" . php-keyword) (" ") ("nullableTitle" . php-function-name) - ("(?") - ("string" . font-lock-type-face) + ("(") + ("?string" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("title" . php-variable-name) - ("): ?") - ("string" . font-lock-type-face) + ("): ") + ("?string" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -60,13 +60,13 @@ ("function" . php-keyword) (" ") ("nullableNumber" . php-function-name) - ("(?") - ("int" . font-lock-type-face) + ("(") + ("?int" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("number" . php-variable-name) - ("): ?") - ("int" . font-lock-type-face) + ("): ") + ("?int" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -86,13 +86,13 @@ ("function" . php-keyword) (" ") ("nullableOtherNumber" . php-function-name) - ("(?") - ("float" . font-lock-type-face) + ("(") + ("?float" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("number" . php-variable-name) - ("): ?") - ("float" . font-lock-type-face) + ("): ") + ("?float" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -112,13 +112,13 @@ ("function" . php-keyword) (" ") ("nullableFlag" . php-function-name) - ("(?") - ("bool" . font-lock-type-face) + ("(") + ("?bool" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("flag" . php-variable-name) - ("): ?") - ("bool" . font-lock-type-face) + ("): ") + ("?bool" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -138,13 +138,13 @@ ("function" . php-keyword) (" ") ("nullableOptions" . php-function-name) - ("(?") - ("array" . font-lock-type-face) + ("(") + ("?array" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("options" . php-variable-name) - ("): ?") - ("array" . font-lock-type-face) + ("): ") + ("?array" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -164,13 +164,13 @@ ("function" . php-keyword) (" ") ("nullableObject" . php-function-name) - ("(?") - ("stdClass" . font-lock-type-face) + ("(") + ("?stdClass" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("object" . php-variable-name) - ("): ?") - ("stdClass" . font-lock-type-face) + ("): ") + ("?stdClass" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -190,13 +190,13 @@ ("function" . php-keyword) (" ") ("nullableNsObject" . php-function-name) - ("(?") - ("\\path\\to\\my\\Object" . font-lock-type-face) + ("(") + ("?\\path\\to\\my\\Object" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("object" . php-variable-name) - ("): ?") - ("\\path\\to\\my\\Object" . font-lock-type-face) + ("): ") + ("?\\path\\to\\my\\Object" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -216,13 +216,13 @@ ("function" . php-keyword) (" ") ("nullableCallable" . php-function-name) - ("(?") - ("callable" . font-lock-type-face) + ("(") + ("?callable" . font-lock-type-face) (" ") ("$" . php-variable-sigil) ("callable" . php-variable-name) - ("): ?") - ("callable" . font-lock-type-face) + ("): ") + ("?callable" . font-lock-type-face) ("\n {\n }\n\n ") ("public" . php-keyword) (" ") @@ -286,8 +286,8 @@ ("function" . php-keyword) (" ") ("getNullableTitle" . php-function-name) - ("(\n ): ?") - ("string" . font-lock-type-face) + ("(\n ): ") + ("?string" . font-lock-type-face) (" {\n }\n\n ") ("public" . php-keyword) (" ") @@ -302,8 +302,8 @@ ("function" . php-keyword) (" ") ("getNullableNumber" . php-function-name) - ("(\n ): ?") - ("int" . font-lock-type-face) + ("(\n ): ") + ("?int" . font-lock-type-face) (" {\n }\n\n ") ("public" . php-keyword) (" ") @@ -318,8 +318,8 @@ ("function" . php-keyword) (" ") ("getNullableOtherNumber" . php-function-name) - ("(\n ): ?") - ("float" . font-lock-type-face) + ("(\n ): ") + ("?float" . font-lock-type-face) (" {\n }\n\n ") ("public" . php-keyword) (" ") @@ -334,8 +334,8 @@ ("function" . php-keyword) (" ") ("getNullableFlag" . php-function-name) - ("(\n ): ?") - ("bool" . font-lock-type-face) + ("(\n ): ") + ("?bool" . font-lock-type-face) (" {\n }\n\n ") ("public" . php-keyword) (" ") @@ -350,8 +350,8 @@ ("function" . php-keyword) (" ") ("getNullableOptions" . php-function-name) - ("(\n ): ?") - ("array" . font-lock-type-face) + ("(\n ): ") + ("?array" . font-lock-type-face) (" {\n }\n\n ") ("public" . php-keyword) (" ") @@ -366,8 +366,8 @@ ("function" . php-keyword) (" ") ("getNullableObject" . php-function-name) - ("(\n ): ?") - ("stdClass" . font-lock-type-face) + ("(\n ): ") + ("?stdClass" . font-lock-type-face) (" {\n }\n\n ") ("abstract" . php-keyword) (" ") @@ -386,8 +386,8 @@ ("function" . php-keyword) (" ") ("getOtherNullableObject" . php-function-name) - ("(\n ): ?") - ("stdClass" . font-lock-type-face) + ("(\n ): ") + ("?stdClass" . font-lock-type-face) (";\n\n ") ("public" . php-keyword) (" ") @@ -402,8 +402,8 @@ ("function" . php-keyword) (" ") ("getNullableNsObject" . php-function-name) - ("(\n ): ?") - ("\\path\\to\\my\\Object" . font-lock-type-face) + ("(\n ): ") + ("?\\path\\to\\my\\Object" . font-lock-type-face) (" {\n }\n\n ") ("public" . php-keyword) @@ -419,6 +419,6 @@ ("function" . php-keyword) (" ") ("getNullableCallable" . php-function-name) - ("(\n ): ?") - ("callable" . font-lock-type-face) + ("(\n ): ") + ("?callable" . font-lock-type-face) (" {\n }\n}\n"))