Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP: Fixed functions with namespaces #2889

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/prism-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@
}
],
'constant': constant,
'function': /\b\w+(?=\s*\()/,
'function': {
pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
lookbehind: true,
inside: {
'punctuation': /\\/
}
},
'property': {
pattern: /(->\s*)\w+/,
lookbehind: true
Expand Down
2 changes: 1 addition & 1 deletion components/prism-php.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 93 additions & 8 deletions tests/languages/latte/delimiter_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,102 @@ line}
----------------------------------------------------

[
["latte", [["ld", [["punctuation", "{"], ["tag", "aa"]]], ["rd", [["punctuation", "}"]]]]],
["latte", [["ld", [["punctuation", "{/"], ["tag", "aa"]]], ["rd", [["punctuation", "}"]]]]],
["latte", [["ld", [["punctuation", "{"]]], ["php", [["operator", "/"]]], ["rd", [["punctuation", "}"]]]]],
["latte", [
["ld", [
["punctuation", "{"],
["tag", "aa"]
]],
["rd", [
["punctuation", "}"]
]]
]],

["latte", [
["ld", [
["punctuation", "{/"],
["tag", "aa"]
]],
["rd", [
["punctuation", "}"]
]]
]],

["latte", [
["ld", [
["punctuation", "{"]
]],
["php", [
["operator", "/"]
]],
["rd", [
["punctuation", "}"]
]]
]],

"\r\n{",
["latte", [["ld", [["punctuation", "{"], ["tag", "aa"]]], ["rd", [["punctuation", "}"]]]]],
["latte", [
["ld", [
["punctuation", "{"],
["tag", "aa"]
]],
["rd", [
["punctuation", "}"]
]]
]],
"}\r\n",
["latte", [["ld", [["punctuation", "{"]]], ["php", [["number", "10"]]], ["rd", [["punctuation", "}"]]]]],
["latte", [["ld", [["punctuation", "{"], ["tag", "="]]], ["php", [["number", "10"]]], ["rd", [["punctuation", "}"]]]]],
["latte", [["ld", [["punctuation", "{"]]], ["php", [["function", "test"], ["punctuation", "("], ["punctuation", ")"]]], ["rd", [["punctuation", "}"]]]]],

["latte", [
["ld", [
["punctuation", "{"]
]],
["php", [
["number", "10"]
]],
["rd", [
["punctuation", "}"]
]]
]],

["latte", [
["ld", [
["punctuation", "{"],
["tag", "="]
]],
["php", [
["number", "10"]
]],
["rd", [
["punctuation", "}"]
]]
]],

["latte", [
["ld", [
["punctuation", "{"]
]],
["php", [
["function", ["test"]],
["punctuation", "("],
["punctuation", ")"]
]],
["rd", [
["punctuation", "}"]
]]
]],

"\r\n{'no'}\r\n{\"no\"}\r\n{ no }\r\n",
["latte", [["ld", [["punctuation", "{"], ["tag", "multi"]]], ["php", ["line"]], ["rd", [["punctuation", "}"]]]]]

["latte", [
["ld", [
["punctuation", "{"],
["tag", "multi"]
]],

["php", ["line"]],
["rd", [
["punctuation", "}"]
]]
]]
]

----------------------------------------------------
Expand Down
86 changes: 43 additions & 43 deletions tests/languages/php!+css-extras/issue2008.test
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
<img style="width:<?php echo (80 / count($images)) ?>%"/>

----------------------------------------------------

[
["tag", [
["tag", [
["punctuation", "<"],
"img"
]],
["special-attr", [
["attr-name", "style"],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
["value", [
["property", "width"],
["punctuation", ":"],
["php", [
["delimiter", "<?php"],
["keyword", "echo"],
["punctuation", "("],
["number", "80"],
["operator", "/"],
["function", "count"],
["punctuation", "("],
["variable", "$images"],
["punctuation", ")"],
["punctuation", ")"],
["delimiter", "?>"]
]],
"%"
]],
["punctuation", "\""]
]]
]],
["punctuation", "/>"]
]]
]

----------------------------------------------------

Checks for #2008 where a part of markup templating's placeholder was tokenized as `number` by CSS Extras.
<img style="width:<?php echo (80 / count($images)) ?>%"/>
----------------------------------------------------
[
["tag", [
["tag", [
["punctuation", "<"],
"img"
]],
["special-attr", [
["attr-name", "style"],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
["value", [
["property", "width"],
["punctuation", ":"],
["php", [
["delimiter", "<?php"],
["keyword", "echo"],
["punctuation", "("],
["number", "80"],
["operator", "/"],
["function", ["count"]],
["punctuation", "("],
["variable", "$images"],
["punctuation", ")"],
["punctuation", ")"],
["delimiter", "?>"]
]],
"%"
]],
["punctuation", "\""]
]]
]],
["punctuation", "/>"]
]]
]
----------------------------------------------------
Checks for #2008 where a part of markup templating's placeholder was tokenized as `number` by CSS Extras.
16 changes: 12 additions & 4 deletions tests/languages/php!+php-extras/scope_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ parent::baz()
["keyword", "static"],
["punctuation", "::"]
]],
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
["function", ["foo"]],
["punctuation", "("],
["punctuation", ")"],

["scope", [
["keyword", "self"],
["punctuation", "::"]
]],
["function", "bar"], ["punctuation", "("], ["punctuation", ")"],
["function", ["bar"]],
["punctuation", "("],
["punctuation", ")"],

["scope", [
["keyword", "parent"],
["punctuation", "::"]
]],
["function", "baz"], ["punctuation", "("], ["punctuation", ")"]
["function", ["baz"]],
["punctuation", "("],
["punctuation", ")"]
]

----------------------------------------------------

Checks for scopes.
Checks for scopes.
7 changes: 5 additions & 2 deletions tests/languages/php/argument-name_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ foo(
----------------------------------------------------

[
["function", "foo"],
["function", ["foo"]],
["punctuation", "("],

["argument-name", "a"],
["punctuation", ":"],
["string", "'bar'"],
["punctuation", ","],

["argument-name", "qux"],
["punctuation", ":"],
["string", "'baz'"],

["punctuation", ")"],
["punctuation", ";"]
]

----------------------------------------------------

Checks for named arguments.
Checks for named arguments.
6 changes: 3 additions & 3 deletions tests/languages/php/class-name_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Foo extends \Package\Bar implements App\Baz {}

["class-name", "Foo"],
["operator", "::"],
["function", "bar"],
["function", ["bar"]],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
Expand All @@ -42,7 +42,7 @@ class Foo extends \Package\Bar implements App\Baz {}
"Foo"
]],
["operator", "::"],
["function", "bar"],
["function", ["bar"]],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
Expand All @@ -54,7 +54,7 @@ class Foo extends \Package\Bar implements App\Baz {}
"Foo"
]],
["operator", "::"],
["function", "bar"],
["function", ["bar"]],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ";"],
Expand Down
Loading