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

Highlight the ? character for nullable type hints and return types #482

Merged
merged 1 commit into from
Aug 29, 2018
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
19 changes: 14 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-06-08"
(defconst php-mode-modified "2018-08-28"
"PHP Mode build date.")

;; This file is free software; you can redistribute it and/or
Expand Down Expand Up @@ -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.")

Expand Down
100 changes: 50 additions & 50 deletions tests/type-hints.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand Down Expand Up @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
(" ")
Expand All @@ -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)
Expand All @@ -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"))