Skip to content

Commit cf1907b

Browse files
authored
Merge pull request #471 from fabacino/bugfix/fix-callable-highlighting
Fix highlighting of callable keyword
2 parents 3699ad2 + 49e9066 commit cf1907b

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

php-mode.el

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(defconst php-mode-version-number "1.19.1"
1616
"PHP Mode version number.")
1717

18-
(defconst php-mode-modified "2018-05-12"
18+
(defconst php-mode-modified "2018-06-08"
1919
"PHP Mode build date.")
2020

2121
;; This file is free software; you can redistribute it and/or
@@ -1635,13 +1635,14 @@ a completion list."
16351635
;; with type, like in arglist)
16361636
("\\(\\$\\)\\(\\sw+\\)" 1 'php-variable-sigil)
16371637

1638-
;; Array is a keyword, except in the following situations:
1639-
;; - when used as cast, so that (int) and (array) look the same
1638+
;; 'array' and 'callable' are keywords, except in the following situations:
16401639
;; - when used as a type hint
16411640
;; - when used as a return type
1641+
("\\b\\(array\\|callable\\)\\s-+&?\\$" 1 font-lock-type-face)
1642+
(")\\s-*:\\s-*\\??\\(array\\|callable\\)\\b" 1 font-lock-type-face)
1643+
;; For 'array', there is an additional situation:
1644+
;; - when used as cast, so that (int) and (array) look the same
16421645
("(\\(array\\))" 1 font-lock-type-face)
1643-
("\\b\\(array\\)\\s-+&?\\$" 1 font-lock-type-face)
1644-
(")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face)
16451646

16461647
;; namespaces
16471648
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face)

tests/type-hints.php

+16
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public function nullableNsObject(?\path\to\my\Object $object): ?\path\to\my\Obje
6262
{
6363
}
6464

65+
public function callable(callable $callable): callable
66+
{
67+
}
68+
69+
public function nullableCallable(?callable $callable): ?callable
70+
{
71+
}
72+
6573
public function someFunction(
6674
$any,
6775
string $name,
@@ -138,4 +146,12 @@ public function getNsObject(
138146
public function getNullableNsObject(
139147
): ?\path\to\my\Object {
140148
}
149+
150+
public function getCallable(
151+
): callable {
152+
}
153+
154+
public function getNullableCallable(
155+
): ?callable {
156+
}
141157
}

tests/type-hints.php.faces

+43
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,32 @@
202202
(" ")
203203
("function" . php-keyword)
204204
(" ")
205+
("callable" . php-function-name)
206+
("(")
207+
("callable" . font-lock-type-face)
208+
(" ")
209+
("$" . php-variable-sigil)
210+
("callable" . php-variable-name)
211+
("): ")
212+
("callable" . font-lock-type-face)
213+
("\n {\n }\n\n ")
214+
("public" . php-keyword)
215+
(" ")
216+
("function" . php-keyword)
217+
(" ")
218+
("nullableCallable" . php-function-name)
219+
("(?")
220+
("callable" . font-lock-type-face)
221+
(" ")
222+
("$" . php-variable-sigil)
223+
("callable" . php-variable-name)
224+
("): ?")
225+
("callable" . font-lock-type-face)
226+
("\n {\n }\n\n ")
227+
("public" . php-keyword)
228+
(" ")
229+
("function" . php-keyword)
230+
(" ")
205231
("someFunction" . php-function-name)
206232
("(\n ")
207233
("$" . php-variable-sigil)
@@ -378,4 +404,21 @@
378404
("getNullableNsObject" . php-function-name)
379405
("(\n ): ?")
380406
("\\path\\to\\my\\Object" . font-lock-type-face)
407+
408+
(" {\n }\n\n ")
409+
("public" . php-keyword)
410+
(" ")
411+
("function" . php-keyword)
412+
(" ")
413+
("getCallable" . php-function-name)
414+
("(\n ): ")
415+
("callable" . font-lock-type-face)
416+
(" {\n }\n\n ")
417+
("public" . php-keyword)
418+
(" ")
419+
("function" . php-keyword)
420+
(" ")
421+
("getNullableCallable" . php-function-name)
422+
("(\n ): ?")
423+
("callable" . font-lock-type-face)
381424
(" {\n }\n}\n"))

0 commit comments

Comments
 (0)