Skip to content

Commit bf48740

Browse files
authored
Merge pull request #520 from emacs-php/reclassification-keywords
Reclassify keywords and types
2 parents 06edbd3 + 2d0a01e commit bf48740

File tree

10 files changed

+204
-7
lines changed

10 files changed

+204
-7
lines changed

php-mode-test.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ Meant for `php-mode-test-issue-503'."
986986

987987
(ert-deftest php-mode-test-lang ()
988988
"Test highlighting for language constructs."
989+
(with-php-mode-test ("lang/types/cast.php" :faces t))
990+
(with-php-mode-test ("lang/types/function.php" :faces t))
991+
(with-php-mode-test ("lang/types/keywords.php" :faces t))
989992
(with-php-mode-test ("lang/errorcontrol.php" :faces t)))
990993

991994
;;; php-mode-test.el ends here

php-mode.el

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ PHP does not have an \"enum\"-like keyword."
502502
"__halt_compiler"
503503
"and"
504504
"array"
505-
"callable"
506-
"iterable"
507505
"as"
508506
"break"
509507
"catch"
@@ -1395,7 +1393,7 @@ a completion list."
13951393
("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call))
13961394

13971395
;; Highlight special variables
1398-
("\\(\\$\\)\\(this\\|that\\)\\_>" (1 'php-$this-sigil) (2 'php-$this))
1396+
("\\(\\$\\)\\(this\\)\\>" (1 'php-$this-sigil) (2 'php-$this))
13991397
("\\(\\$+\\)\\(\\sw+\\)" (1 'php-variable-sigil) (2 'php-variable-name))
14001398
("\\(->\\)\\([a-zA-Z0-9_]+\\)" (1 'php-object-op) (2 'php-property-name))
14011399

tests/issue-201.php.faces

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
("$" . php-$this-sigil)
1414
("this" . php-$this)
1515
(";\n")
16-
("$" . php-$this-sigil)
17-
("that" . php-$this)
16+
("$" . php-variable-sigil)
17+
("that" . php-variable-name)
1818
(";\n")
1919
("self" . php-keyword)
2020
("::" . php-paamayim-nekudotayim)

tests/lang/types/cast.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$var = 1;
4+
5+
(array)$var;
6+
(binary)$var;
7+
(bool)$var;
8+
(boolean)$var;
9+
(float)$var;
10+
(int)$var;
11+
(integer)$var;
12+
(object)$var;
13+
(real)$var;
14+
(string)$var;
15+
(unset)$var;

tests/lang/types/cast.php.faces

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("$" . php-variable-sigil)
5+
("var" . php-variable-name)
6+
(" = 1;\n\n(")
7+
("array" . font-lock-type-face)
8+
(")")
9+
("$" . php-variable-sigil)
10+
("var" . php-variable-name)
11+
(";\n(")
12+
("binary" . font-lock-type-face)
13+
(")")
14+
("$" . php-variable-sigil)
15+
("var" . php-variable-name)
16+
(";\n(")
17+
("bool" . font-lock-type-face)
18+
(")")
19+
("$" . php-variable-sigil)
20+
("var" . php-variable-name)
21+
(";\n(")
22+
("boolean" . font-lock-type-face)
23+
(")")
24+
("$" . php-variable-sigil)
25+
("var" . php-variable-name)
26+
(";\n(")
27+
("float" . font-lock-type-face)
28+
(")")
29+
("$" . php-variable-sigil)
30+
("var" . php-variable-name)
31+
(";\n(")
32+
("int" . font-lock-type-face)
33+
(")")
34+
("$" . php-variable-sigil)
35+
("var" . php-variable-name)
36+
(";\n(")
37+
("integer" . font-lock-type-face)
38+
(")")
39+
("$" . php-variable-sigil)
40+
("var" . php-variable-name)
41+
(";\n(")
42+
("object" . font-lock-type-face)
43+
(")")
44+
("$" . php-variable-sigil)
45+
("var" . php-variable-name)
46+
(";\n(")
47+
("real" . font-lock-type-face)
48+
(")")
49+
("$" . php-variable-sigil)
50+
("var" . php-variable-name)
51+
(";\n(")
52+
("string" . font-lock-type-face)
53+
(")")
54+
("$" . php-variable-sigil)
55+
("var" . php-variable-name)
56+
(";\n(")
57+
("unset" . php-keyword)
58+
(")")
59+
("$" . php-variable-sigil)
60+
("var" . php-variable-name)
61+
(";\n"))

tests/lang/types/function.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
function (bool $args) {};
4+
function (boolean $args) {};
5+
function (int $args) {};
6+
function (integer $args) {};
7+
function (float $args) {};
8+
function (double $args) {};
9+
function (real $args) {};
10+
function (string $args) {};
11+
function (object $args) {};
12+
function (resource $args) {};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("function" . php-keyword)
5+
(" (")
6+
("bool" . font-lock-type-face)
7+
(" ")
8+
("$" . php-variable-sigil)
9+
("args" . php-variable-name)
10+
(") {};\n")
11+
("function" . php-keyword)
12+
(" (")
13+
("boolean" . font-lock-type-face)
14+
(" ")
15+
("$" . php-variable-sigil)
16+
("args" . php-variable-name)
17+
(") {};\n")
18+
("function" . php-keyword)
19+
(" (")
20+
("int" . font-lock-type-face)
21+
(" ")
22+
("$" . php-variable-sigil)
23+
("args" . php-variable-name)
24+
(") {};\n")
25+
("function" . php-keyword)
26+
(" (")
27+
("integer" . font-lock-type-face)
28+
(" ")
29+
("$" . php-variable-sigil)
30+
("args" . php-variable-name)
31+
(") {};\n")
32+
("function" . php-keyword)
33+
(" (")
34+
("float" . font-lock-type-face)
35+
(" ")
36+
("$" . php-variable-sigil)
37+
("args" . php-variable-name)
38+
(") {};\n")
39+
("function" . php-keyword)
40+
(" (")
41+
("double" . font-lock-type-face)
42+
(" ")
43+
("$" . php-variable-sigil)
44+
("args" . php-variable-name)
45+
(") {};\n")
46+
("function" . php-keyword)
47+
(" (")
48+
("real" . font-lock-type-face)
49+
(" ")
50+
("$" . php-variable-sigil)
51+
("args" . php-variable-name)
52+
(") {};\n")
53+
("function" . php-keyword)
54+
(" (")
55+
("string" . font-lock-type-face)
56+
(" ")
57+
("$" . php-variable-sigil)
58+
("args" . php-variable-name)
59+
(") {};\n")
60+
("function" . php-keyword)
61+
(" (")
62+
("object" . font-lock-type-face)
63+
(" ")
64+
("$" . php-variable-sigil)
65+
("args" . php-variable-name)
66+
(") {};\n")
67+
("function" . php-keyword)
68+
(" (")
69+
("resource" . font-lock-type-face)
70+
(" ")
71+
("$" . php-variable-sigil)
72+
("args" . php-variable-name)
73+
(") {};\n"))

tests/lang/types/keywords.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
__halt_compiler();
4+
5+
bool;
6+
boolean;
7+
int;
8+
integer;
9+
float;
10+
double;
11+
real;
12+
string;
13+
object;
14+
resource;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("__halt_compiler" . php-keyword)
5+
("();\n\n")
6+
("bool" . font-lock-type-face)
7+
(";\n")
8+
("boolean" . font-lock-type-face)
9+
(";\n")
10+
("int" . font-lock-type-face)
11+
(";\n")
12+
("integer" . font-lock-type-face)
13+
(";\n")
14+
("float" . font-lock-type-face)
15+
(";\n")
16+
("double" . font-lock-type-face)
17+
(";\n")
18+
("real" . font-lock-type-face)
19+
(";\n")
20+
("string" . font-lock-type-face)
21+
(";\n")
22+
("object" . font-lock-type-face)
23+
(";\nresource;\n"))

tests/language-constructs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
array();
1818
as;
1919
break;
20-
callable;
2120
case;
2221
catch;
2322
class ClassName;
@@ -56,7 +55,6 @@ function;
5655
insteadof ClassName;
5756
interface ClassName;
5857
isset();
59-
iterable;
6058
list();
6159
namespace ClassName;
6260
new ClassName;

0 commit comments

Comments
 (0)