Skip to content

Commit 37191d8

Browse files
authored
Merge pull request #507 from emacs-php/feature/72-arrow-function
Add fn keyword (PHP 7.2 arrow function)
2 parents c20b3a7 + 32b4943 commit 37191d8

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

Diff for: php-mode-test.el

+4
Original file line numberDiff line numberDiff line change
@@ -973,4 +973,8 @@ Meant for `php-mode-test-issue-503'."
973973
(goto-char (point-min))
974974
(should (eq (php-mode-test-in-function-p nil) nil))))
975975

976+
(ert-deftest php-mode-test-php74-arrow-fn ()
977+
"Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4."
978+
(with-php-mode-test ("7.4/arrow-function.php" :faces t)))
979+
976980
;;; php-mode-test.el ends here

Diff for: php-mode.el

+1
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ PHP does not have an \"enum\"-like keyword."
625625
"endswitch"
626626
"endwhile"
627627
"eval"
628+
"fn" ;; NOT c-lambda-kwds
628629
"global"
629630
"isset"
630631
"list"

Diff for: tests/7.4/arrow-function.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* GitHub-Issue: https://github.com/emacs-php/php-mode/issues/506
5+
*
6+
* @see https://wiki.php.net/rfc/arrow_functions_v2
7+
*/
8+
9+
$fn1 = fn($x) => $x + $y;
10+
11+
$fn2 = [
12+
fn($x) => $x + $y
13+
];
14+
15+
$z = 1;
16+
$fn3 = fn($x) => fn($y) => $x * $y + $z;

Diff for: tests/7.4/arrow-function.php.faces

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("/**\n * GitHub-Issue: " . font-lock-doc-face)
5+
("https://github.com/emacs-php/php-mode/issues/506" link font-lock-doc-face)
6+
("\n *\n * " . font-lock-doc-face)
7+
("@see" php-doc-annotation-tag font-lock-doc-face)
8+
(" " . font-lock-doc-face)
9+
("https://wiki.php.net/rfc/arrow_functions_v2" link font-lock-doc-face)
10+
("\n */" . font-lock-doc-face)
11+
("\n\n")
12+
("$" . php-variable-sigil)
13+
("fn1" . php-variable-name)
14+
(" = ")
15+
("fn" . php-keyword)
16+
("(")
17+
("$" . php-variable-sigil)
18+
("x" . php-variable-name)
19+
(") => ")
20+
("$" . php-variable-sigil)
21+
("x" . php-variable-name)
22+
(" + ")
23+
("$" . php-variable-sigil)
24+
("y" . php-variable-name)
25+
(";\n\n")
26+
("$" . php-variable-sigil)
27+
("fn2" . php-variable-name)
28+
(" = [\n ")
29+
("fn" . php-keyword)
30+
("(")
31+
("$" . php-variable-sigil)
32+
("x" . php-variable-name)
33+
(") => ")
34+
("$" . php-variable-sigil)
35+
("x" . php-variable-name)
36+
(" + ")
37+
("$" . php-variable-sigil)
38+
("y" . php-variable-name)
39+
("\n];\n\n")
40+
("$" . php-variable-sigil)
41+
("z" . php-variable-name)
42+
(" = 1;\n")
43+
("$" . php-variable-sigil)
44+
("fn3" . php-variable-name)
45+
(" = ")
46+
("fn" . php-keyword)
47+
("(")
48+
("$" . php-variable-sigil)
49+
("x" . php-variable-name)
50+
(") => ")
51+
("fn" . php-keyword)
52+
("(")
53+
("$" . php-variable-sigil)
54+
("y" . php-variable-name)
55+
(") => ")
56+
("$" . php-variable-sigil)
57+
("x" . php-variable-name)
58+
(" * ")
59+
("$" . php-variable-sigil)
60+
("y" . php-variable-name)
61+
(" + ")
62+
("$" . php-variable-sigil)
63+
("z" . php-variable-name)
64+
(";\n"))

0 commit comments

Comments
 (0)