Skip to content

Commit 969b577

Browse files
authored
Merge pull request #653 from emacs-php/feture/support-php81-enum
Impl PHP 8.1 enum syntax
2 parents 53da0b4 + 5223a39 commit 969b577

File tree

5 files changed

+112
-2
lines changed

5 files changed

+112
-2
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
- "27.1"
2525
- snapshot
2626
include:
27+
- emacs_version: "24.4"
28+
allow_failure: true
29+
- emacs_version: "24.5"
30+
allow_failure: true
2731
- emacs_version: snapshot
2832
allow_failure: true
2933
steps:

lisp/php-mode.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ In that case set to `NIL'."
480480
(c-lang-defconst c-class-decl-kwds
481481
"Keywords introducing declarations where the following block (if any)
482482
contains another declaration level that should be considered a class."
483-
php '("class" "trait" "interface"))
483+
php '("class" "trait" "interface" "enum"))
484484

485485
(c-lang-defconst c-brace-list-decl-kwds
486486
"Keywords introducing declarations where the following block (if
@@ -493,7 +493,7 @@ PHP does not have an \"enum\"-like keyword."
493493
php (append (c-lang-const c-class-decl-kwds) '("function")))
494494

495495
(c-lang-defconst c-modifier-kwds
496-
php '("abstract" "const" "final" "static"))
496+
php '("abstract" "const" "final" "static" "case"))
497497

498498
(c-lang-defconst c-protection-kwds
499499
"Access protection label keywords in classes."

tests/8.1/enum.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
enum Size
4+
{
5+
case Small;
6+
case Medium;
7+
case Large;
8+
9+
public static function fromLength(int $cm)
10+
{
11+
return match(true) {
12+
$cm < 50 => static::Small,
13+
$cm < 100 => static::Medium,
14+
default => static::Large,
15+
};
16+
}
17+
}

tests/8.1/enum.php.faces

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("
4+
5+
")
6+
("enum" . php-keyword)
7+
(" ")
8+
("Size" . font-lock-type-face)
9+
("
10+
{
11+
")
12+
("case" . php-keyword)
13+
(" ")
14+
("Small" . font-lock-type-face)
15+
(";
16+
")
17+
("case" . php-keyword)
18+
(" ")
19+
("Medium" . font-lock-type-face)
20+
(";
21+
")
22+
("case" . php-keyword)
23+
(" ")
24+
("Large" . font-lock-type-face)
25+
(";
26+
27+
")
28+
("public" . php-keyword)
29+
(" ")
30+
("static" . php-keyword)
31+
(" ")
32+
("function" . php-keyword)
33+
(" ")
34+
("fromLength" . php-function-name)
35+
("(")
36+
("int" . font-lock-type-face)
37+
(" ")
38+
("$" . php-variable-sigil)
39+
("cm" . php-variable-name)
40+
(")
41+
{
42+
")
43+
("return" . php-keyword)
44+
(" ")
45+
("match" . php-keyword)
46+
("(")
47+
("true" . php-constant)
48+
(") {
49+
")
50+
("$" . php-variable-sigil)
51+
("cm" . php-variable-name)
52+
(" ")
53+
("<" . php-comparison-op)
54+
(" 50 ")
55+
("=" . php-assignment-op)
56+
(">" . php-comparison-op)
57+
(" ")
58+
("static" . php-keyword)
59+
("::" . php-paamayim-nekudotayim)
60+
("Small,
61+
")
62+
("$" . php-variable-sigil)
63+
("cm" . php-variable-name)
64+
(" ")
65+
("<" . php-comparison-op)
66+
(" 100 ")
67+
("=" . php-assignment-op)
68+
(">" . php-comparison-op)
69+
(" ")
70+
("static" . php-keyword)
71+
("::" . php-paamayim-nekudotayim)
72+
("Medium,
73+
")
74+
("default" . php-keyword)
75+
(" ")
76+
("=" . php-assignment-op)
77+
(">" . php-comparison-op)
78+
(" ")
79+
("static" . php-keyword)
80+
("::" . php-paamayim-nekudotayim)
81+
("Large,
82+
};
83+
}
84+
}
85+
"))

tests/php-mode-test.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ Meant for `php-mode-test-issue-503'."
654654
(with-php-mode-test ("7.4/arrow-function.php" :faces t))
655655
(with-php-mode-test ("7.4/typed-property.php" :faces t)))
656656

657+
(ert-deftest php-mode-test-php81 ()
658+
"Test highlighting language constructs added in PHP 8.1."
659+
(with-php-mode-test ("8.1/enum.php" :faces t)))
660+
657661
(ert-deftest php-mode-test-lang ()
658662
"Test highlighting for language constructs."
659663
(with-php-mode-test ("lang/class/anonymous-class.php" :indent t :magic t :faces t))

0 commit comments

Comments
 (0)