Skip to content

Commit 7ca814e

Browse files
committed
Add highlight class name in typed property
1 parent 27a1f78 commit 7ca814e

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

php-mode-test.el

+4-3
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,10 @@ Meant for `php-mode-test-issue-503'."
662662
(goto-char (point-min))
663663
(should (eq (php-mode-test-in-function-p nil) nil))))
664664

665-
(ert-deftest php-mode-test-php74-arrow-fn ()
666-
"Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4."
667-
(with-php-mode-test ("7.4/arrow-function.php" :faces t)))
665+
(ert-deftest php-mode-test-php74 ()
666+
"Test highlighting language constructs added in PHP 7.4."
667+
(with-php-mode-test ("7.4/arrow-function.php" :faces t))
668+
(with-php-mode-test ("7.4/typed-property.php" :faces t)))
668669

669670
(ert-deftest php-mode-test-lang ()
670671
"Test highlighting for language constructs."

php-mode.el

+8-1
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,14 @@ a completion list."
14641464
;; namespaces
14651465
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face)
14661466
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant)
1467-
1467+
(,(eval-when-compile
1468+
(rx bol (* (syntax whitespace))
1469+
(or "private" "protected" "public")
1470+
(+ (syntax whitespace))
1471+
(group (? "?") (+ (or "\\" (syntax word) (syntax symbol))))
1472+
(+ (syntax whitespace))
1473+
(: "$" (+ (or (syntax word) (syntax symbol))))))
1474+
1 'php-class)
14681475
;; Support the ::class constant in PHP5.6
14691476
("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant))
14701477

tests/7.4/typed-property.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class Typed
4+
{
5+
private ?string $string;
6+
7+
private Hoge $hoge;
8+
9+
public function __construct($var = null)
10+
{
11+
$this->string = $var;
12+
}
13+
14+
public function print()
15+
{
16+
var_dump($this->string);
17+
}
18+
}
19+
20+
(new Typed)->print();

tests/7.4/typed-property.php.faces

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("
4+
5+
")
6+
("class" . php-keyword)
7+
(" ")
8+
("Typed" . font-lock-type-face)
9+
("
10+
{
11+
")
12+
("private" . php-keyword)
13+
(" ")
14+
("?string" . php-class)
15+
(" ")
16+
("$" . php-variable-sigil)
17+
("string" . php-variable-name)
18+
(";
19+
20+
")
21+
("private" . php-keyword)
22+
(" ")
23+
("Hoge" . php-class)
24+
(" ")
25+
("$" . php-variable-sigil)
26+
("hoge" . php-variable-name)
27+
(";
28+
29+
")
30+
("public" . php-keyword)
31+
(" ")
32+
("function" . php-keyword)
33+
(" ")
34+
("__construct" . php-function-name)
35+
("(")
36+
("$" . php-variable-sigil)
37+
("var" . php-variable-name)
38+
(" = ")
39+
("null" . php-constant)
40+
(")
41+
{
42+
")
43+
("$" . php-$this-sigil)
44+
("this" . php-$this)
45+
("->" . php-object-op)
46+
("string" . php-property-name)
47+
(" = ")
48+
("$" . php-variable-sigil)
49+
("var" . php-variable-name)
50+
(";
51+
}
52+
53+
")
54+
("public" . php-keyword)
55+
(" ")
56+
("function" . php-keyword)
57+
(" ")
58+
("print" . php-function-name)
59+
("()
60+
{
61+
var_dump(")
62+
("$" . php-$this-sigil)
63+
("this" . php-$this)
64+
("->" . php-object-op)
65+
("string" . php-property-name)
66+
(");
67+
}
68+
}
69+
70+
(")
71+
("new" . php-keyword)
72+
(" ")
73+
("Typed" . font-lock-type-face)
74+
(")")
75+
("->" . php-object-op)
76+
("print" . php-method-call)
77+
("();
78+
"))

0 commit comments

Comments
 (0)