From df922d908dd3d77f30fccb287e61b207264df6ec Mon Sep 17 00:00:00 2001 From: Tom Pavelec <46928405+TomPavelec@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:20:59 +0200 Subject: [PATCH] PHP: Added support for PHP 8.0 features (#2591) --- components/prism-php.js | 235 +++++++---- components/prism-php.min.js | 2 +- tests/languages/latte/html_feature.test | 2 +- tests/languages/latte/n-attr_feature.test | 4 +- .../languages/php/argument-name_feature.test | 24 ++ tests/languages/php/array_feature.test | 136 +++++++ tests/languages/php/attribute_feature.test | 364 ++++++++++++++++++ tests/languages/php/class-name_feature.test | 79 +++- tests/languages/php/delimiter_feature.test | 28 ++ tests/languages/php/operators_feature.test | 6 + tests/languages/php/type_feature.test | 23 +- 11 files changed, 817 insertions(+), 86 deletions(-) create mode 100644 tests/languages/php/argument-name_feature.test create mode 100644 tests/languages/php/array_feature.test create mode 100644 tests/languages/php/attribute_feature.test diff --git a/components/prism-php.js b/components/prism-php.js index c6607fca3b..8c6634dc29 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -3,17 +3,28 @@ * Modified by Miles Johnson: http://milesj.me * Rewritten by Tom Pavelec * - * Supports PHP 5.3 - 7.4 + * Supports PHP 5.3 - 8.0 */ (function (Prism) { + var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/; + var constant = [ + { + pattern: /\b(?:false|true)\b/i, + alias: 'boolean' + }, + /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/, + /\b(?:null)\b/i, + ]; + var number = /\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i; + var operator = /|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/; + var punctuation = /[{}\[\](),:;]/; + Prism.languages.php = { 'delimiter': { pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i, alias: 'important' }, - 'comment': [ - /\/\*[\s\S]*?\*\/|\/\/.*|#.*/ - ], + 'comment': comment, 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, @@ -30,22 +41,40 @@ lookbehind: true }, { - pattern: /([(,?]\s*)\b(?:bool|boolean|int|integer|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable)\b(?=\s*\$)/i, + pattern: /([(,?]\s*)\b(?:bool|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\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|callable|iterable)\b/i, + pattern: /([(,?]\s*[a-z0-9_|]\|\s*)(?:null|false)\b(?=\s*\$)/i, + alias: 'type-hint', + greedy: true, + lookbehind: true + }, + { + pattern: /(\)\s*:\s*\??\s*)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i, alias: 'return-type', greedy: true, lookbehind: true }, { - pattern: /\b(?:bool|boolean|int|integer|float|string|object|void|array(?!\s*\()|mixed|iterable)\b/i, + pattern: /(\)\s*:\s*\??\s*[a-z0-9_|]\|\s*)(?:null|false)\b/i, + alias: 'return-type', + greedy: true, + lookbehind: true + }, + { + pattern: /\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i, alias: 'type-declaration', greedy: true }, + { + pattern: /(\|\s*)(?:null|false)\b/i, + alias: 'type-declaration', + greedy: true, + lookbehind: true + }, { pattern: /\b(?:parent|self|static)(?=\s*::)/i, alias: 'static-context', @@ -53,14 +82,41 @@ }, /\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 ], + 'argument-name': /\b[a-z_]\w*(?=\s*:(?!:))/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, + 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: /(\|\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-z_]\w*)+\b(?!\\)/i, + pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i, + greedy: true + }, + { + pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i, + alias: 'class-name-fully-qualified', + greedy: true, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } + }, + { + pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i, + alias: 'class-name-fully-qualified', + greedy: true, + inside: { + 'punctuation': /\\/ + } + }, + { + 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, @@ -110,13 +166,13 @@ } }, { - pattern: /(\)\s*:\s*\?*\s*)\b[a-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-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, @@ -125,22 +181,15 @@ } } ], - 'constant': [ - { - pattern: /\b(?:false|true)\b/i, - alias: 'boolean' - }, - /\b[A-Z_][A-Z0-9_]*\b/, - /\b(?:null)\b/i, - ], + 'constant': constant, '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': /[{}\[\](),:;]/ + 'number': number, + 'operator': operator, + 'punctuation': punctuation }; var string_interpolation = { @@ -149,56 +198,104 @@ inside: Prism.languages.php }; - 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': /^<<<'?|[';]$/ - } + var string = [ + { + pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/, + alias: 'nowdoc-string', + greedy: true, + 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: true, - inside: { - 'delimiter': { - pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i, - alias: 'symbol', - inside: { - 'punctuation': /^<<<"?|[";]$/ - } - }, - 'interpolation': string_interpolation // See below - } - }, - { - pattern: /`(?:\\[\s\S]|[^\\`])*`/, - alias: 'backtick-quoted-string', - greedy: 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 + } + }, + { + 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 + } + }, + { + pattern: /`(?:\\[\s\S]|[^\\`])*`/, + alias: 'backtick-quoted-string', + greedy: 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.languages.insertBefore('php', 'variable', { + 'string': string, + }); + + Prism.languages.insertBefore('php', 'variable', { + 'attribute': { + pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/mi, + greedy: true, + inside: { + 'attribute-content': { + pattern: /^(#\[)[\s\S]+(?=]$)/, + lookbehind: true, + // inside can appear subset of php + inside: { + 'comment': comment, + 'string': string, + 'attribute-class-name': [ + { + pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i, + alias: 'class-name', + greedy: true, + lookbehind: true + }, + { + pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i, + alias: [ + 'class-name', + 'class-name-fully-qualified' + ], + greedy: true, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } + } + ], + 'constant': constant, + 'number': number, + 'operator': operator, + 'punctuation': punctuation + } + }, + 'delimiter': { + pattern: /^#\[|]$/, + alias: 'punctuation' } } - ], + }, }); Prism.hooks.add('before-tokenize', function(env) { @@ -206,7 +303,7 @@ return; } - var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#)(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig; + var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*[\s\S]*?(?:\*\/|$))*?(?:\?>|$)/ig; Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern); }); diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 7ab532e717..f5b86bf85f 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:[/\/\*[\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){var e=/\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/,t=[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},/\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/,/\b(?:null)\b/i],i=/\b0b[01]+\b|\b0x[\da-f]+\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)*|\B\.\d+)(?:e[+-]?\d+)?/i,n=/|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/,s=/[{}\[\](),:;]/;a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:e,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|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*[a-z0-9_|]\|\s*)(?:null|false)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\??\s*)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*\??\s*[a-z0-9_|]\|\s*)(?:null|false)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i,alias:"type-declaration",greedy:!0},{pattern:/(\|\s*)(?:null|false)\b/i,alias:"type-declaration",greedy:!0,lookbehind:!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],"argument-name":/\b[a-z_]\w*(?=\s*:(?!:))/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:/(\|\s*)\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,greedy:!0},{pattern:/(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,alias:"class-name-fully-qualified",greedy:!0,inside:{punctuation:/\\/}},{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:t,function:/\w+\s*(?=\()/,property:{pattern:/(->)[\w]+/,lookbehind:!0},number:i,operator:n,punctuation:s};var l={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php},r=[{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:l}},{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:l}}];a.languages.insertBefore("php","variable",{string:r}),a.languages.insertBefore("php","variable",{attribute:{pattern:/#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,greedy:!0,inside:{"attribute-content":{pattern:/^(#\[)[\s\S]+(?=]$)/,lookbehind:!0,inside:{comment:e,string:r,"attribute-class-name":[{pattern:/([^:]|^)\b[a-z_]\w*(?!\\)\b/i,alias:"class-name",greedy:!0,lookbehind:!0},{pattern:/([^:]|^)(?:\\?\b[a-z_]\w*)+/i,alias:["class-name","class-name-fully-qualified"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:t,number:i,operator:n,punctuation:s}},delimiter:{pattern:/^#\[|]$/,alias:"punctuation"}}}}),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 d6534973bb..437d0ad944 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", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], + ["php", [["argument-name", "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 3effa4630c..4126431d1b 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", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["argument-name", "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", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], + ["attr-value", [["punctuation", "="], ["punctuation", "\""], ["php", [["argument-name", "Post"], ["punctuation", ":"], ["class-name", "show"], ["variable", "$post"], ["operator", "->"], ["property", "id"]]], ["punctuation", "\""]]]]], ["punctuation", ">"]]], "link", ["tag", [["tag", [["punctuation", ""]]], diff --git a/tests/languages/php/argument-name_feature.test b/tests/languages/php/argument-name_feature.test new file mode 100644 index 0000000000..8abbca14de --- /dev/null +++ b/tests/languages/php/argument-name_feature.test @@ -0,0 +1,24 @@ +foo( + a: 'bar', + qux: 'baz' +); + +---------------------------------------------------- + +[ + ["function", "foo"], + ["punctuation", "("], + ["argument-name", "a"], + ["punctuation", ":"], + ["string", "'bar'"], + ["punctuation", ","], + ["argument-name", "qux"], + ["punctuation", ":"], + ["string", "'baz'"], + ["punctuation", ")"], + ["punctuation", ";"] +] + +---------------------------------------------------- + +Checks for named arguments. \ No newline at end of file diff --git a/tests/languages/php/array_feature.test b/tests/languages/php/array_feature.test new file mode 100644 index 0000000000..5769920baf --- /dev/null +++ b/tests/languages/php/array_feature.test @@ -0,0 +1,136 @@ +$a = [ + 1 => [0, 1], + 2 => [2, 3], + 3 => [ + [0, 1], + [2, 3] + ] +]; + +$b = array( + Array(1, 2) +); + +$c = [...$a, ...$b, [5, 6]]; + +$d = [0, 1] + [2]; + +[$e] = [2, 3]; + +$f[] = 3; + +$g['key'] = 3; + +---------------------------------------------------- + +[ + ["variable", "$a"], + ["operator", "="], + ["punctuation", "["], + ["number", "1"], + ["operator", "=>"], + ["punctuation", "["], + ["number", "0"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", "]"], + ["punctuation", ","], + ["number", "2"], + ["operator", "=>"], + ["punctuation", "["], + ["number", "2"], + ["punctuation", ","], + ["number", "3"], + ["punctuation", "]"], + ["punctuation", ","], + ["number", "3"], + ["operator", "=>"], + ["punctuation", "["], + ["punctuation", "["], + ["number", "0"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", "]"], + ["punctuation", ","], + ["punctuation", "["], + ["number", "2"], + ["punctuation", ","], + ["number", "3"], + ["punctuation", "]"], + ["punctuation", "]"], + ["punctuation", "]"], + ["punctuation", ";"], + + ["variable", "$b"], + ["operator", "="], + ["keyword", "array"], + ["punctuation", "("], + ["keyword", "Array"], + ["punctuation", "("], + ["number", "1"], + ["punctuation", ","], + ["number", "2"], + ["punctuation", ")"], + ["punctuation", ")"], + ["punctuation", ";"], + + ["variable", "$c"], + ["operator", "="], + ["punctuation", "["], + ["operator", "..."], + ["variable", "$a"], + ["punctuation", ","], + ["operator", "..."], + ["variable", "$b"], + ["punctuation", ","], + ["punctuation", "["], + ["number", "5"], + ["punctuation", ","], + ["number", "6"], + ["punctuation", "]"], + ["punctuation", "]"], + ["punctuation", ";"], + + ["variable", "$d"], + ["operator", "="], + ["punctuation", "["], + ["number", "0"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", "]"], + ["operator", "+"], + ["punctuation", "["], + ["number", "2"], + ["punctuation", "]"], + ["punctuation", ";"], + + ["punctuation", "["], + ["variable", "$e"], + ["punctuation", "]"], + ["operator", "="], + ["punctuation", "["], + ["number", "2"], + ["punctuation", ","], + ["number", "3"], + ["punctuation", "]"], + ["punctuation", ";"], + + ["variable", "$f"], + ["punctuation", "["], + ["punctuation", "]"], + ["operator", "="], + ["number", "3"], + ["punctuation", ";"], + + ["variable", "$g"], + ["punctuation", "["], + ["string", "'key'"], + ["punctuation", "]"], + ["operator", "="], + ["number", "3"], + ["punctuation", ";"] +] + +---------------------------------------------------- + +Checks for arrays. \ No newline at end of file diff --git a/tests/languages/php/attribute_feature.test b/tests/languages/php/attribute_feature.test new file mode 100644 index 0000000000..de9816a803 --- /dev/null +++ b/tests/languages/php/attribute_feature.test @@ -0,0 +1,364 @@ +// #[Foo] + +#[] + +#[ + // something ] + Foo, + /* something + else #[] */ + Bar + # shell comments aren't confusing at all in here +] + +#[Foo([0, 1])] + +#[ + Foo( + [ + 1 => [0, 1], + 2 => [2, 3], + 3 => [ + [0, 1], + [2, 3] + ] + ] + ) +] + +#[Foo] +#[Foo\Bar\Baz] +#[Route(Http::POST, '/products/create', 1)] +#[ + Http\Route(Http::POST, '/products/create', 1), + Foo\Bar\Baz, + AttributeFoo('value') +] + +#[A1(1), A1(2), A2(3)] +class Foo { + public function foo(#[A1(5)] $a, #[A1(6)] $b) { } +} + +$object = new #[A1(7)] class () {}; + +function foo( + #[Attribute] $param1, + $param2 +) {} + +$f1 = #[ExampleAttribute] function () {}; + +$ref = new \ReflectionFunction(#[A1] #[A2] function () { }); + +#[DeprecationReason('reason: ')] +function main() {} + +---------------------------------------------------- + +[ + ["comment", "// #[Foo]"], + "\r\n\r\n#", + ["punctuation", "["], + ["punctuation", "]"], + + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["comment", "// something ]"], + ["attribute-class-name", "Foo"], + ["punctuation", ","], + ["comment", "/* something\r\n\telse #[] */"], + ["attribute-class-name", "Bar"], + ["comment", "# shell comments aren't confusing at all in here"] + ]], + ["delimiter", "]"] + ]], + + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "Foo"], + ["punctuation", "("], + ["punctuation", "["], + ["number", "0"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", "]"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "Foo"], + ["punctuation", "("], + ["punctuation", "["], + ["number", "1"], + ["operator", "=>"], + ["punctuation", "["], + ["number", "0"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", "]"], + ["punctuation", ","], + ["number", "2"], + ["operator", "=>"], + ["punctuation", "["], + ["number", "2"], + ["punctuation", ","], + ["number", "3"], + ["punctuation", "]"], + ["punctuation", ","], + ["number", "3"], + ["operator", "=>"], + ["punctuation", "["], + ["punctuation", "["], + ["number", "0"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", "]"], + ["punctuation", ","], + ["punctuation", "["], + ["number", "2"], + ["punctuation", ","], + ["number", "3"], + ["punctuation", "]"], + ["punctuation", "]"], + ["punctuation", "]"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "Foo"] + ]], + ["delimiter", "]"] + ]], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", [ + "Foo", + ["punctuation", "\\"], + "Bar", + ["punctuation", "\\"], + "Baz" + ]] + ]], + ["delimiter", "]"] + ]], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "Route"], + ["punctuation", "("], + ["attribute-class-name", "Http"], + ["operator", "::"], + ["constant", "POST"], + ["punctuation", ","], + ["string", "'/products/create'"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", [ + "Http", + ["punctuation", "\\"], + "Route" + ]], + ["punctuation", "("], + ["attribute-class-name", "Http"], + ["operator", "::"], + ["constant", "POST"], + ["punctuation", ","], + ["string", "'/products/create'"], + ["punctuation", ","], + ["number", "1"], + ["punctuation", ")"], + ["punctuation", ","], + ["attribute-class-name", [ + "Foo", + ["punctuation", "\\"], + "Bar", + ["punctuation", "\\"], + "Baz" + ]], + ["punctuation", ","], + ["attribute-class-name", "AttributeFoo"], + ["punctuation", "("], + ["string", "'value'"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "A1"], + ["punctuation", "("], + ["number", "1"], + ["punctuation", ")"], + ["punctuation", ","], + ["attribute-class-name", "A1"], + ["punctuation", "("], + ["number", "2"], + ["punctuation", ")"], + ["punctuation", ","], + ["attribute-class-name", "A2"], + ["punctuation", "("], + ["number", "3"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["keyword", "class"], + ["class-name", "Foo"], + ["punctuation", "{"], + ["keyword", "public"], + ["keyword", "function"], + ["function", "foo"], + ["punctuation", "("], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "A1"], + ["punctuation", "("], + ["number", "5"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["variable", "$a"], + ["punctuation", ","], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "A1"], + ["punctuation", "("], + ["number", "6"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["variable", "$b"], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + ["punctuation", "}"], + + ["variable", "$object"], + ["operator", "="], + ["keyword", "new"], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "A1"], + ["punctuation", "("], + ["number", "7"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["keyword", "class"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + ["punctuation", ";"], + + ["keyword", "function"], + ["function", "foo"], + ["punctuation", "("], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "Attribute"] + ]], + ["delimiter", "]"] + ]], + ["variable", "$param1"], + ["punctuation", ","], + ["variable", "$param2"], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + + ["variable", "$f1"], + ["operator", "="], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "ExampleAttribute"] + ]], + ["delimiter", "]"] + ]], + ["keyword", "function"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + ["punctuation", ";"], + + ["variable", "$ref"], + ["operator", "="], + ["keyword", "new"], + ["class-name", [ + ["punctuation", "\\"], + "ReflectionFunction" + ]], + ["punctuation", "("], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "A1"] + ]], + ["delimiter", "]"] + ]], + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "A2"] + ]], + ["delimiter", "]"] + ]], + ["keyword", "function"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + ["punctuation", ")"], + ["punctuation", ";"], + + ["attribute", [ + ["delimiter", "#["], + ["attribute-content", [ + ["attribute-class-name", "DeprecationReason"], + ["punctuation", "("], + ["string", "'reason: '"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["keyword", "function"], + ["function", "main"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"] +] + +---------------------------------------------------- + +Checks for attributes. diff --git a/tests/languages/php/class-name_feature.test b/tests/languages/php/class-name_feature.test index 8693b9adce..8b3b824811 100644 --- a/tests/languages/php/class-name_feature.test +++ b/tests/languages/php/class-name_feature.test @@ -1,14 +1,23 @@ public Foo $a; Foo::bar(); + \Foo::bar(); + \Package\Foo::bar(); function f(Foo $variable): Foo {} + function f(\Foo $variable): \Foo {} + function f(\Package\Foo $variable): \Package\Foo {} + function f($variable): ?Foo {} +function f(Foo|Bar $variable): Foo|Bar {} + +function f(\Package\Foo|\Package\Bar $variable): \Package\Foo|\Package\Bar {} + class Foo extends Bar implements Baz {} class Foo extends \Package\Bar implements App\Baz {} @@ -58,7 +67,8 @@ class Foo extends \Package\Bar implements App\Baz {} ["punctuation", ")"], ["punctuation", ":"], ["class-name", "Foo"], - ["punctuation", "{"], ["punctuation", "}"], + ["punctuation", "{"], + ["punctuation", "}"], ["keyword", "function"], ["function", "f"], @@ -74,7 +84,8 @@ class Foo extends \Package\Bar implements App\Baz {} ["punctuation", "\\"], "Foo" ]], - ["punctuation", "{"], ["punctuation", "}"], + ["punctuation", "{"], + ["punctuation", "}"], ["keyword", "function"], ["function", "f"], @@ -94,7 +105,8 @@ class Foo extends \Package\Bar implements App\Baz {} ["punctuation", "\\"], "Foo" ]], - ["punctuation", "{"], ["punctuation", "}"], + ["punctuation", "{"], + ["punctuation", "}"], ["keyword", "function"], ["function", "f"], @@ -104,7 +116,58 @@ class Foo extends \Package\Bar implements App\Baz {} ["punctuation", ":"], ["operator", "?"], ["class-name", "Foo"], - ["punctuation", "{"], ["punctuation", "}"], + ["punctuation", "{"], + ["punctuation", "}"], + + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["class-name", "Foo"], + ["operator", "|"], + ["class-name", "Bar"], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", "Foo"], + ["operator", "|"], + ["class-name", "Bar"], + ["punctuation", "{"], + ["punctuation", "}"], + + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], + ["operator", "|"], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Bar" + ]], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], + ["operator", "|"], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Bar" + ]], + ["punctuation", "{"], + ["punctuation", "}"], ["keyword", "class"], ["class-name", "Foo"], @@ -112,7 +175,8 @@ class Foo extends \Package\Bar implements App\Baz {} ["class-name", "Bar"], ["keyword", "implements"], ["class-name", "Baz"], - ["punctuation", "{"], ["punctuation", "}"], + ["punctuation", "{"], + ["punctuation", "}"], ["keyword", "class"], ["class-name", "Foo"], @@ -129,9 +193,10 @@ class Foo extends \Package\Bar implements App\Baz {} ["punctuation", "\\"], "Baz" ]], - ["punctuation", "{"], ["punctuation", "}"] + ["punctuation", "{"], + ["punctuation", "}"] ] ---------------------------------------------------- -Checks for class names. \ No newline at end of file +Checks for class names. diff --git a/tests/languages/php/delimiter_feature.test b/tests/languages/php/delimiter_feature.test index f7bd684679..22e613f835 100644 --- a/tests/languages/php/delimiter_feature.test +++ b/tests/languages/php/delimiter_feature.test @@ -2,6 +2,12 @@ +')] +function main() {} +// php is not ended yet +?> + ---------------------------------------------------- [ @@ -17,6 +23,28 @@ ["delimiter", ""] + ]], + + ["php", [ + ["delimiter", "'"], + ["punctuation", ")"] + ]], + ["delimiter", "]"] + ]], + ["keyword", "function"], + ["function", "main"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + ["punctuation", "}"], + ["comment", "// php is not ended yet"], + ["delimiter", "?>"] ]] ] diff --git a/tests/languages/php/operators_feature.test b/tests/languages/php/operators_feature.test index 33aa7d47e4..58bb1f5af2 100644 --- a/tests/languages/php/operators_feature.test +++ b/tests/languages/php/operators_feature.test @@ -3,6 +3,7 @@ ?? ??= -> +?-> :: ... / @@ -32,6 +33,8 @@ += - -- +>> +<< -= ? ~ @@ -48,6 +51,7 @@ ["operator", "??"], ["operator", "??="], ["operator", "->"], + ["operator", "?->"], ["operator", "::"], ["operator", "..."], ["operator", "/"], @@ -77,6 +81,8 @@ ["operator", "+="], ["operator", "-"], ["operator", "--"], + ["operator", ">>"], + ["operator", "<<"], ["operator", "-="], ["operator", "?"], ["operator", "~"], diff --git a/tests/languages/php/type_feature.test b/tests/languages/php/type_feature.test index c1d69b97e3..196110b445 100644 --- a/tests/languages/php/type_feature.test +++ b/tests/languages/php/type_feature.test @@ -1,17 +1,20 @@ 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; +public int|null $a; +public int|false $a; +public false | int $a; (int) $a; (string) $a; (object) $a; (array) $a; +(boolean) $a; +(integer) $a; function f(): int {} function f() :string {} @@ -19,26 +22,31 @@ function f() : object {} function f(): ?array {} function f(): self {} function f(): static {} +function f(): int|null {} +function f(): int|false {} -function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f) {} +function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f, int|null $g) {} ---------------------------------------------------- [ ["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", ";"], + ["keyword", "public"], ["keyword", "int"], ["operator", "|"], ["keyword", "null"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "int"], ["operator", "|"], ["keyword", "false"], ["variable", "$a"], ["punctuation", ";"], + ["keyword", "public"], ["keyword", "false"], ["operator", "|"], ["keyword", "int"], ["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", ";"], + ["punctuation", "("], ["keyword", "boolean"], ["punctuation", ")"], ["variable", "$a"], ["punctuation", ";"], + ["punctuation", "("], ["keyword", "integer"], ["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", "}"], @@ -46,6 +54,8 @@ function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f) {} ["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", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "int"], ["operator", "|"], ["keyword", "null"], ["punctuation", "{"], ["punctuation", "}"], + ["keyword", "function"], ["function", "f"], ["punctuation", "("], ["punctuation", ")"], ["punctuation", ":"], ["keyword", "int"], ["operator", "|"], ["keyword", "false"], ["punctuation", "{"], ["punctuation", "}"], ["keyword", "function"], ["function", "foo"], ["punctuation", "("], ["keyword", "int"], ["variable", "$a"], ["punctuation", ","], @@ -53,7 +63,8 @@ function foo(int $a, string $b, ? object $c, ?array $d, self $e, static $f) {} ["operator", "?"], ["keyword", "object"], ["variable", "$c"], ["punctuation", ","], ["operator", "?"], ["keyword", "array"], ["variable", "$d"], ["punctuation", ","], ["keyword", "self"], ["variable", "$e"], ["punctuation", ","], - ["keyword", "static"], ["variable", "$f"], + ["keyword", "static"], ["variable", "$f"], ["punctuation", ","], + ["keyword", "int"], ["operator", "|"], ["keyword", "null"], ["variable", "$g"], ["punctuation", ")"], ["punctuation", "{"], ["punctuation", "}"] ]