Skip to content

Commit

Permalink
Add highlight class name in typed property
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Jun 18, 2019
1 parent 27a1f78 commit c12a2ab
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 4 deletions.
7 changes: 4 additions & 3 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,10 @@ Meant for `php-mode-test-issue-503'."
(goto-char (point-min))
(should (eq (php-mode-test-in-function-p nil) nil))))

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

(ert-deftest php-mode-test-lang ()
"Test highlighting for language constructs."
Expand Down
9 changes: 8 additions & 1 deletion php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,14 @@ a completion list."
;; namespaces
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face)
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant)

(,(eval-when-compile
(rx bol (* (syntax whitespace))
(or "private" "protected" "public")
(+ (syntax whitespace))
(group (? "?") (+ (or "\\" (syntax word) (syntax symbol))))
(+ (syntax whitespace))
(: "$" (+ (or (syntax word) (syntax symbol))))))
1 'php-class)
;; Support the ::class constant in PHP5.6
("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant))

Expand Down
20 changes: 20 additions & 0 deletions tests/7.4/typed-property.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class Typed
{
private ?string $string;

private Hoge $hoge;

public function __construct($var = null)
{
$this->string = $var;
}

public function print()
{
var_dump($this->string);
}
}

(new Typed)->print();
78 changes: 78 additions & 0 deletions tests/7.4/typed-property.php.faces
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
;; -*- mode: emacs-lisp -*-
(("<?php" . php-php-tag)
("
")
("class" . php-keyword)
(" ")
("Typed" . font-lock-type-face)
("
{
")
("private" . php-keyword)
(" ")
("?string" . php-class)
(" ")
("$" . php-variable-sigil)
("string" . php-variable-name)
(";
")
("private" . php-keyword)
(" ")
("Hoge" . php-class)
(" ")
("$" . php-variable-sigil)
("hoge" . php-variable-name)
(";
")
("public" . php-keyword)
(" ")
("function" . php-keyword)
(" ")
("__construct" . php-function-name)
("(")
("$" . php-variable-sigil)
("var" . php-variable-name)
(" = ")
("null" . php-constant)
(")
{
")
("$" . php-$this-sigil)
("this" . php-$this)
("->" . php-object-op)
("string" . php-property-name)
(" = ")
("$" . php-variable-sigil)
("var" . php-variable-name)
(";
}
")
("public" . php-keyword)
(" ")
("function" . php-keyword)
(" ")
("print" . php-function-name)
("()
{
var_dump(")
("$" . php-$this-sigil)
("this" . php-$this)
("->" . php-object-op)
("string" . php-property-name)
(");
}
}
(")
("new" . php-keyword)
(" ")
("Typed" . font-lock-type-face)
(")")
("->" . php-object-op)
("print" . php-method-call)
("();
"))

0 comments on commit c12a2ab

Please sign in to comment.