From 3e078d25ab05c3818f5f13b60969753f0668fd96 Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Thu, 1 Oct 2020 11:19:56 +0200 Subject: [PATCH 01/11] feature: support for PHP 7.4 (typehint, return types) fix: `Foo::bar` Foo matched as class name fix: `new self` self matched as keyword instead of class name fix: `use function` is matched as package --- components/prism-php.js | 37 +++++++++++++++++++-- components/prism-php.min.js | 2 +- tests/languages/php/class-name_feature.test | 34 +++++++++++++++++++ tests/languages/php/keyword_feature.test | 7 ++-- tests/languages/php/package_feature.test | 12 +++++++ tests/languages/php/type_feature.test | 29 ++++++++++++++++ 6 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 tests/languages/php/class-name_feature.test create mode 100644 tests/languages/php/type_feature.test diff --git a/components/prism-php.js b/components/prism-php.js index 19bca937c6..63f4abaf7f 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -12,7 +12,7 @@ */ (function (Prism) { Prism.languages.php = Prism.languages.extend('clike', { - 'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|new|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i, + 'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i, 'boolean': { pattern: /\b(?:false|true)\b/i, alias: 'constant' @@ -24,6 +24,13 @@ 'comment': { pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, lookbehind: true + }, + 'class-name': { + pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new\s+(?!self))\s+|\bcatch\s+\()[a-zA-Z_][\w\\]+/i, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } } }); @@ -42,14 +49,19 @@ } }); - Prism.languages.insertBefore('php', 'keyword', { + // Must be defined before class-name (because primitive types must be matched before class names in function typehint) + Prism.languages.insertBefore('php', 'class-name', { 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { - pattern: /(\\|namespace\s+|use\s+)[\w\\]+/, + pattern: /(\\|namespace\s+|use\s+(function\s+)*)[a-zA-Z_][\w\\]+/, lookbehind: true, inside: { punctuation: /\\/ } + }, + 'type': { + pattern: /(bool|boolean|int|integer|float|string|object|void|array|mixed)(?!_)/, + greedy: !0 } }); @@ -114,6 +126,25 @@ // The different types of PHP strings "replace" the C-like standard string delete Prism.languages.php['string']; + Prism.languages.insertBefore('php', 'class-name', { + 'class-static-call': { + pattern: /[a-zA-Z_][\w\\]+(?=\:\:)/, + greedy: !0, + alias: 'class-name' + }, + 'class-type-hint': { + pattern: /[a-zA-Z_][\w\\]+(?=\s*\$)/, + greedy: !0, + alias: 'class-name' + }, + 'class-return-type': { + pattern: /(\)\s*\:\s*\?*\s*)[a-zA-Z_][\w\\]+/, + greedy: !0, + alias: 'class-name', + lookbehind: true + } + }); + Prism.hooks.add('before-tokenize', function(env) { if (!/<\?/.test(env.code)) { return; diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 63caeeadf7..7e973db72a 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(n){n.languages.php=n.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|new|or|parent|print|private|protected|public|require|require_once|return|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0}}),n.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),n.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),n.languages.insertBefore("php","keyword",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(\\|namespace\s+|use\s+)[\w\\]+/,lookbehind:!0,inside:{punctuation:/\\/}}}),n.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:n.languages.php};n.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete n.languages.php.string,n.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){n.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),n.hooks.add("after-tokenize",function(e){n.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(a){a.languages.php=a.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new\s+(?!self))\s+|\bcatch\s+\()[a-zA-Z_][\w\\]+/i,lookbehind:!0,inside:{punctuation:/\\/}}}),a.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),a.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),a.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(\\|namespace\s+|use\s+(function\s+)*)[a-zA-Z_][\w\\]+/,lookbehind:!0,inside:{punctuation:/\\/}},type:{pattern:/(bool|boolean|int|integer|float|string|object|void|array|mixed)(?!_)/,greedy:!0}}),a.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete a.languages.php.string,a.languages.insertBefore("php","class-name",{"class-static-call":{pattern:/[a-zA-Z_][\w\\]+(?=\:\:)/,greedy:!0,alias:"class-name"},"class-type-hint":{pattern:/[a-zA-Z_][\w\\]+(?=\s*\$)/,greedy:!0,alias:"class-name"},"class-return-type":{pattern:/(\)\s*\:\s*\?*\s*)[a-zA-Z_][\w\\]+/,greedy:!0,alias:"class-name",lookbehind:!0}}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file diff --git a/tests/languages/php/class-name_feature.test b/tests/languages/php/class-name_feature.test new file mode 100644 index 0000000000..53dd8cfa97 --- /dev/null +++ b/tests/languages/php/class-name_feature.test @@ -0,0 +1,34 @@ +Foo::bar(); +(Foo $variable) +): Foo +): ?Foo + +---------------------------------------------------- + +[ + ["class-name", ["Foo"]], + ["punctuation", ":"], + ["punctuation", ":"], + ["function", "foo"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["punctuation", "("], + ["class-name", ["Foo"]], + ["variable", "$variable"], + ["punctuation", ")"], + + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", ["Foo"]], + + ["punctuation", ")"], + ["punctuation", ":"], + ["operator", "?"], + ["class-name", ["Foo"]] +] + +---------------------------------------------------- + +Checks for class names. \ No newline at end of file diff --git a/tests/languages/php/keyword_feature.test b/tests/languages/php/keyword_feature.test index 41b72b7f14..917567538d 100644 --- a/tests/languages/php/keyword_feature.test +++ b/tests/languages/php/keyword_feature.test @@ -44,7 +44,6 @@ insteadof interface; isset list -match namespace; new; or @@ -56,6 +55,8 @@ public require require_once return +self +new self static switch throw @@ -117,7 +118,6 @@ yield ["keyword", "interface"], ["punctuation", ";"], ["keyword", "isset"], ["keyword", "list"], - ["keyword", "match"], ["keyword", "namespace"], ["punctuation", ";"], ["keyword", "new"], ["punctuation", ";"], ["keyword", "or"], @@ -129,6 +129,9 @@ yield ["keyword", "require"], ["keyword", "require_once"], ["keyword", "return"], + ["keyword", "self"], + ["keyword", "new"], + ["keyword", "self"], ["keyword", "static"], ["keyword", "switch"], ["keyword", "throw"], diff --git a/tests/languages/php/package_feature.test b/tests/languages/php/package_feature.test index e1d3e5f25c..5330036fe9 100644 --- a/tests/languages/php/package_feature.test +++ b/tests/languages/php/package_feature.test @@ -2,6 +2,8 @@ namespace \foo namespace \foo\bar\baz use \foo use \foo\bar\baz +use function \foo +use function \foo\bar\baz ---------------------------------------------------- @@ -17,6 +19,16 @@ use \foo\bar\baz ["keyword", "use"], ["package", [["punctuation", "\\"], "foo"]], ["keyword", "use"], + ["package", [ + ["punctuation", "\\"], "foo", + ["punctuation", "\\"], "bar", + ["punctuation", "\\"], "baz" + ]], + ["keyword", "use"], + ["keyword", "function"], + ["package", [["punctuation", "\\"], "foo"]], + ["keyword", "use"], + ["keyword", "function"], ["package", [ ["punctuation", "\\"], "foo", ["punctuation", "\\"], "bar", diff --git a/tests/languages/php/type_feature.test b/tests/languages/php/type_feature.test new file mode 100644 index 0000000000..26ca1df6f8 --- /dev/null +++ b/tests/languages/php/type_feature.test @@ -0,0 +1,29 @@ +bool +boolean +int +integer +float +string +object +void +array +mixed + +---------------------------------------------------- + +[ + ["type", "bool"], + ["type", "boolean"], + ["type", "int"], + ["type", "integer"], + ["type", "float"], + ["type", "string"], + ["type", "object"], + ["type", "void"], + ["type", "array"], + ["type", "mixed"] +] + +---------------------------------------------------- + +Checks for types. \ No newline at end of file From cd9d38b3b506296063f2371236184df674e3510d Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Fri, 2 Oct 2020 16:38:10 +0200 Subject: [PATCH 02/11] fix: !0 changed to true feature: class name / namespace (package) can not begin with number feature: added binary and underscore number format feature: added operators `::`, `->`, `=>`, `<=>`, `...`, and some assignment operators fix: moved `.` from punctuation to operators (concatenation operator) feature: for `type` added subtypes `type-casting`, `type-hint`, `return-type` feature: added backtick string quoted string (shell exec) feature: for keywords `parent`, `self` and `static` added subtype `static-context` when a static prop/const/method accessed on them feature: for class name added subtype `class-name-fully-qualified` when class name is fully qualified feature: for class name added subtype `static-context` when a static prop/const/method accessed on it --- components/prism-php.js | 101 +++++++++++++---- components/prism-php.min.js | 2 +- tests/languages/latte/html_feature.test | 8 +- tests/languages/latte/n-attr_feature.test | 4 +- tests/languages/php/class-name_feature.test | 104 ++++++++++++++++-- tests/languages/php/keyword_feature.test | 15 ++- tests/languages/php/number_feature.test | 27 +++++ tests/languages/php/operators_feature.test | 91 +++++++++++++++ tests/languages/php/package_feature.test | 3 + tests/languages/php/property_feature.test | 6 +- tests/languages/php/punctuation_feature.test | 27 +++++ .../php/string-interpolation_feature.test | 12 +- tests/languages/php/string_feature.test | 5 +- tests/languages/php/type_feature.test | 37 ++++++- 14 files changed, 389 insertions(+), 53 deletions(-) create mode 100644 tests/languages/php/number_feature.test create mode 100644 tests/languages/php/operators_feature.test create mode 100644 tests/languages/php/punctuation_feature.test diff --git a/components/prism-php.js b/components/prism-php.js index 63f4abaf7f..000e4663b8 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -26,12 +26,12 @@ lookbehind: true }, 'class-name': { - pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new\s+(?!self))\s+|\bcatch\s+\()[a-zA-Z_][\w\\]+/i, + pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_][\w]*(?!\\)\b/i, lookbehind: true, - inside: { - 'punctuation': /\\/ - } - } + }, + 'number': /\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i, + 'operator': /|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/, + 'punctuation': /[{}\[\](),:;]/ }); Prism.languages.insertBefore('php', 'string', { @@ -53,15 +53,29 @@ Prism.languages.insertBefore('php', 'class-name', { 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { - pattern: /(\\|namespace\s+|use\s+(function\s+)*)[a-zA-Z_][\w\\]+/, + pattern: /(namespace\s+|use\s+(function\s+)?)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, lookbehind: true, inside: { punctuation: /\\/ } }, + 'type type-casting': { + pattern: /(?<=\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i, + greedy: true + }, + 'type type-hint': { + pattern: /(?<=[(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i, + greedy: true, + lookbehind: true + }, + 'type return-type': { + pattern: /(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i, + greedy: true, + lookbehind: true + }, 'type': { - pattern: /(bool|boolean|int|integer|float|string|object|void|array|mixed)(?!_)/, - greedy: !0 + pattern: /\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i, + greedy: true } }); @@ -109,6 +123,11 @@ 'interpolation': string_interpolation // See below } }, + 'backtick-quoted-string': { + pattern: /`(?:\\[\s\S]|[^\\`])*`/, + greedy: true, + alias: 'string' + }, 'single-quoted-string': { pattern: /'(?:\\[\s\S]|[^\\'])*'/, greedy: true, @@ -126,21 +145,57 @@ // The different types of PHP strings "replace" the C-like standard string delete Prism.languages.php['string']; - Prism.languages.insertBefore('php', 'class-name', { - 'class-static-call': { - pattern: /[a-zA-Z_][\w\\]+(?=\:\:)/, - greedy: !0, - alias: 'class-name' - }, - 'class-type-hint': { - pattern: /[a-zA-Z_][\w\\]+(?=\s*\$)/, - greedy: !0, - alias: 'class-name' - }, - 'class-return-type': { - pattern: /(\)\s*\:\s*\?*\s*)[a-zA-Z_][\w\\]+/, - greedy: !0, - alias: 'class-name', + Prism.languages.insertBefore('php', 'keyword', { + 'keyword static-context': { + pattern: /\b(parent|self|static)(?=\s*::)/i, + greedy: true + } + }); + + Prism.languages.insertBefore('php', 'boolean', { + 'class-name class-name-fully-qualified': { + pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + greedy: true, + inside: { + punctuation: /\\/ + }, + lookbehind: true + }, + 'class-name static-context': { + pattern: /\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*::)/i, + greedy: true, + }, + 'class-name class-name-fully-qualified static-context': { + pattern: /(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i, + greedy: true, + inside: { + punctuation: /\\/ + } + }, + 'class-name type-hint': { + pattern: /([(,?]\s*)\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*\$)/i, + greedy: true, + lookbehind: true + }, + 'class-name class-name-fully-qualified type-hint': { + pattern: /([(,?]\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i, + greedy: true, + inside: { + punctuation: /\\/ + }, + lookbehind: true + }, + 'class-name return-type': { + pattern: /(\)\s*:\s*\?*\s*)\b[a-zA-Z_][\w]*(?!\\)\b/i, + greedy: true, + lookbehind: true + }, + 'class-name class-name-fully-qualified return-type': { + pattern: /(\)\s*:\s*\?*\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + greedy: true, + inside: { + punctuation: /\\/ + }, lookbehind: true } }); diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 7e973db72a..fe0dee768b 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(a){a.languages.php=a.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new\s+(?!self))\s+|\bcatch\s+\()[a-zA-Z_][\w\\]+/i,lookbehind:!0,inside:{punctuation:/\\/}}}),a.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),a.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),a.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(\\|namespace\s+|use\s+(function\s+)*)[a-zA-Z_][\w\\]+/,lookbehind:!0,inside:{punctuation:/\\/}},type:{pattern:/(bool|boolean|int|integer|float|string|object|void|array|mixed)(?!_)/,greedy:!0}}),a.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete a.languages.php.string,a.languages.insertBefore("php","class-name",{"class-static-call":{pattern:/[a-zA-Z_][\w\\]+(?=\:\:)/,greedy:!0,alias:"class-name"},"class-type-hint":{pattern:/[a-zA-Z_][\w\\]+(?=\s*\$)/,greedy:!0,alias:"class-name"},"class-return-type":{pattern:/(\)\s*\:\s*\?*\s*)[a-zA-Z_][\w\\]+/,greedy:!0,alias:"class-name",lookbehind:!0}}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(t){t.languages.php=t.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_][\w]*(?!\\)\b/i,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/}),t.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),t.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),t.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(function\s+)?)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"type type-casting":{pattern:/(?<=\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i,greedy:!0},"type type-hint":{pattern:/(?<=[(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"type return-type":{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,greedy:!0,lookbehind:!0},type:{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}}),t.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"backtick-quoted-string":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,greedy:!0,alias:"string"},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete t.languages.php.string,t.languages.insertBefore("php","keyword",{"keyword static-context":{pattern:/\b(parent|self|static)(?=\s*::)/i,greedy:!0}}),t.languages.insertBefore("php","boolean",{"class-name class-name-fully-qualified":{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name static-context":{pattern:/\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*::)/i,greedy:!0},"class-name class-name-fully-qualified static-context":{pattern:/(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i,greedy:!0,inside:{punctuation:/\\/}},"class-name type-hint":{pattern:/([(,?]\s*)\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified type-hint":{pattern:/([(,?]\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name return-type":{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_][\w]*(?!\\)\b/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified return-type":{pattern:/(\)\s*:\s*\?*\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0}}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file diff --git a/tests/languages/latte/html_feature.test b/tests/languages/latte/html_feature.test index 3047eb0a27..d720492853 100644 --- a/tests/languages/latte/html_feature.test +++ b/tests/languages/latte/html_feature.test @@ -15,20 +15,20 @@ ["tag", [["tag", [["punctuation", "<"], "a"]], ["attr-name", ["href"]], ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["latte", [["ld", [["punctuation", "{"], ["tag", "link"]]], - ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "-"], ["operator", ">"], ["property", "id"]]], + ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["rd", [["punctuation", "}"]]]]], ["punctuation", "\""]]], ["punctuation", ">"]]], - ["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "-"], ["operator", ">"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]], ["tag", [["tag", [["punctuation", ""]]], ["tag", [["tag", [["punctuation", "<"], "a"]], ["attr-name", - [["latte", [["ld", [["punctuation", "{"], ["tag", "if"]]], ["php", [["variable", "$post"], ["operator", "-"], ["operator", ">"], ["property", "id"]]], ["rd", [["punctuation", "}"]]]]], "title"] + [["latte", [["ld", [["punctuation", "{"], ["tag", "if"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["rd", [["punctuation", "}"]]]]], "title"] ], ["attr-value", [["punctuation", "="], ["punctuation", "\""], "ahoj", ["punctuation", "\""]]], ["attr-name", [["latte", [["ld", [["punctuation", "{/"], ["tag", "if"]]], ["rd", [["punctuation", "}"]]]]]]], ["punctuation", ">"]]], - ["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "-"], ["operator", ">"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]], ["tag", [["tag", [["punctuation", ""]]], ["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["boolean", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]], diff --git a/tests/languages/latte/n-attr_feature.test b/tests/languages/latte/n-attr_feature.test index 678f5a4e87..c7e401dac3 100644 --- a/tests/languages/latte/n-attr_feature.test +++ b/tests/languages/latte/n-attr_feature.test @@ -9,13 +9,13 @@ [ ["tag", [["tag", [["punctuation", "<"], "a"]], ["n-attr", [["attr-name", "n:href"], - ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "-"], ["operator", ">"], ["property", "id"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], "link", ["tag", [["tag", [["punctuation", ""]]], ["tag", [["tag", [["punctuation", "<"], "a"]], ["n-attr", [["attr-name", "n:href"], - ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "-"], ["operator", ">"], ["property", "id"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], "link", ["tag", [["tag", [["punctuation", ""]]], diff --git a/tests/languages/php/class-name_feature.test b/tests/languages/php/class-name_feature.test index 53dd8cfa97..964ba29f3b 100644 --- a/tests/languages/php/class-name_feature.test +++ b/tests/languages/php/class-name_feature.test @@ -1,32 +1,122 @@ Foo::bar(); +\Foo::bar(); +\Package\Foo::bar(); + (Foo $variable) +(\Foo $variable) +(\Package\Foo $variable) + ): Foo +): \Foo +): \Package\Foo ): ?Foo +class Foo extends Bar implements Baz + +class Foo extends \Package\Bar implements App\Baz + ---------------------------------------------------- [ - ["class-name", ["Foo"]], - ["punctuation", ":"], - ["punctuation", ":"], - ["function", "foo"], + ["class-name static-context", "Foo"], + ["operator", "::"], + ["function", "bar"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ";"], + ["class-name class-name-fully-qualified static-context", [ + ["punctuation", "\\"], + "Foo" + ]], + ["operator", "::"], + ["function", "bar"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["class-name class-name-fully-qualified static-context", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], + ["operator", "::"], + ["function", "bar"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["punctuation", "("], + ["class-name type-hint", "Foo"], + ["variable", "$variable"], + ["punctuation", ")"], + + ["punctuation", "("], + ["class-name class-name-fully-qualified type-hint", [ + ["punctuation", "\\"], + "Foo" + ]], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", "("], - ["class-name", ["Foo"]], + ["class-name class-name-fully-qualified type-hint", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], ["variable", "$variable"], ["punctuation", ")"], ["punctuation", ")"], ["punctuation", ":"], - ["class-name", ["Foo"]], + ["class-name return-type", "Foo"], + + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name class-name-fully-qualified return-type", [ + ["punctuation", "\\"], + "Foo" + ]], + + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name class-name-fully-qualified return-type", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], ["punctuation", ")"], ["punctuation", ":"], ["operator", "?"], - ["class-name", ["Foo"]] + ["class-name return-type", "Foo"], + + ["keyword", "class"], + ["class-name", "Foo"], + ["keyword", "extends"], + ["class-name", "Bar"], + ["keyword", "implements"], + ["class-name", "Baz"], + + ["keyword", "class"], + ["class-name", "Foo"], + ["keyword", "extends"], + ["class-name class-name-fully-qualified", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Bar" + ]], + ["keyword", "implements"], + ["class-name class-name-fully-qualified", [ + "App", + ["punctuation", "\\"], + "Baz" + ]] ] ---------------------------------------------------- diff --git a/tests/languages/php/keyword_feature.test b/tests/languages/php/keyword_feature.test index 917567538d..fcf8b22c27 100644 --- a/tests/languages/php/keyword_feature.test +++ b/tests/languages/php/keyword_feature.test @@ -1,7 +1,7 @@ __halt_compiler abstract and -array +array() as break callable @@ -48,6 +48,7 @@ namespace; new; or parent +parent:: print private protected @@ -57,7 +58,9 @@ require_once return self new self +self:: static +static:: switch throw trait; @@ -75,7 +78,7 @@ yield ["keyword", "__halt_compiler"], ["keyword", "abstract"], ["keyword", "and"], - ["keyword", "array"], + ["keyword", "array"], ["punctuation", "("], ["punctuation", ")"], ["keyword", "as"], ["keyword", "break"], ["keyword", "callable"], @@ -122,6 +125,7 @@ yield ["keyword", "new"], ["punctuation", ";"], ["keyword", "or"], ["keyword", "parent"], + ["keyword static-context", "parent"], ["operator", "::"], ["keyword", "print"], ["keyword", "private"], ["keyword", "protected"], @@ -130,12 +134,13 @@ yield ["keyword", "require_once"], ["keyword", "return"], ["keyword", "self"], - ["keyword", "new"], - ["keyword", "self"], + ["keyword", "new"], ["keyword", "self"], + ["keyword static-context", "self"], ["operator", "::"], ["keyword", "static"], + ["keyword static-context", "static"], ["operator", "::"], ["keyword", "switch"], ["keyword", "throw"], - ["keyword", "trait"], ["punctuation", ";"], + ["keyword", "trait"], ["punctuation", ";"], ["keyword", "try"], ["keyword", "unset"], ["keyword", "use"], ["punctuation", ";"], diff --git a/tests/languages/php/number_feature.test b/tests/languages/php/number_feature.test new file mode 100644 index 0000000000..850930ea03 --- /dev/null +++ b/tests/languages/php/number_feature.test @@ -0,0 +1,27 @@ +664.6 +107_925_284.88_4 +1e7 +1.2e3 +1E-7 +0b10100111001 +0x539 +0x1A +0123 + +---------------------------------------------------- + +[ + ["number", "664.6"], + ["number", "107_925_284.88_4"], + ["number", "1e7"], + ["number", "1.2e3"], + ["number", "1E-7"], + ["number", "0b10100111001"], + ["number", "0x539"], + ["number", "0x1A"], + ["number", "0123"] +] + +---------------------------------------------------- + +Checks for numbers. \ No newline at end of file diff --git a/tests/languages/php/operators_feature.test b/tests/languages/php/operators_feature.test new file mode 100644 index 0000000000..33aa7d47e4 --- /dev/null +++ b/tests/languages/php/operators_feature.test @@ -0,0 +1,91 @@ +=> +<=> +?? +??= +-> +:: +... +/ +/= +^ +^= +| +|| +|= +% +%= +* +*= +** +**= +& +&& +&= +< +<= +> +>= +. +.= ++ +++ ++= +- +-- +-= +? +~ +== +!= +=== +!== + +---------------------------------------------------- + +[ + ["operator", "=>"], + ["operator", "<=>"], + ["operator", "??"], + ["operator", "??="], + ["operator", "->"], + ["operator", "::"], + ["operator", "..."], + ["operator", "/"], + ["operator", "/="], + ["operator", "^"], + ["operator", "^="], + ["operator", "|"], + ["operator", "||"], + ["operator", "|="], + ["operator", "%"], + ["operator", "%="], + ["operator", "*"], + ["operator", "*="], + ["operator", "**"], + ["operator", "**="], + ["operator", "&"], + ["operator", "&&"], + ["operator", "&="], + ["operator", "<"], + ["operator", "<="], + ["operator", ">"], + ["operator", ">="], + ["operator", "."], + ["operator", ".="], + ["operator", "+"], + ["operator", "++"], + ["operator", "+="], + ["operator", "-"], + ["operator", "--"], + ["operator", "-="], + ["operator", "?"], + ["operator", "~"], + ["operator", "=="], + ["operator", "!="], + ["operator", "==="], + ["operator", "!=="] +] + +---------------------------------------------------- + +Checks for operators. \ No newline at end of file diff --git a/tests/languages/php/package_feature.test b/tests/languages/php/package_feature.test index 5330036fe9..297f3a022e 100644 --- a/tests/languages/php/package_feature.test +++ b/tests/languages/php/package_feature.test @@ -1,3 +1,4 @@ +namespace App namespace \foo namespace \foo\bar\baz use \foo @@ -8,6 +9,8 @@ use function \foo\bar\baz ---------------------------------------------------- [ + ["keyword", "namespace"], + ["package", ["App"]], ["keyword", "namespace"], ["package", [["punctuation", "\\"], "foo"]], ["keyword", "namespace"], diff --git a/tests/languages/php/property_feature.test b/tests/languages/php/property_feature.test index f7790197a5..819e741235 100644 --- a/tests/languages/php/property_feature.test +++ b/tests/languages/php/property_feature.test @@ -5,12 +5,12 @@ $foo->bar->baz [ ["variable", "$variable"], - ["operator", "-"], ["operator", ">"], + ["operator", "->"], ["property", "property"], ["variable", "$foo"], - ["operator", "-"], ["operator", ">"], + ["operator", "->"], ["property", "bar"], - ["operator", "-"], ["operator", ">"], + ["operator", "->"], ["property", "baz"] ] diff --git a/tests/languages/php/punctuation_feature.test b/tests/languages/php/punctuation_feature.test new file mode 100644 index 0000000000..5bedfca843 --- /dev/null +++ b/tests/languages/php/punctuation_feature.test @@ -0,0 +1,27 @@ +{ +} +[ +] +( +) +, +: +; + +---------------------------------------------------- + +[ + ["punctuation", "{"], + ["punctuation", "}"], + ["punctuation", "["], + ["punctuation", "]"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ","], + ["punctuation", ":"], + ["punctuation", ";"] +] + +---------------------------------------------------- + +Checks for punctuation. \ No newline at end of file diff --git a/tests/languages/php/string-interpolation_feature.test b/tests/languages/php/string-interpolation_feature.test index b0d57f894c..122452f41a 100644 --- a/tests/languages/php/string-interpolation_feature.test +++ b/tests/languages/php/string-interpolation_feature.test @@ -33,7 +33,7 @@ FOO_BAR; ]], ["double-quoted-string", [ "\"", - ["interpolation", [["variable", "$foo"], ["operator", "-"], ["operator", ">"], ["property", "bar"]]], + ["interpolation", [["variable", "$foo"], ["operator", "->"], ["property", "bar"]]], "\"" ]], ["double-quoted-string", [ @@ -80,7 +80,7 @@ FOO_BAR; "\"the return value of \\$object->getName(): ", ["interpolation", [ ["punctuation", "{"], ["variable", "$"], ["punctuation", "{"], - ["variable", "$object"], ["operator", "-"], ["operator", ">"], ["function", "getName"], ["punctuation", "("], ["punctuation", ")"], + ["variable", "$object"], ["operator", "->"], ["function", "getName"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", "}"], ["punctuation", "}"] ]], "\"" @@ -89,13 +89,13 @@ FOO_BAR; "\"", ["interpolation", [ ["punctuation", "{"], - ["variable", "$foo"], ["operator", "-"], ["operator", ">"], ["variable", "$bar"], + ["variable", "$foo"], ["operator", "->"], ["variable", "$bar"], ["punctuation", "}"] ]], ", ", ["interpolation", [ ["punctuation", "{"], - ["variable", "$foo"], ["operator", "-"], ["operator", ">"], ["punctuation", "{"], + ["variable", "$foo"], ["operator", "->"], ["punctuation", "{"], ["variable", "$baz"], ["punctuation", "["], ["number", "1"], ["punctuation", "]"], ["punctuation", "}"], ["punctuation", "}"] @@ -108,11 +108,11 @@ FOO_BAR; ]], "\r\nHeredoc strings ", ["interpolation", [ - ["variable", "$also"], ["operator", "-"], ["operator", ">"], ["property", "support"] + ["variable", "$also"], ["operator", "->"], ["property", "support"] ]], ["interpolation", [ ["punctuation", "{"], ["variable", "$"], ["punctuation", "{"], - ["variable", "$string"], ["operator", "-"], ["operator", ">"], ["function", "interpolation"], ["punctuation", "("], ["punctuation", ")"], + ["variable", "$string"], ["operator", "->"], ["function", "interpolation"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", "}"], ["punctuation", "}"] ]], ["delimiter", [ diff --git a/tests/languages/php/string_feature.test b/tests/languages/php/string_feature.test index cac7a947cc..8f46cc67db 100644 --- a/tests/languages/php/string_feature.test +++ b/tests/languages/php/string_feature.test @@ -14,6 +14,8 @@ NOWDOC; string" 'multi-line string' +`multi-line +shell exec string` ---------------------------------------------------- @@ -48,7 +50,8 @@ string' ["double-quoted-string", ["\"https://example.com\""]], ["double-quoted-string", ["\" /* not a comment */ \""]], ["double-quoted-string", ["\"multi-line\r\nstring\""]], - ["single-quoted-string", "'multi-line\r\nstring'"] + ["single-quoted-string", "'multi-line\r\nstring'"], + ["backtick-quoted-string", "`multi-line\r\nshell exec string`"] ] ---------------------------------------------------- diff --git a/tests/languages/php/type_feature.test b/tests/languages/php/type_feature.test index 26ca1df6f8..3ea0db65f4 100644 --- a/tests/languages/php/type_feature.test +++ b/tests/languages/php/type_feature.test @@ -9,6 +9,20 @@ void array mixed +(int) +(string) +(object) +(array) + +): int +) :string +) : object +): ?array +): self +): static + +function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f) + ---------------------------------------------------- [ @@ -21,7 +35,28 @@ mixed ["type", "object"], ["type", "void"], ["type", "array"], - ["type", "mixed"] + ["type", "mixed"], + + ["punctuation", "("], ["type type-casting", "int"], ["punctuation", ")"], + ["punctuation", "("], ["type type-casting", "string"], ["punctuation", ")"], + ["punctuation", "("], ["type type-casting", "object"], ["punctuation", ")"], + ["punctuation", "("], ["type type-casting", "array"], ["punctuation", ")"], + + ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "int"], + ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "string"], + ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "object"], + ["punctuation", ")"], ["punctuation", ":"], ["operator", "?"], ["type return-type", "array"], + ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "self"], + ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "static"], + + ["keyword", "function"], ["function", "foo"], ["punctuation", "("], + ["type type-hint", "int"], ["variable", "$a"], ["punctuation", ","], + ["type type-hint", "string"], ["variable", "$b"], ["punctuation", ","], + ["operator", "?"], ["type type-hint", "object"], ["variable", "$c"], ["punctuation", ","], + ["operator", "?"], ["type type-hint", "array"], ["variable", "$d"], ["punctuation", ","], + ["type type-hint", "self"], ["variable", "$e"], ["punctuation", ","], + ["type type-hint", "static"], ["variable", "$f"], + ["punctuation", ")"] ] ---------------------------------------------------- From a18e8a2ca1ab1783a73e86f962fd5c81115f68ca Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Fri, 2 Oct 2020 18:11:35 +0200 Subject: [PATCH 03/11] fix: non-capturing groups in patterns --- components/prism-php.js | 19 ++++++++++--------- components/prism-php.min.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/components/prism-php.js b/components/prism-php.js index 000e4663b8..b7929c99dc 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -53,18 +53,19 @@ Prism.languages.insertBefore('php', 'class-name', { 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { - pattern: /(namespace\s+|use\s+(function\s+)?)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, lookbehind: true, inside: { punctuation: /\\/ } }, 'type type-casting': { - pattern: /(?<=\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i, - greedy: true + pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i, + greedy: true, + lookbehind: true }, 'type type-hint': { - pattern: /(?<=[(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i, + pattern: /([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i, greedy: true, lookbehind: true }, @@ -147,14 +148,14 @@ Prism.languages.insertBefore('php', 'keyword', { 'keyword static-context': { - pattern: /\b(parent|self|static)(?=\s*::)/i, + pattern: /\b(?:parent|self|static)(?=\s*::)/i, greedy: true } }); Prism.languages.insertBefore('php', 'boolean', { 'class-name class-name-fully-qualified': { - pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, greedy: true, inside: { punctuation: /\\/ @@ -166,7 +167,7 @@ greedy: true, }, 'class-name class-name-fully-qualified static-context': { - pattern: /(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i, + pattern: /(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i, greedy: true, inside: { punctuation: /\\/ @@ -178,7 +179,7 @@ lookbehind: true }, 'class-name class-name-fully-qualified type-hint': { - pattern: /([(,?]\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i, + pattern: /([(,?]\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i, greedy: true, inside: { punctuation: /\\/ @@ -191,7 +192,7 @@ lookbehind: true }, 'class-name class-name-fully-qualified return-type': { - pattern: /(\)\s*:\s*\?*\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + pattern: /(\)\s*:\s*\?*\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, greedy: true, inside: { punctuation: /\\/ diff --git a/components/prism-php.min.js b/components/prism-php.min.js index fe0dee768b..79978c7b4e 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(t){t.languages.php=t.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_][\w]*(?!\\)\b/i,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/}),t.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),t.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),t.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(function\s+)?)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"type type-casting":{pattern:/(?<=\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i,greedy:!0},"type type-hint":{pattern:/(?<=[(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"type return-type":{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,greedy:!0,lookbehind:!0},type:{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}}),t.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"backtick-quoted-string":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,greedy:!0,alias:"string"},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete t.languages.php.string,t.languages.insertBefore("php","keyword",{"keyword static-context":{pattern:/\b(parent|self|static)(?=\s*::)/i,greedy:!0}}),t.languages.insertBefore("php","boolean",{"class-name class-name-fully-qualified":{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name static-context":{pattern:/\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*::)/i,greedy:!0},"class-name class-name-fully-qualified static-context":{pattern:/(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i,greedy:!0,inside:{punctuation:/\\/}},"class-name type-hint":{pattern:/([(,?]\s*)\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified type-hint":{pattern:/([(,?]\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name return-type":{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_][\w]*(?!\\)\b/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified return-type":{pattern:/(\)\s*:\s*\?*\s*)(\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0}}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(t){t.languages.php=t.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_][\w]*(?!\\)\b/i,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/}),t.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),t.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),t.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"type type-casting":{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i,greedy:!0,lookbehind:!0},"type type-hint":{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"type return-type":{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,greedy:!0,lookbehind:!0},type:{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}}),t.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"backtick-quoted-string":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,greedy:!0,alias:"string"},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete t.languages.php.string,t.languages.insertBefore("php","keyword",{"keyword static-context":{pattern:/\b(?:parent|self|static)(?=\s*::)/i,greedy:!0}}),t.languages.insertBefore("php","boolean",{"class-name class-name-fully-qualified":{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name static-context":{pattern:/\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*::)/i,greedy:!0},"class-name class-name-fully-qualified static-context":{pattern:/(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i,greedy:!0,inside:{punctuation:/\\/}},"class-name type-hint":{pattern:/([(,?]\s*)\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified type-hint":{pattern:/([(,?]\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name return-type":{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_][\w]*(?!\\)\b/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified return-type":{pattern:/(\)\s*:\s*\?*\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0}}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file From a0b8ce73f1a6a9bf8c69830c56b3e9c49f6a6649 Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Fri, 2 Oct 2020 18:25:08 +0200 Subject: [PATCH 04/11] fix: nice name pattern supports more names separated by spaces --- tests/pattern-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pattern-tests.js b/tests/pattern-tests.js index cbf1d54eca..5106b964f5 100644 --- a/tests/pattern-tests.js +++ b/tests/pattern-tests.js @@ -291,7 +291,7 @@ function testPatterns(Prism) { }); it('- should have nice names and aliases', function () { - const niceName = /^[a-z][a-z\d]*(?:[-_][a-z\d]+)*$/; + const niceName = /^[a-z][-_a-z\d]*(?: [a-z][-_a-z\d]*)*$/; function testName(name, desc = 'token name') { if (!niceName.test(name)) { assert.fail(`The ${desc} '${name}' does not match ${niceName}.\n\n` From 39b2eaf8dc5cce04add153258a3f83ee0da8ea7f Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Fri, 2 Oct 2020 22:50:10 +0200 Subject: [PATCH 05/11] fix: simple mistakes in patterns fix: use single quotes for token names --- components/prism-php.js | 30 +++++++++++++++--------------- components/prism-php.min.js | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/prism-php.js b/components/prism-php.js index b7929c99dc..d6d96c00c7 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -26,7 +26,7 @@ lookbehind: true }, 'class-name': { - pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_][\w]*(?!\\)\b/i, + pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i, lookbehind: true, }, 'number': /\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i, @@ -53,14 +53,14 @@ Prism.languages.insertBefore('php', 'class-name', { 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { - pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, lookbehind: true, inside: { - punctuation: /\\/ + 'punctuation': /\\/ } }, 'type type-casting': { - pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i, + pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i, greedy: true, lookbehind: true }, @@ -155,47 +155,47 @@ Prism.languages.insertBefore('php', 'boolean', { 'class-name class-name-fully-qualified': { - pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, greedy: true, inside: { - punctuation: /\\/ + 'punctuation': /\\/ }, lookbehind: true }, 'class-name static-context': { - pattern: /\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*::)/i, + pattern: /\b[a-zA-Z_]\w*(?=\s*::)/i, greedy: true, }, 'class-name class-name-fully-qualified static-context': { - pattern: /(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i, + pattern: /(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i, greedy: true, inside: { - punctuation: /\\/ + 'punctuation': /\\/ } }, 'class-name type-hint': { - pattern: /([(,?]\s*)\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*\$)/i, + pattern: /([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i, greedy: true, lookbehind: true }, 'class-name class-name-fully-qualified type-hint': { - pattern: /([(,?]\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i, + pattern: /([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i, greedy: true, inside: { - punctuation: /\\/ + 'punctuation': /\\/ }, lookbehind: true }, 'class-name return-type': { - pattern: /(\)\s*:\s*\?*\s*)\b[a-zA-Z_][\w]*(?!\\)\b/i, + pattern: /(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i, greedy: true, lookbehind: true }, 'class-name class-name-fully-qualified return-type': { - pattern: /(\)\s*:\s*\?*\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i, + pattern: /(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, greedy: true, inside: { - punctuation: /\\/ + 'punctuation': /\\/ }, lookbehind: true } diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 79978c7b4e..749478cc2c 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(t){t.languages.php=t.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_][\w]*(?!\\)\b/i,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/}),t.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),t.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),t.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"type type-casting":{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\())\b(?=\s*\))/i,greedy:!0,lookbehind:!0},"type type-hint":{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"type return-type":{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,greedy:!0,lookbehind:!0},type:{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}}),t.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"backtick-quoted-string":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,greedy:!0,alias:"string"},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete t.languages.php.string,t.languages.insertBefore("php","keyword",{"keyword static-context":{pattern:/\b(?:parent|self|static)(?=\s*::)/i,greedy:!0}}),t.languages.insertBefore("php","boolean",{"class-name class-name-fully-qualified":{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name static-context":{pattern:/\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*::)/i,greedy:!0},"class-name class-name-fully-qualified static-context":{pattern:/(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*::)/i,greedy:!0,inside:{punctuation:/\\/}},"class-name type-hint":{pattern:/([(,?]\s*)\b[a-zA-Z_][\w]*(?!\\)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified type-hint":{pattern:/([(,?]\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)(?=\s*\$)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name return-type":{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_][\w]*(?!\\)\b/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified return-type":{pattern:/(\)\s*:\s*\?*\s*)(?:\\*\b[a-zA-Z_][\w]*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0}}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(t){t.languages.php=t.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/}),t.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),t.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),t.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"type type-casting":{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,greedy:!0,lookbehind:!0},"type type-hint":{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"type return-type":{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,greedy:!0,lookbehind:!0},type:{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}}),t.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"backtick-quoted-string":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,greedy:!0,alias:"string"},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete t.languages.php.string,t.languages.insertBefore("php","keyword",{"keyword static-context":{pattern:/\b(?:parent|self|static)(?=\s*::)/i,greedy:!0}}),t.languages.insertBefore("php","boolean",{"class-name class-name-fully-qualified":{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name static-context":{pattern:/\b[a-zA-Z_]\w*(?=\s*::)/i,greedy:!0},"class-name class-name-fully-qualified static-context":{pattern:/(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i,greedy:!0,inside:{punctuation:/\\/}},"class-name type-hint":{pattern:/([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified type-hint":{pattern:/([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name return-type":{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified return-type":{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0}}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file From 5fe7b7ebac37f13c0729957bec86c2026acfec26 Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Sun, 4 Oct 2020 12:23:12 +0200 Subject: [PATCH 06/11] refactor: removed extension of clike language (everything from clike is overridden) --- components/prism-php.js | 331 ++++++++++++++++++++-------------------- tests/pattern-tests.js | 2 +- 2 files changed, 166 insertions(+), 167 deletions(-) diff --git a/components/prism-php.js b/components/prism-php.js index d6d96c00c7..660b009515 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -1,56 +1,30 @@ /** * Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/ * Modified by Miles Johnson: http://milesj.me + * Rewritten by Tom Pavelec * - * Supports the following: - * - Extends clike syntax - * - Support for PHP 5.3+ (namespaces, traits, generators, etc) - * - Smarter constant and function matching + * Supports PHP 5.3 - 7.4 * * Adds the following new token classes: * constant, delimiter, variable, function, package */ (function (Prism) { - Prism.languages.php = Prism.languages.extend('clike', { - 'keyword': /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i, - 'boolean': { - pattern: /\b(?:false|true)\b/i, - alias: 'constant' - }, - 'constant': [ - /\b[A-Z_][A-Z0-9_]*\b/, - /\b(?:null)\b/i, - ], - 'comment': { - pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, - lookbehind: true - }, - 'class-name': { - pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i, - lookbehind: true, - }, - 'number': /\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i, - 'operator': /|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/, - 'punctuation': /[{}\[\](),:;]/ - }); - - Prism.languages.insertBefore('php', 'string', { - 'shell-comment': { - pattern: /(^|[^\\])#.*/, - lookbehind: true, - alias: 'comment' - } - }); - - Prism.languages.insertBefore('php', 'comment', { + Prism.languages.php = { 'delimiter': { pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i, alias: 'important' - } - }); - - // Must be defined before class-name (because primitive types must be matched before class names in function typehint) - Prism.languages.insertBefore('php', 'class-name', { + }, + 'comment': [ + { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, + lookbehind: true + }, + { + pattern: /(^|[^\\])#.*/, + alias: 'shell-comment', + lookbehind: true + } + ], 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, @@ -59,34 +33,114 @@ 'punctuation': /\\/ } }, - 'type type-casting': { - pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i, - greedy: true, - lookbehind: true - }, - 'type type-hint': { - pattern: /([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i, - greedy: true, - lookbehind: true - }, - 'type return-type': { - pattern: /(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i, - greedy: true, - lookbehind: true - }, - 'type': { - pattern: /\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i, - greedy: true - } - }); - - // Must be defined after the function pattern - Prism.languages.insertBefore('php', 'operator', { + 'type': [ + { + pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i, + alias: 'type-casting', + greedy: true, + lookbehind: true + }, + { + pattern: /([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i, + alias: 'type-hint', + greedy: true, + lookbehind: true + }, + { + pattern: /(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i, + alias: 'return-type', + greedy: true, + lookbehind: true + }, + { + pattern: /\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i, + greedy: true + } + ], + 'keyword': [ + { + pattern: /\b(?:parent|self|static)(?=\s*::)/i, + alias: 'static-context', + greedy: true + }, + /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i + ], + 'class-name': [ + { + pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i, + greedy: true, + lookbehind: true + }, + { + pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, + alias: 'class-name-fully-qualified', + greedy: true, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } + }, + { + pattern: /\b[a-zA-Z_]\w*(?=\s*::)/i, + alias: 'static-context', + greedy: true + }, + { + pattern: /(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i, + alias: ['class-name-fully-qualified', 'static-context'], + greedy: true, + inside: { + 'punctuation': /\\/ + } + }, + { + pattern: /([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i, + alias: 'type-hint', + greedy: true, + lookbehind: true + }, + { + pattern: /([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i, + alias: ['class-name-fully-qualified', 'type-hint'], + greedy: true, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } + }, + { + pattern: /(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i, + alias: 'return-type', + greedy: true, + lookbehind: true + }, + { + pattern: /(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, + alias: ['class-name-fully-qualified', 'return-type'], + greedy: true, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } + } + ], + 'constant': [ + { + pattern: /\b(?:false|true)\b/i, + alias: 'boolean' + }, + /\b[A-Z_][A-Z0-9_]*\b/, + /\b(?:null)\b/i, + ], + 'function': /\w+\s*(?=\()/, 'property': { pattern: /(->)[\w]+/, lookbehind: true - } - }); + }, + 'number': /\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i, + 'operator': /|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/, + 'punctuation': /[{}\[\](),:;]/ + }; var string_interpolation = { pattern: /{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/, @@ -94,111 +148,56 @@ inside: Prism.languages.php }; - Prism.languages.insertBefore('php', 'string', { - 'nowdoc-string': { - pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/, - greedy: true, - alias: 'string', - inside: { - 'delimiter': { - pattern: /^<<<'[^']+'|[a-z_]\w*;$/i, - alias: 'symbol', - inside: { - 'punctuation': /^<<<'?|[';]$/ + Prism.languages.insertBefore('php', 'variable', { + 'string': [ + { + pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/, + alias: 'nowdoc-string', + greedy: true, + inside: { + 'delimiter': { + pattern: /^<<<'[^']+'|[a-z_]\w*;$/i, + alias: 'symbol', + inside: { + 'punctuation': /^<<<'?|[';]$/ + } } } - } - }, - 'heredoc-string': { - pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i, - greedy: true, - alias: 'string', - inside: { - 'delimiter': { - pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i, - alias: 'symbol', - inside: { - 'punctuation': /^<<<"?|[";]$/ - } - }, - 'interpolation': string_interpolation // See below - } - }, - 'backtick-quoted-string': { - pattern: /`(?:\\[\s\S]|[^\\`])*`/, - greedy: true, - alias: 'string' - }, - 'single-quoted-string': { - pattern: /'(?:\\[\s\S]|[^\\'])*'/, - greedy: true, - alias: 'string' - }, - 'double-quoted-string': { - pattern: /"(?:\\[\s\S]|[^\\"])*"/, - greedy: true, - alias: 'string', - inside: { - 'interpolation': string_interpolation // See below - } - } - }); - // The different types of PHP strings "replace" the C-like standard string - delete Prism.languages.php['string']; - - Prism.languages.insertBefore('php', 'keyword', { - 'keyword static-context': { - pattern: /\b(?:parent|self|static)(?=\s*::)/i, - greedy: true - } - }); - - Prism.languages.insertBefore('php', 'boolean', { - 'class-name class-name-fully-qualified': { - pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, - greedy: true, - inside: { - 'punctuation': /\\/ }, - lookbehind: true - }, - 'class-name static-context': { - pattern: /\b[a-zA-Z_]\w*(?=\s*::)/i, - greedy: true, - }, - 'class-name class-name-fully-qualified static-context': { - pattern: /(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i, - greedy: true, - inside: { - 'punctuation': /\\/ - } - }, - 'class-name type-hint': { - pattern: /([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i, - greedy: true, - lookbehind: true - }, - 'class-name class-name-fully-qualified type-hint': { - pattern: /([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i, - greedy: true, - inside: { - 'punctuation': /\\/ + { + pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i, + alias: 'heredoc-string', + greedy: true, + inside: { + 'delimiter': { + pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i, + alias: 'symbol', + inside: { + 'punctuation': /^<<<"?|[";]$/ + } + }, + 'interpolation': string_interpolation // See below + } }, - lookbehind: true - }, - 'class-name return-type': { - pattern: /(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i, - greedy: true, - lookbehind: true - }, - 'class-name class-name-fully-qualified return-type': { - pattern: /(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, - greedy: true, - inside: { - 'punctuation': /\\/ + { + pattern: /`(?:\\[\s\S]|[^\\`])*`/, + alias: 'backtick-quoted-string', + greedy: true }, - lookbehind: true - } + { + pattern: /'(?:\\[\s\S]|[^\\'])*'/, + alias: 'single-quoted-string', + greedy: true + }, + { + pattern: /"(?:\\[\s\S]|[^\\"])*"/, + alias: 'double-quoted-string', + greedy: true, + inside: { + 'interpolation': string_interpolation // See below + } + } + ], }); Prism.hooks.add('before-tokenize', function(env) { diff --git a/tests/pattern-tests.js b/tests/pattern-tests.js index 5106b964f5..cbf1d54eca 100644 --- a/tests/pattern-tests.js +++ b/tests/pattern-tests.js @@ -291,7 +291,7 @@ function testPatterns(Prism) { }); it('- should have nice names and aliases', function () { - const niceName = /^[a-z][-_a-z\d]*(?: [a-z][-_a-z\d]*)*$/; + const niceName = /^[a-z][a-z\d]*(?:[-_][a-z\d]+)*$/; function testName(name, desc = 'token name') { if (!niceName.test(name)) { assert.fail(`The ${desc} '${name}' does not match ${niceName}.\n\n` From 49a0b3dd3fc21d2f1dcc770f8ed0f7b859ef7fc6 Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Sun, 4 Oct 2020 15:08:50 +0200 Subject: [PATCH 07/11] fix: forgotten minified code --- components/prism-php.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 749478cc2c..55d201fde2 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(t){t.languages.php=t.languages.extend("clike",{keyword:/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,boolean:{pattern:/\b(?:false|true)\b/i,alias:"constant"},constant:[/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/}),t.languages.insertBefore("php","string",{"shell-comment":{pattern:/(^|[^\\])#.*/,lookbehind:!0,alias:"comment"}}),t.languages.insertBefore("php","comment",{delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"}}),t.languages.insertBefore("php","class-name",{variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"type type-casting":{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,greedy:!0,lookbehind:!0},"type type-hint":{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,greedy:!0,lookbehind:!0},"type return-type":{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,greedy:!0,lookbehind:!0},type:{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}}),t.languages.insertBefore("php","operator",{property:{pattern:/(->)[\w]+/,lookbehind:!0}});var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","string",{"nowdoc-string":{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},"heredoc-string":{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,greedy:!0,alias:"string",inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},"backtick-quoted-string":{pattern:/`(?:\\[\s\S]|[^\\`])*`/,greedy:!0,alias:"string"},"single-quoted-string":{pattern:/'(?:\\[\s\S]|[^\\'])*'/,greedy:!0,alias:"string"},"double-quoted-string":{pattern:/"(?:\\[\s\S]|[^\\"])*"/,greedy:!0,alias:"string",inside:{interpolation:e}}}),delete t.languages.php.string,t.languages.insertBefore("php","keyword",{"keyword static-context":{pattern:/\b(?:parent|self|static)(?=\s*::)/i,greedy:!0}}),t.languages.insertBefore("php","boolean",{"class-name class-name-fully-qualified":{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name static-context":{pattern:/\b[a-zA-Z_]\w*(?=\s*::)/i,greedy:!0},"class-name class-name-fully-qualified static-context":{pattern:/(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i,greedy:!0,inside:{punctuation:/\\/}},"class-name type-hint":{pattern:/([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified type-hint":{pattern:/([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0},"class-name return-type":{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},"class-name class-name-fully-qualified return-type":{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,greedy:!0,inside:{punctuation:/\\/},lookbehind:!0}}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(t){t.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},{pattern:/(^|[^\\])#.*/,alias:"shell-comment",lookbehind:!0}],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},type:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}],keyword:[{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-zA-Z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file From 253dfad1ce956d74f3e7580349f24d9effa44138 Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Mon, 12 Oct 2020 16:02:15 +0200 Subject: [PATCH 08/11] fix: tests fix: removed A-Z in case insensitive patterns removed: alias shell-comment fix: types handled as keywords --- components/prism-php.js | 45 ++++---- components/prism-php.min.js | 2 +- tests/languages/latte/html_feature.test | 12 +- tests/languages/latte/php_feature.test | 12 +- tests/languages/markup+php/issue1582.test | 46 ++++---- ...hp_with_closing_tag_in_markup_feature.test | 88 +++++++-------- tests/languages/php/boolean_feature.test | 32 +++--- tests/languages/php/class-name_feature.test | 74 ++++++------ tests/languages/php/comment_feature.test | 12 +- tests/languages/php/keyword_feature.test | 6 +- .../languages/php/shell-comment_feature.test | 13 --- .../php/string-interpolation_feature.test | 26 ++--- tests/languages/php/string_feature.test | 16 +-- tests/languages/php/type_feature.test | 105 +++++++++--------- 14 files changed, 240 insertions(+), 249 deletions(-) delete mode 100644 tests/languages/php/shell-comment_feature.test diff --git a/components/prism-php.js b/components/prism-php.js index 660b009515..271b3fd336 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -4,9 +4,6 @@ * Rewritten by Tom Pavelec * * Supports PHP 5.3 - 7.4 - * - * Adds the following new token classes: - * constant, delimiter, variable, function, package */ (function (Prism) { Prism.languages.php = { @@ -15,25 +12,22 @@ alias: 'important' }, 'comment': [ + /\/\*\*\//, { - pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, - lookbehind: true + pattern: /\/\*\*[\s\S]*?\*\//, + alias: 'doc-comment' }, - { - pattern: /(^|[^\\])#.*/, - alias: 'shell-comment', - lookbehind: true - } + /\/\*[\s\S]*?\*\/|\/\/.*|#.*/ ], 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { - pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, + pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, lookbehind: true, inside: { 'punctuation': /\\/ } }, - 'type': [ + 'keyword': [ { pattern: /(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i, alias: 'type-casting', @@ -41,23 +35,22 @@ lookbehind: true }, { - pattern: /([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i, + pattern: /([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i, alias: 'type-hint', greedy: true, lookbehind: true }, { - pattern: /(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i, + pattern: /(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable)\b/i, alias: 'return-type', greedy: true, lookbehind: true }, { - pattern: /\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i, + pattern: /\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i, + alias: 'type-declaration', greedy: true - } - ], - 'keyword': [ + }, { pattern: /\b(?:parent|self|static)(?=\s*::)/i, alias: 'static-context', @@ -67,12 +60,12 @@ ], 'class-name': [ { - pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i, + pattern: /(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-z_]\w*(?!\\)\b/i, greedy: true, lookbehind: true }, { - pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, + pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, alias: 'class-name-fully-qualified', greedy: true, lookbehind: true, @@ -81,12 +74,12 @@ } }, { - pattern: /\b[a-zA-Z_]\w*(?=\s*::)/i, + pattern: /\b[a-z_]\w*(?=\s*::)/i, alias: 'static-context', greedy: true }, { - pattern: /(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i, + pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i, alias: ['class-name-fully-qualified', 'static-context'], greedy: true, inside: { @@ -94,13 +87,13 @@ } }, { - pattern: /([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i, + pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i, alias: 'type-hint', greedy: true, lookbehind: true }, { - pattern: /([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i, + pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i, alias: ['class-name-fully-qualified', 'type-hint'], greedy: true, lookbehind: true, @@ -109,13 +102,13 @@ } }, { - pattern: /(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i, + pattern: /(\)\s*:\s*\?*\s*)\b[a-z_]\w*(?!\\)\b/i, alias: 'return-type', greedy: true, lookbehind: true }, { - pattern: /(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i, + pattern: /(\)\s*:\s*\?*\s*)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, alias: ['class-name-fully-qualified', 'return-type'], greedy: true, lookbehind: true, diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 55d201fde2..66d88f2537 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(t){t.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},{pattern:/(^|[^\\])#.*/,alias:"shell-comment",lookbehind:!0}],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},type:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed)\b/i,greedy:!0}],keyword:[{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-zA-Z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-zA-Z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-zA-Z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-zA-Z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-zA-Z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-zA-Z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-zA-Z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:t.languages.php};t.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),t.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){t.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),t.hooks.add("after-tokenize",function(e){t.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(a){a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[/\/\*\*\//,{pattern:/\/\*\*[\s\S]*?\*\//,alias:"doc-comment"},/\/\*[\s\S]*?\*\/|\/\/.*|#.*/],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},keyword:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i,alias:"type-declaration",greedy:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file diff --git a/tests/languages/latte/html_feature.test b/tests/languages/latte/html_feature.test index d720492853..8614c29655 100644 --- a/tests/languages/latte/html_feature.test +++ b/tests/languages/latte/html_feature.test @@ -31,19 +31,19 @@ ["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]], ["tag", [["tag", [["punctuation", ""]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["boolean", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]], ["tag", [["tag", [["punctuation", "<"], "div"]], - ["n-attr", [["attr-name", "n:attr"], ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["boolean", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]], + ["n-attr", [["attr-name", "n:attr"], ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["single-quoted-string", "''"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "''"]]], ["rd", [["punctuation", "}"]]]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["double-quoted-string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["double-quoted-string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["single-quoted-string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]], ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["comment", "/* \" */"]]], ["rd", [["punctuation", "}"]]]]] ] diff --git a/tests/languages/latte/php_feature.test b/tests/languages/latte/php_feature.test index cc916a469d..6d23c0ec1e 100644 --- a/tests/languages/latte/php_feature.test +++ b/tests/languages/latte/php_feature.test @@ -10,19 +10,19 @@ ---------------------------------------------------- [ - ["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["boolean", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "tag"]]], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["rd", [["punctuation", "}"]]]]], ["tag", [["tag", [["punctuation", "<"], "div"]], ["n-attr", [["attr-name", "n:attr"], - ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["boolean", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["variable", "$a"], ["operator", "="], ["constant", "true"], ["operator", "?"], ["number", "10"], ["operator", "*"], ["number", "5"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["single-quoted-string", "''"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "''"]]], ["rd", [["punctuation", "}"]]]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["double-quoted-string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"\""]]]], ["rd", [["punctuation", "}"]]]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["double-quoted-string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", ["\"ba\\\"r\""]]]], ["rd", [["punctuation", "}"]]]]], - ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["single-quoted-string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]], + ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["string", "'ba\\'z'"]]], ["rd", [["punctuation", "}"]]]]], ["latte", [["ld", [["punctuation", "{"], ["tag", "php"]]], ["php", [["comment", "/* \" */"]]], ["rd", [["punctuation", "}"]]]]], diff --git a/tests/languages/markup+php/issue1582.test b/tests/languages/markup+php/issue1582.test index 255f97e74e..9ed8faec0e 100644 --- a/tests/languages/markup+php/issue1582.test +++ b/tests/languages/markup+php/issue1582.test @@ -1,23 +1,23 @@ -'; - echo PHP_EOL; - ----------------------------------------------------- - -[ - ["php", [ - ["delimiter", "'"], - ["punctuation", ";"], - ["keyword", "echo"], - ["constant", "PHP_EOL"], - ["punctuation", ";"] - ]] -] - ----------------------------------------------------- - -Checks for PHP closing tags '?>' inside of strings. -See #1582 for details. +'; + echo PHP_EOL; + +---------------------------------------------------- + +[ + ["php", [ + ["delimiter", "'"], + ["punctuation", ";"], + ["keyword", "echo"], + ["constant", "PHP_EOL"], + ["punctuation", ";"] + ]] +] + +---------------------------------------------------- + +Checks for PHP closing tags '?>' inside of strings. +See #1582 for details. diff --git a/tests/languages/markup+php/php_with_closing_tag_in_markup_feature.test b/tests/languages/markup+php/php_with_closing_tag_in_markup_feature.test index 8067d7c0b4..c3c5135b8f 100644 --- a/tests/languages/markup+php/php_with_closing_tag_in_markup_feature.test +++ b/tests/languages/markup+php/php_with_closing_tag_in_markup_feature.test @@ -1,44 +1,44 @@ -' + "?>"; /* ?> */ - echo PHP_EOL; - // */ - // ?> - - - ----------------------------------------------------- - -[ - ["php", [ - ["delimiter", "'"], - ["operator", "+"], - ["double-quoted-string", ["\"?>\""]], - ["punctuation", ";"], - ["comment", "/* ?> */"], - ["keyword", "echo"], - ["constant", "PHP_EOL"], - ["punctuation", ";"], - ["comment", "// */"], - ["comment", "// "], - ["delimiter", "?>"] - ]], - - ["php", [ - ["delimiter", ""] - ]] -] - ----------------------------------------------------- - -Checks for PHP closing tags '?>' inside of strings and comments. +' + "?>"; /* ?> */ + echo PHP_EOL; + // */ + // ?> + + + +---------------------------------------------------- + +[ + ["php", [ + ["delimiter", "'"], + ["operator", "+"], + ["string", ["\"?>\""]], + ["punctuation", ";"], + ["comment", "/* ?> */"], + ["keyword", "echo"], + ["constant", "PHP_EOL"], + ["punctuation", ";"], + ["comment", "// */"], + ["comment", "// "], + ["delimiter", "?>"] + ]], + + ["php", [ + ["delimiter", ""] + ]] +] + +---------------------------------------------------- + +Checks for PHP closing tags '?>' inside of strings and comments. diff --git a/tests/languages/php/boolean_feature.test b/tests/languages/php/boolean_feature.test index 55c24bc993..66e0d21a7c 100644 --- a/tests/languages/php/boolean_feature.test +++ b/tests/languages/php/boolean_feature.test @@ -1,17 +1,17 @@ -FALSE -false -TRUE -true - ----------------------------------------------------- - -[ - ["boolean", "FALSE"], - ["boolean", "false"], - ["boolean", "TRUE"], - ["boolean", "true"] -] - ----------------------------------------------------- - +FALSE +false +TRUE +true + +---------------------------------------------------- + +[ + ["constant", "FALSE"], + ["constant", "false"], + ["constant", "TRUE"], + ["constant", "true"] +] + +---------------------------------------------------- + Checks for booleans. \ No newline at end of file diff --git a/tests/languages/php/class-name_feature.test b/tests/languages/php/class-name_feature.test index 964ba29f3b..2f8d8094e4 100644 --- a/tests/languages/php/class-name_feature.test +++ b/tests/languages/php/class-name_feature.test @@ -2,30 +2,26 @@ Foo::bar(); \Foo::bar(); \Package\Foo::bar(); -(Foo $variable) -(\Foo $variable) -(\Package\Foo $variable) +function f(Foo $variable): Foo {} +function f(\Foo $variable): \Foo {} +function f(\Package\Foo $variable): \Package\Foo {} +function f($variable): ?Foo {} -): Foo -): \Foo -): \Package\Foo -): ?Foo +class Foo extends Bar implements Baz {} -class Foo extends Bar implements Baz - -class Foo extends \Package\Bar implements App\Baz +class Foo extends \Package\Bar implements App\Baz {} ---------------------------------------------------- [ - ["class-name static-context", "Foo"], + ["class-name", "Foo"], ["operator", "::"], ["function", "bar"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ";"], - ["class-name class-name-fully-qualified static-context", [ + ["class-name", [ ["punctuation", "\\"], "Foo" ]], @@ -35,7 +31,7 @@ class Foo extends \Package\Bar implements App\Baz ["punctuation", ")"], ["punctuation", ";"], - ["class-name class-name-fully-qualified static-context", [ + ["class-name", [ ["punctuation", "\\"], "Package", ["punctuation", "\\"], @@ -47,53 +43,61 @@ class Foo extends \Package\Bar implements App\Baz ["punctuation", ")"], ["punctuation", ";"], + ["keyword", "function"], + ["function", "f"], ["punctuation", "("], - ["class-name type-hint", "Foo"], + ["class-name", "Foo"], ["variable", "$variable"], ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", "Foo"], + ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], + ["function", "f"], ["punctuation", "("], - ["class-name class-name-fully-qualified type-hint", [ + ["class-name", [ ["punctuation", "\\"], "Foo" ]], ["variable", "$variable"], ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", [ + ["punctuation", "\\"], + "Foo" + ]], + ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], + ["function", "f"], ["punctuation", "("], - ["class-name class-name-fully-qualified type-hint", [ + ["class-name", [ ["punctuation", "\\"], "Package", ["punctuation", "\\"], "Foo" ]], ["variable", "$variable"], - ["punctuation", ")"], - - ["punctuation", ")"], - ["punctuation", ":"], - ["class-name return-type", "Foo"], - - ["punctuation", ")"], - ["punctuation", ":"], - ["class-name class-name-fully-qualified return-type", [ - ["punctuation", "\\"], - "Foo" - ]], - ["punctuation", ")"], ["punctuation", ":"], - ["class-name class-name-fully-qualified return-type", [ + ["class-name", [ ["punctuation", "\\"], "Package", ["punctuation", "\\"], "Foo" ]], + ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["variable", "$variable"], ["punctuation", ")"], ["punctuation", ":"], ["operator", "?"], - ["class-name return-type", "Foo"], + ["class-name", "Foo"], + ["punctuation", "{"], ["punctuation", "}"], ["keyword", "class"], ["class-name", "Foo"], @@ -101,22 +105,24 @@ class Foo extends \Package\Bar implements App\Baz ["class-name", "Bar"], ["keyword", "implements"], ["class-name", "Baz"], + ["punctuation", "{"], ["punctuation", "}"], ["keyword", "class"], ["class-name", "Foo"], ["keyword", "extends"], - ["class-name class-name-fully-qualified", [ + ["class-name", [ ["punctuation", "\\"], "Package", ["punctuation", "\\"], "Bar" ]], ["keyword", "implements"], - ["class-name class-name-fully-qualified", [ + ["class-name", [ "App", ["punctuation", "\\"], "Baz" - ]] + ]], + ["punctuation", "{"], ["punctuation", "}"] ] ---------------------------------------------------- diff --git a/tests/languages/php/comment_feature.test b/tests/languages/php/comment_feature.test index 0db0474557..fcbd3567b0 100644 --- a/tests/languages/php/comment_feature.test +++ b/tests/languages/php/comment_feature.test @@ -1,18 +1,24 @@ // // foobar -/**/ /* foo bar */ /* */ +/**/ +/** doc comment */ +# +# foobar ---------------------------------------------------- [ ["comment", "//"], ["comment", "// foobar"], - ["comment", "/**/"], ["comment", "/* foo\r\nbar */"], - ["comment", "/* */"] + ["comment", "/* */"], + ["comment", "/**/"], + ["comment", "/** doc comment */"], + ["comment", "#"], + ["comment", "# foobar"] ] ---------------------------------------------------- diff --git a/tests/languages/php/keyword_feature.test b/tests/languages/php/keyword_feature.test index fcf8b22c27..9e1f10e19f 100644 --- a/tests/languages/php/keyword_feature.test +++ b/tests/languages/php/keyword_feature.test @@ -125,7 +125,7 @@ yield ["keyword", "new"], ["punctuation", ";"], ["keyword", "or"], ["keyword", "parent"], - ["keyword static-context", "parent"], ["operator", "::"], + ["keyword", "parent"], ["operator", "::"], ["keyword", "print"], ["keyword", "private"], ["keyword", "protected"], @@ -135,9 +135,9 @@ yield ["keyword", "return"], ["keyword", "self"], ["keyword", "new"], ["keyword", "self"], - ["keyword static-context", "self"], ["operator", "::"], + ["keyword", "self"], ["operator", "::"], ["keyword", "static"], - ["keyword static-context", "static"], ["operator", "::"], + ["keyword", "static"], ["operator", "::"], ["keyword", "switch"], ["keyword", "throw"], ["keyword", "trait"], ["punctuation", ";"], diff --git a/tests/languages/php/shell-comment_feature.test b/tests/languages/php/shell-comment_feature.test deleted file mode 100644 index a1f077c8c7..0000000000 --- a/tests/languages/php/shell-comment_feature.test +++ /dev/null @@ -1,13 +0,0 @@ -# -# foobar - ----------------------------------------------------- - -[ - ["shell-comment", "#"], - ["shell-comment", "# foobar"] -] - ----------------------------------------------------- - -Checks for shell-like comments. \ No newline at end of file diff --git a/tests/languages/php/string-interpolation_feature.test b/tests/languages/php/string-interpolation_feature.test index 122452f41a..2c7a0dfad5 100644 --- a/tests/languages/php/string-interpolation_feature.test +++ b/tests/languages/php/string-interpolation_feature.test @@ -17,12 +17,12 @@ FOO_BAR; ---------------------------------------------------- [ - ["double-quoted-string", [ + ["string", [ "\"This ", ["interpolation", [["variable", "$variable"]]], " is interpolated\"" ]], - ["double-quoted-string", [ + ["string", [ "\"", ["interpolation", [["variable", "$foo"], ["punctuation", "["], ["number", "2"], ["punctuation", "]"]]], ", ", @@ -31,34 +31,34 @@ FOO_BAR; ["interpolation", [["variable", "$foo"], ["punctuation", "["], ["variable", "$bar"], ["punctuation", "]"]]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"", ["interpolation", [["variable", "$foo"], ["operator", "->"], ["property", "bar"]]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"More ", ["interpolation", [["punctuation", "{"], ["variable", "$interpolation"], ["punctuation", "}"]]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"", ["interpolation", [ ["punctuation", "{"], - ["variable", "$arr"], ["punctuation", "["], ["single-quoted-string", "'key'"], ["punctuation", "]"], + ["variable", "$arr"], ["punctuation", "["], ["string", "'key'"], ["punctuation", "]"], ["punctuation", "}"] ]], ", ", ["interpolation", [ ["punctuation", "{"], ["variable", "$arr"], - ["punctuation", "["], ["single-quoted-string", "'foo'"], ["punctuation", "]"], + ["punctuation", "["], ["string", "'foo'"], ["punctuation", "]"], ["punctuation", "["], ["number", "3"], ["punctuation", "]"], ["punctuation", "}"] ]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"", ["interpolation", [ ["punctuation", "{"], ["variable", "$"], ["punctuation", "{"], @@ -67,7 +67,7 @@ FOO_BAR; ]], ", but not {\\${\\$name}}\"" ]], - ["double-quoted-string", [ + ["string", [ "\"the return value of getName(): ", ["interpolation", [ ["punctuation", "{"], ["variable", "$"], ["punctuation", "{"], @@ -76,7 +76,7 @@ FOO_BAR; ]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"the return value of \\$object->getName(): ", ["interpolation", [ ["punctuation", "{"], ["variable", "$"], ["punctuation", "{"], @@ -85,7 +85,7 @@ FOO_BAR; ]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"", ["interpolation", [ ["punctuation", "{"], @@ -102,7 +102,7 @@ FOO_BAR; ]], "\"" ]], - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<"], "FOO" ]], @@ -119,7 +119,7 @@ FOO_BAR; "FOO", ["punctuation", ";"] ]] ]], - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<\""], "FOO_BAR", ["punctuation", "\""] ]], diff --git a/tests/languages/php/string_feature.test b/tests/languages/php/string_feature.test index 8f46cc67db..5e5942af9e 100644 --- a/tests/languages/php/string_feature.test +++ b/tests/languages/php/string_feature.test @@ -20,7 +20,7 @@ shell exec string` ---------------------------------------------------- [ - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<"], "FOO_BAR" ]], @@ -29,7 +29,7 @@ shell exec string` "FOO_BAR", ["punctuation", ";"] ]] ]], - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<\""], "FOO", ["punctuation", "\""] ]], @@ -38,7 +38,7 @@ shell exec string` "FOO", ["punctuation", ";"] ]] ]], - ["nowdoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<'"], "NOWDOC", ["punctuation", "'"] ]], @@ -47,11 +47,11 @@ shell exec string` "NOWDOC", ["punctuation", ";"] ]] ]], - ["double-quoted-string", ["\"https://example.com\""]], - ["double-quoted-string", ["\" /* not a comment */ \""]], - ["double-quoted-string", ["\"multi-line\r\nstring\""]], - ["single-quoted-string", "'multi-line\r\nstring'"], - ["backtick-quoted-string", "`multi-line\r\nshell exec string`"] + ["string", ["\"https://example.com\""]], + ["string", ["\" /* not a comment */ \""]], + ["string", ["\"multi-line\r\nstring\""]], + ["string", "'multi-line\r\nstring'"], + ["string", "`multi-line\r\nshell exec string`"] ] ---------------------------------------------------- diff --git a/tests/languages/php/type_feature.test b/tests/languages/php/type_feature.test index 3ea0db65f4..c1d69b97e3 100644 --- a/tests/languages/php/type_feature.test +++ b/tests/languages/php/type_feature.test @@ -1,62 +1,61 @@ -bool -boolean -int -integer -float -string -object -void -array -mixed - -(int) -(string) -(object) -(array) - -): int -) :string -) : object -): ?array -): self -): static - -function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f) +public bool $a; +public boolean $a; +public int $a; +public integer $a; +public float $a; +public string $a; +public object $a; +public array $a; +public mixed $a; + +(int) $a; +(string) $a; +(object) $a; +(array) $a; + +function f(): int {} +function f() :string {} +function f() : object {} +function f(): ?array {} +function f(): self {} +function f(): static {} + +function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f) {} ---------------------------------------------------- [ - ["type", "bool"], - ["type", "boolean"], - ["type", "int"], - ["type", "integer"], - ["type", "float"], - ["type", "string"], - ["type", "object"], - ["type", "void"], - ["type", "array"], - ["type", "mixed"], - - ["punctuation", "("], ["type type-casting", "int"], ["punctuation", ")"], - ["punctuation", "("], ["type type-casting", "string"], ["punctuation", ")"], - ["punctuation", "("], ["type type-casting", "object"], ["punctuation", ")"], - ["punctuation", "("], ["type type-casting", "array"], ["punctuation", ")"], - - ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "int"], - ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "string"], - ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "object"], - ["punctuation", ")"], ["punctuation", ":"], ["operator", "?"], ["type return-type", "array"], - ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "self"], - ["punctuation", ")"], ["punctuation", ":"], ["type return-type", "static"], + ["keyword", "public"], ["keyword", "bool"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "boolean"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "int"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "integer"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "float"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "string"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "object"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "array"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "mixed"], ["variable", "$a"], ["punctuation", ";"], + + ["punctuation", "("], ["keyword", "int"], ["punctuation", ")"], ["variable", "$a"], ["punctuation", ";"], + ["punctuation", "("], ["keyword", "string"], ["punctuation", ")"], ["variable", "$a"], ["punctuation", ";"], + ["punctuation", "("], ["keyword", "object"], ["punctuation", ")"], ["variable", "$a"], ["punctuation", ";"], + ["punctuation", "("], ["keyword", "array"], ["punctuation", ")"], ["variable", "$a"], ["punctuation", ";"], + + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "int"], ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "string"], ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "object"], ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["operator", "?"], ["keyword", "array"], ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "self"], ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "static"], ["punctuation", "{"], ["punctuation", "}"], ["keyword", "function"], ["function", "foo"], ["punctuation", "("], - ["type type-hint", "int"], ["variable", "$a"], ["punctuation", ","], - ["type type-hint", "string"], ["variable", "$b"], ["punctuation", ","], - ["operator", "?"], ["type type-hint", "object"], ["variable", "$c"], ["punctuation", ","], - ["operator", "?"], ["type type-hint", "array"], ["variable", "$d"], ["punctuation", ","], - ["type type-hint", "self"], ["variable", "$e"], ["punctuation", ","], - ["type type-hint", "static"], ["variable", "$f"], - ["punctuation", ")"] + ["keyword", "int"], ["variable", "$a"], ["punctuation", ","], + ["keyword", "string"], ["variable", "$b"], ["punctuation", ","], + ["operator", "?"], ["keyword", "object"], ["variable", "$c"], ["punctuation", ","], + ["operator", "?"], ["keyword", "array"], ["variable", "$d"], ["punctuation", ","], + ["keyword", "self"], ["variable", "$e"], ["punctuation", ","], + ["keyword", "static"], ["variable", "$f"], + ["punctuation", ")"], + ["punctuation", "{"], ["punctuation", "}"] ] ---------------------------------------------------- From 9a61d81eeecfbf2907b578fb6b607247cb7c574e Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Mon, 12 Oct 2020 16:48:04 +0200 Subject: [PATCH 09/11] feat: classname in type declaration --- components/prism-php.js | 13 +++++++++++++ tests/languages/php/class-name_feature.test | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/components/prism-php.js b/components/prism-php.js index 271b3fd336..2785eb01b5 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -73,6 +73,19 @@ 'punctuation': /\\/ } }, + { + pattern: /\b[a-z_]\w*(?=\s*\$)/i, + alias: 'type-declaration', + greedy: true + }, + { + pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i, + alias: ['class-name-fully-qualified', 'type-declaration'], + greedy: true, + inside: { + 'punctuation': /\\/ + } + }, { pattern: /\b[a-z_]\w*(?=\s*::)/i, alias: 'static-context', diff --git a/tests/languages/php/class-name_feature.test b/tests/languages/php/class-name_feature.test index 2f8d8094e4..8693b9adce 100644 --- a/tests/languages/php/class-name_feature.test +++ b/tests/languages/php/class-name_feature.test @@ -1,3 +1,5 @@ +public Foo $a; + Foo::bar(); \Foo::bar(); \Package\Foo::bar(); @@ -14,6 +16,11 @@ class Foo extends \Package\Bar implements App\Baz {} ---------------------------------------------------- [ + ["keyword", "public"], + ["class-name", "Foo"], + ["variable", "$a"], + ["punctuation", ";"], + ["class-name", "Foo"], ["operator", "::"], ["function", "bar"], From 39bbd69f9a55f03149e44a3d6e000f4cf0523f7e Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Mon, 12 Oct 2020 16:57:14 +0200 Subject: [PATCH 10/11] rebase --- components/prism-php.js | 2 +- components/prism-php.min.js | 2 +- tests/languages/php/keyword_feature.test | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/prism-php.js b/components/prism-php.js index 2785eb01b5..64f640643a 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -56,7 +56,7 @@ alias: 'static-context', greedy: true }, - /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i + /\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i ], 'class-name': [ { diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 66d88f2537..be710dae6d 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(a){a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[/\/\*\*\//,{pattern:/\/\*\*[\s\S]*?\*\//,alias:"doc-comment"},/\/\*[\s\S]*?\*\/|\/\/.*|#.*/],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},keyword:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i,alias:"type-declaration",greedy:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(a){a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[/\/\*\*\//,{pattern:/\/\*\*[\s\S]*?\*\//,alias:"doc-comment"},/\/\*[\s\S]*?\*\/|\/\/.*|#.*/],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},keyword:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i,alias:"type-declaration",greedy:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*\$)/i,alias:"type-declaration",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-declaration"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file diff --git a/tests/languages/php/keyword_feature.test b/tests/languages/php/keyword_feature.test index 9e1f10e19f..88d5e2bbbc 100644 --- a/tests/languages/php/keyword_feature.test +++ b/tests/languages/php/keyword_feature.test @@ -45,6 +45,7 @@ interface; isset list namespace; +match new; or parent @@ -122,6 +123,7 @@ yield ["keyword", "isset"], ["keyword", "list"], ["keyword", "namespace"], ["punctuation", ";"], + ["keyword", "match"], ["keyword", "new"], ["punctuation", ";"], ["keyword", "or"], ["keyword", "parent"], From 2f0b21eb5a00a81cc592323c7f8f1ded18d9efb7 Mon Sep 17 00:00:00 2001 From: Tom Pavelec Date: Tue, 13 Oct 2020 09:51:42 +0200 Subject: [PATCH 11/11] fix: test feat: unite comment patterns --- components/prism-php.js | 5 ----- components/prism-php.min.js | 2 +- tests/languages/latte/html_feature.test | 2 +- tests/languages/latte/n-attr_feature.test | 4 ++-- tests/languages/php/property_feature.test | 8 +++++--- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/components/prism-php.js b/components/prism-php.js index 64f640643a..c6607fca3b 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -12,11 +12,6 @@ alias: 'important' }, 'comment': [ - /\/\*\*\//, - { - pattern: /\/\*\*[\s\S]*?\*\//, - alias: 'doc-comment' - }, /\/\*[\s\S]*?\*\/|\/\/.*|#.*/ ], 'variable': /\$+(?:\w+\b|(?={))/i, diff --git a/components/prism-php.min.js b/components/prism-php.min.js index be710dae6d..7ab532e717 100644 --- a/components/prism-php.min.js +++ b/components/prism-php.min.js @@ -1 +1 @@ -!function(a){a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[/\/\*\*\//,{pattern:/\/\*\*[\s\S]*?\*\//,alias:"doc-comment"},/\/\*[\s\S]*?\*\/|\/\/.*|#.*/],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},keyword:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i,alias:"type-declaration",greedy:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*\$)/i,alias:"type-declaration",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-declaration"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file +!function(a){a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:[/\/\*[\s\S]*?\*\/|\/\/.*|#.*/],variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},keyword:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i,alias:"type-declaration",greedy:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},/\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|class|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|final|finally|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i],"class-name":[{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s+\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s+\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*\$)/i,alias:"type-declaration",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-declaration"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*\?*\s*)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\?*\s*)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b/,/\b(?:null)\b/i],function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/|\?\?=?|\.{3}|->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||[?~]|[/^|%*&<>.+-]=?/,punctuation:/[{}\[\](),:;]/};var e={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php};a.languages.insertBefore("php","variable",{string:[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:e}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:e}}]}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); \ No newline at end of file diff --git a/tests/languages/latte/html_feature.test b/tests/languages/latte/html_feature.test index 8614c29655..d6534973bb 100644 --- a/tests/languages/latte/html_feature.test +++ b/tests/languages/latte/html_feature.test @@ -15,7 +15,7 @@ ["tag", [["tag", [["punctuation", "<"], "a"]], ["attr-name", ["href"]], ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["latte", [["ld", [["punctuation", "{"], ["tag", "link"]]], - ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "->"], ["property", "id"]]], + ["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["rd", [["punctuation", "}"]]]]], ["punctuation", "\""]]], ["punctuation", ">"]]], ["latte", [["ld", [["punctuation", "{"]]], ["php", [["variable", "$post"], ["operator", "->"], ["property", "title"]]], ["rd", [["punctuation", "}"]]]]], diff --git a/tests/languages/latte/n-attr_feature.test b/tests/languages/latte/n-attr_feature.test index c7e401dac3..3effa4630c 100644 --- a/tests/languages/latte/n-attr_feature.test +++ b/tests/languages/latte/n-attr_feature.test @@ -9,13 +9,13 @@ [ ["tag", [["tag", [["punctuation", "<"], "a"]], ["n-attr", [["attr-name", "n:href"], - ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], "link", ["tag", [["tag", [["punctuation", ""]]], ["tag", [["tag", [["punctuation", "<"], "a"]], ["n-attr", [["attr-name", "n:href"], - ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], "show ", ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", ["Post", ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], "link", ["tag", [["tag", [["punctuation", ""]]], diff --git a/tests/languages/php/property_feature.test b/tests/languages/php/property_feature.test index 819e741235..031529cb95 100644 --- a/tests/languages/php/property_feature.test +++ b/tests/languages/php/property_feature.test @@ -1,5 +1,5 @@ -$variable->property -$foo->bar->baz +$variable->property; +$foo->bar->baz; ---------------------------------------------------- @@ -7,11 +7,13 @@ $foo->bar->baz ["variable", "$variable"], ["operator", "->"], ["property", "property"], + ["punctuation", ";"], ["variable", "$foo"], ["operator", "->"], ["property", "bar"], ["operator", "->"], - ["property", "baz"] + ["property", "baz"], + ["punctuation", ";"] ] ----------------------------------------------------