Skip to content

Commit

Permalink
Merge pull request #471 from fabacino/bugfix/fix-callable-highlighting
Browse files Browse the repository at this point in the history
Fix highlighting of callable keyword
  • Loading branch information
zonuexe authored Jun 8, 2018
2 parents 3699ad2 + 49e9066 commit cf1907b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
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"))

0 comments on commit cf1907b

Please sign in to comment.