Skip to content

Commit

Permalink
Merge pull request #680 from emacs-php/feature/php81-readonly-keyword
Browse files Browse the repository at this point in the history
Add PHP 8.1 readonly keyword
  • Loading branch information
zonuexe authored Aug 1, 2021
2 parents 4b0e9f8 + df84b7e commit 83b21b5
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ PHP does not have an C-like \"enum\" keyword."
php (append (c-lang-const c-class-decl-kwds) '("function")))

(c-lang-defconst c-modifier-kwds
php '("abstract" "const" "final" "static" "case"))
php '("abstract" "const" "final" "static" "case" "readonly"))

(c-lang-defconst c-protection-kwds
"Access protection label keywords in classes."
Expand Down
20 changes: 20 additions & 0 deletions tests/8.1/readonly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class Foo
{
private readonly string $p1;
public readonly int $p2;

public function __construct(
private readonly string $a1,
public readonly int $a2,
) {}
}

__halt_compiler();

claas Err
{
/** Readonly property must have type */
public readonly $e1;
}
84 changes: 84 additions & 0 deletions tests/8.1/readonly.php.faces
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
;; -*- mode: emacs-lisp -*-
(("<?php" . php-php-tag)
("
")
("class" . php-class-declaration)
(" ")
("Foo" . font-lock-type-face)
("
{
")
("private" . php-keyword)
(" ")
("readonly" . php-keyword)
(" ")
("string" . font-lock-type-face)
(" ")
("$" . php-variable-sigil)
("p1" . php-variable-name)
(";
")
("public" . php-keyword)
(" ")
("readonly" . php-keyword)
(" ")
("int" . font-lock-type-face)
(" ")
("$" . php-variable-sigil)
("p2" . php-variable-name)
(";
")
("public" . php-keyword)
(" ")
("function" . php-keyword)
(" ")
("__construct" . php-function-name)
("(
")
("private" . php-keyword)
(" ")
("readonly" . php-keyword)
(" ")
("string" . font-lock-type-face)
(" ")
("$" . php-variable-sigil)
("a1" . php-variable-name)
(",
")
("public" . php-keyword)
(" ")
("readonly" . php-keyword)
(" ")
("int" . font-lock-type-face)
(" ")
("$" . php-variable-sigil)
("a2" . php-variable-name)
(",
) {}
}
")
("__halt_compiler" . php-keyword)
("();
")
("claas" . font-lock-type-face)
(" ")
("Err" . font-lock-variable-name-face)
("
{
")
("/** Readonly property must have type */" . font-lock-doc-face)
("
")
("public" . php-keyword)
(" ")
("readonly" . php-class)
(" ")
("$" . php-variable-sigil)
("e1" . php-variable-name)
(";
}
"))
3 changes: 2 additions & 1 deletion tests/php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ Meant for `php-mode-test-issue-503'."

(ert-deftest php-mode-test-php81 ()
"Test highlighting language constructs added in PHP 8.1."
(with-php-mode-test ("8.1/enum.php" :faces t)))
(with-php-mode-test ("8.1/enum.php" :faces t))
(with-php-mode-test ("8.1/readonly.php" :faces t)))

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

0 comments on commit 83b21b5

Please sign in to comment.