Skip to content

Commit 87d7939

Browse files
PHP: Fixed functions with namespaces (#2889)
1 parent 8047118 commit 87d7939

File tree

9 files changed

+209
-73
lines changed

9 files changed

+209
-73
lines changed

components/prism-php.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@
219219
}
220220
],
221221
'constant': constant,
222-
'function': /\b\w+(?=\s*\()/,
222+
'function': {
223+
pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
224+
lookbehind: true,
225+
inside: {
226+
'punctuation': /\\/
227+
}
228+
},
223229
'property': {
224230
pattern: /(->\s*)\w+/,
225231
lookbehind: true

components/prism-php.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/latte/delimiter_feature.test

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,102 @@ line}
1414
----------------------------------------------------
1515

1616
[
17-
["latte", [["ld", [["punctuation", "{"], ["tag", "aa"]]], ["rd", [["punctuation", "}"]]]]],
18-
["latte", [["ld", [["punctuation", "{/"], ["tag", "aa"]]], ["rd", [["punctuation", "}"]]]]],
19-
["latte", [["ld", [["punctuation", "{"]]], ["php", [["operator", "/"]]], ["rd", [["punctuation", "}"]]]]],
17+
["latte", [
18+
["ld", [
19+
["punctuation", "{"],
20+
["tag", "aa"]
21+
]],
22+
["rd", [
23+
["punctuation", "}"]
24+
]]
25+
]],
26+
27+
["latte", [
28+
["ld", [
29+
["punctuation", "{/"],
30+
["tag", "aa"]
31+
]],
32+
["rd", [
33+
["punctuation", "}"]
34+
]]
35+
]],
36+
37+
["latte", [
38+
["ld", [
39+
["punctuation", "{"]
40+
]],
41+
["php", [
42+
["operator", "/"]
43+
]],
44+
["rd", [
45+
["punctuation", "}"]
46+
]]
47+
]],
48+
2049
"\r\n{",
21-
["latte", [["ld", [["punctuation", "{"], ["tag", "aa"]]], ["rd", [["punctuation", "}"]]]]],
50+
["latte", [
51+
["ld", [
52+
["punctuation", "{"],
53+
["tag", "aa"]
54+
]],
55+
["rd", [
56+
["punctuation", "}"]
57+
]]
58+
]],
2259
"}\r\n",
23-
["latte", [["ld", [["punctuation", "{"]]], ["php", [["number", "10"]]], ["rd", [["punctuation", "}"]]]]],
24-
["latte", [["ld", [["punctuation", "{"], ["tag", "="]]], ["php", [["number", "10"]]], ["rd", [["punctuation", "}"]]]]],
25-
["latte", [["ld", [["punctuation", "{"]]], ["php", [["function", "test"], ["punctuation", "("], ["punctuation", ")"]]], ["rd", [["punctuation", "}"]]]]],
60+
61+
["latte", [
62+
["ld", [
63+
["punctuation", "{"]
64+
]],
65+
["php", [
66+
["number", "10"]
67+
]],
68+
["rd", [
69+
["punctuation", "}"]
70+
]]
71+
]],
72+
73+
["latte", [
74+
["ld", [
75+
["punctuation", "{"],
76+
["tag", "="]
77+
]],
78+
["php", [
79+
["number", "10"]
80+
]],
81+
["rd", [
82+
["punctuation", "}"]
83+
]]
84+
]],
85+
86+
["latte", [
87+
["ld", [
88+
["punctuation", "{"]
89+
]],
90+
["php", [
91+
["function", ["test"]],
92+
["punctuation", "("],
93+
["punctuation", ")"]
94+
]],
95+
["rd", [
96+
["punctuation", "}"]
97+
]]
98+
]],
99+
26100
"\r\n{'no'}\r\n{\"no\"}\r\n{ no }\r\n",
27-
["latte", [["ld", [["punctuation", "{"], ["tag", "multi"]]], ["php", ["line"]], ["rd", [["punctuation", "}"]]]]]
101+
102+
["latte", [
103+
["ld", [
104+
["punctuation", "{"],
105+
["tag", "multi"]
106+
]],
107+
108+
["php", ["line"]],
109+
["rd", [
110+
["punctuation", "}"]
111+
]]
112+
]]
28113
]
29114

30115
----------------------------------------------------
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
<img style="width:<?php echo (80 / count($images)) ?>%"/>
2-
3-
----------------------------------------------------
4-
5-
[
6-
["tag", [
7-
["tag", [
8-
["punctuation", "<"],
9-
"img"
10-
]],
11-
["special-attr", [
12-
["attr-name", "style"],
13-
["attr-value", [
14-
["punctuation", "="],
15-
["punctuation", "\""],
16-
["value", [
17-
["property", "width"],
18-
["punctuation", ":"],
19-
["php", [
20-
["delimiter", "<?php"],
21-
["keyword", "echo"],
22-
["punctuation", "("],
23-
["number", "80"],
24-
["operator", "/"],
25-
["function", "count"],
26-
["punctuation", "("],
27-
["variable", "$images"],
28-
["punctuation", ")"],
29-
["punctuation", ")"],
30-
["delimiter", "?>"]
31-
]],
32-
"%"
33-
]],
34-
["punctuation", "\""]
35-
]]
36-
]],
37-
["punctuation", "/>"]
38-
]]
39-
]
40-
41-
----------------------------------------------------
42-
43-
Checks for #2008 where a part of markup templating's placeholder was tokenized as `number` by CSS Extras.
1+
<img style="width:<?php echo (80 / count($images)) ?>%"/>
2+
3+
----------------------------------------------------
4+
5+
[
6+
["tag", [
7+
["tag", [
8+
["punctuation", "<"],
9+
"img"
10+
]],
11+
["special-attr", [
12+
["attr-name", "style"],
13+
["attr-value", [
14+
["punctuation", "="],
15+
["punctuation", "\""],
16+
["value", [
17+
["property", "width"],
18+
["punctuation", ":"],
19+
["php", [
20+
["delimiter", "<?php"],
21+
["keyword", "echo"],
22+
["punctuation", "("],
23+
["number", "80"],
24+
["operator", "/"],
25+
["function", ["count"]],
26+
["punctuation", "("],
27+
["variable", "$images"],
28+
["punctuation", ")"],
29+
["punctuation", ")"],
30+
["delimiter", "?>"]
31+
]],
32+
"%"
33+
]],
34+
["punctuation", "\""]
35+
]]
36+
]],
37+
["punctuation", "/>"]
38+
]]
39+
]
40+
41+
----------------------------------------------------
42+
43+
Checks for #2008 where a part of markup templating's placeholder was tokenized as `number` by CSS Extras.

tests/languages/php!+php-extras/scope_feature.test

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@ parent::baz()
99
["keyword", "static"],
1010
["punctuation", "::"]
1111
]],
12-
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
12+
["function", ["foo"]],
13+
["punctuation", "("],
14+
["punctuation", ")"],
15+
1316
["scope", [
1417
["keyword", "self"],
1518
["punctuation", "::"]
1619
]],
17-
["function", "bar"], ["punctuation", "("], ["punctuation", ")"],
20+
["function", ["bar"]],
21+
["punctuation", "("],
22+
["punctuation", ")"],
23+
1824
["scope", [
1925
["keyword", "parent"],
2026
["punctuation", "::"]
2127
]],
22-
["function", "baz"], ["punctuation", "("], ["punctuation", ")"]
28+
["function", ["baz"]],
29+
["punctuation", "("],
30+
["punctuation", ")"]
2331
]
2432

2533
----------------------------------------------------
2634

27-
Checks for scopes.
35+
Checks for scopes.

tests/languages/php/argument-name_feature.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ foo(
66
----------------------------------------------------
77

88
[
9-
["function", "foo"],
9+
["function", ["foo"]],
1010
["punctuation", "("],
11+
1112
["argument-name", "a"],
1213
["punctuation", ":"],
1314
["string", "'bar'"],
1415
["punctuation", ","],
16+
1517
["argument-name", "qux"],
1618
["punctuation", ":"],
1719
["string", "'baz'"],
20+
1821
["punctuation", ")"],
1922
["punctuation", ";"]
2023
]
2124

2225
----------------------------------------------------
2326

24-
Checks for named arguments.
27+
Checks for named arguments.

tests/languages/php/class-name_feature.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Foo extends \Package\Bar implements App\Baz {}
3232

3333
["class-name", "Foo"],
3434
["operator", "::"],
35-
["function", "bar"],
35+
["function", ["bar"]],
3636
["punctuation", "("],
3737
["punctuation", ")"],
3838
["punctuation", ";"],
@@ -42,7 +42,7 @@ class Foo extends \Package\Bar implements App\Baz {}
4242
"Foo"
4343
]],
4444
["operator", "::"],
45-
["function", "bar"],
45+
["function", ["bar"]],
4646
["punctuation", "("],
4747
["punctuation", ")"],
4848
["punctuation", ";"],
@@ -54,7 +54,7 @@ class Foo extends \Package\Bar implements App\Baz {}
5454
"Foo"
5555
]],
5656
["operator", "::"],
57-
["function", "bar"],
57+
["function", ["bar"]],
5858
["punctuation", "("],
5959
["punctuation", ")"],
6060
["punctuation", ";"],

0 commit comments

Comments
 (0)