Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highlighting of callable keyword #471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/type-hints.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,4 +146,12 @@ public function getNsObject(
public function getNullableNsObject(
): ?\path\to\my\Object {
}

public function getCallable(
): callable {
}

public function getNullableCallable(
): ?callable {
}
}
43 changes: 43 additions & 0 deletions tests/type-hints.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))