Skip to content

Commit

Permalink
PHP: Fixed functions with namespaces (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed May 17, 2021
1 parent 8047118 commit 87d7939
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 73 deletions.
8 changes: 7 additions & 1 deletion components/prism-php.js
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
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
@@ -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
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
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
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

0 comments on commit 87d7939

Please sign in to comment.