From 49e9066e385625d728d05f186b65ea30e894dfa0 Mon Sep 17 00:00:00 2001 From: fabacino Date: Fri, 8 Jun 2018 08:45:25 +0200 Subject: [PATCH] Fix highlighting of keyword callable If the keyword `callable` is used as a type hint or a return type, it is highlighted as a keyword instead of a type. This commit fixes this inconsistency. --- php-mode.el | 11 +++++----- tests/type-hints.php | 16 ++++++++++++++ tests/type-hints.php.faces | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/php-mode.el b/php-mode.el index 6b9e2ee6..d8f58941 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-05-12" +(defconst php-mode-modified "2018-06-08" "PHP Mode build date.") ;; This file is free software; you can redistribute it and/or @@ -1635,13 +1635,14 @@ a completion list." ;; with type, like in arglist) ("\\(\\$\\)\\(\\sw+\\)" 1 'php-variable-sigil) - ;; Array is a keyword, except in the following situations: - ;; - when used as cast, so that (int) and (array) look the same + ;; 'array' and 'callable' are keywords, except in the following situations: ;; - when used as a type hint ;; - when used as a return type + ("\\b\\(array\\|callable\\)\\s-+&?\\$" 1 font-lock-type-face) + (")\\s-*:\\s-*\\??\\(array\\|callable\\)\\b" 1 font-lock-type-face) + ;; For 'array', there is an additional situation: + ;; - when used as cast, so that (int) and (array) look the same ("(\\(array\\))" 1 font-lock-type-face) - ("\\b\\(array\\)\\s-+&?\\$" 1 font-lock-type-face) - (")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face) ;; namespaces ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face) diff --git a/tests/type-hints.php b/tests/type-hints.php index 0fbb3892..bfe987fc 100644 --- a/tests/type-hints.php +++ b/tests/type-hints.php @@ -62,6 +62,14 @@ public function nullableNsObject(?\path\to\my\Object $object): ?\path\to\my\Obje { } + public function callable(callable $callable): callable + { + } + + public function nullableCallable(?callable $callable): ?callable + { + } + public function someFunction( $any, string $name, @@ -138,4 +146,12 @@ public function getNsObject( public function getNullableNsObject( ): ?\path\to\my\Object { } + + public function getCallable( + ): callable { + } + + public function getNullableCallable( + ): ?callable { + } } diff --git a/tests/type-hints.php.faces b/tests/type-hints.php.faces index f5ba455a..e87c66f6 100644 --- a/tests/type-hints.php.faces +++ b/tests/type-hints.php.faces @@ -202,6 +202,32 @@ (" ") ("function" . php-keyword) (" ") + ("callable" . php-function-name) + ("(") + ("callable" . font-lock-type-face) + (" ") + ("$" . php-variable-sigil) + ("callable" . php-variable-name) + ("): ") + ("callable" . font-lock-type-face) + ("\n {\n }\n\n ") + ("public" . php-keyword) + (" ") + ("function" . php-keyword) + (" ") + ("nullableCallable" . php-function-name) + ("(?") + ("callable" . font-lock-type-face) + (" ") + ("$" . php-variable-sigil) + ("callable" . php-variable-name) + ("): ?") + ("callable" . font-lock-type-face) + ("\n {\n }\n\n ") + ("public" . php-keyword) + (" ") + ("function" . php-keyword) + (" ") ("someFunction" . php-function-name) ("(\n ") ("$" . php-variable-sigil) @@ -378,4 +404,21 @@ ("getNullableNsObject" . php-function-name) ("(\n ): ?") ("\\path\\to\\my\\Object" . font-lock-type-face) + + (" {\n }\n\n ") + ("public" . php-keyword) + (" ") + ("function" . php-keyword) + (" ") + ("getCallable" . php-function-name) + ("(\n ): ") + ("callable" . font-lock-type-face) + (" {\n }\n\n ") + ("public" . php-keyword) + (" ") + ("function" . php-keyword) + (" ") + ("getNullableCallable" . php-function-name) + ("(\n ): ?") + ("callable" . font-lock-type-face) (" {\n }\n}\n"))