diff --git a/components/prism-php.js b/components/prism-php.js index 19bca937c6..c6607fca3b 100644 --- a/components/prism-php.js +++ b/components/prism-php.js @@ -1,65 +1,147 @@ /** * 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 - * - * Adds the following new token classes: - * constant, delimiter, variable, function, package + * Supports PHP 5.3 - 7.4 */ (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, - '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 - } - }); - - 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' - } - }); - - Prism.languages.insertBefore('php', 'keyword', { + }, + 'comment': [ + /\/\*[\s\S]*?\*\/|\/\/.*|#.*/ + ], 'variable': /\$+(?:\w+\b|(?={))/i, 'package': { - pattern: /(\\|namespace\s+|use\s+)[\w\\]+/, + pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i, lookbehind: true, inside: { - punctuation: /\\/ + 'punctuation': /\\/ } - } - }); - - // Must be defined after the function pattern - Prism.languages.insertBefore('php', 'operator', { + }, + 'keyword': [ + { + 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|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|callable|iterable)\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, + alias: 'type-declaration', + greedy: true + }, + { + 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|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: true, + lookbehind: true + }, + { + 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, + inside: { + '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', + greedy: true + }, + { + pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i, + alias: ['class-name-fully-qualified', 'static-context'], + greedy: true, + inside: { + 'punctuation': /\\/ + } + }, + { + pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i, + alias: 'type-hint', + greedy: true, + lookbehind: true + }, + { + pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i, + alias: ['class-name-fully-qualified', 'type-hint'], + greedy: true, + lookbehind: true, + inside: { + 'punctuation': /\\/ + } + }, + { + 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, + 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+)*)/, @@ -67,52 +149,57 @@ 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': /^<<<'?|[';]$/ + } } } + }, + { + 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 + } } - }, - '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 - } - }, - '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.hooks.add('before-tokenize', function(env) { if (!/<\?/.test(env.code)) { diff --git a/components/prism-php.min.js b/components/prism-php.min.js index 63caeeadf7..7ab532e717 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={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 3047eb0a27..d6534973bb 100644 --- a/tests/languages/latte/html_feature.test +++ b/tests/languages/latte/html_feature.test @@ -15,35 +15,35 @@ ["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", ":"], ["class-name", "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", "}"]]]]], + ["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/n-attr_feature.test b/tests/languages/latte/n-attr_feature.test index 678f5a4e87..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", "-"], ["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", "-"], ["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/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 new file mode 100644 index 0000000000..8693b9adce --- /dev/null +++ b/tests/languages/php/class-name_feature.test @@ -0,0 +1,137 @@ +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 {} + +class Foo extends Bar implements Baz {} + +class Foo extends \Package\Bar implements App\Baz {} + +---------------------------------------------------- + +[ + ["keyword", "public"], + ["class-name", "Foo"], + ["variable", "$a"], + ["punctuation", ";"], + + ["class-name", "Foo"], + ["operator", "::"], + ["function", "bar"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["class-name", [ + ["punctuation", "\\"], + "Foo" + ]], + ["operator", "::"], + ["function", "bar"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], + ["operator", "::"], + ["function", "bar"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", ";"], + + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["class-name", "Foo"], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", "Foo"], + ["punctuation", "{"], ["punctuation", "}"], + + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["class-name", [ + ["punctuation", "\\"], + "Foo" + ]], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", [ + ["punctuation", "\\"], + "Foo" + ]], + ["punctuation", "{"], ["punctuation", "}"], + + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", ":"], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Foo" + ]], + ["punctuation", "{"], ["punctuation", "}"], + + ["keyword", "function"], + ["function", "f"], + ["punctuation", "("], + ["variable", "$variable"], + ["punctuation", ")"], + ["punctuation", ":"], + ["operator", "?"], + ["class-name", "Foo"], + ["punctuation", "{"], ["punctuation", "}"], + + ["keyword", "class"], + ["class-name", "Foo"], + ["keyword", "extends"], + ["class-name", "Bar"], + ["keyword", "implements"], + ["class-name", "Baz"], + ["punctuation", "{"], ["punctuation", "}"], + + ["keyword", "class"], + ["class-name", "Foo"], + ["keyword", "extends"], + ["class-name", [ + ["punctuation", "\\"], + "Package", + ["punctuation", "\\"], + "Bar" + ]], + ["keyword", "implements"], + ["class-name", [ + "App", + ["punctuation", "\\"], + "Baz" + ]], + ["punctuation", "{"], ["punctuation", "}"] +] + +---------------------------------------------------- + +Checks for class names. \ No newline at end of file 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 41b72b7f14..88d5e2bbbc 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 @@ -44,11 +44,12 @@ insteadof interface; isset list -match namespace; +match new; or parent +parent:: print private protected @@ -56,7 +57,11 @@ public require require_once return +self +new self +self:: static +static:: switch throw trait; @@ -74,7 +79,7 @@ yield ["keyword", "__halt_compiler"], ["keyword", "abstract"], ["keyword", "and"], - ["keyword", "array"], + ["keyword", "array"], ["punctuation", "("], ["punctuation", ")"], ["keyword", "as"], ["keyword", "break"], ["keyword", "callable"], @@ -117,11 +122,12 @@ yield ["keyword", "interface"], ["punctuation", ";"], ["keyword", "isset"], ["keyword", "list"], - ["keyword", "match"], ["keyword", "namespace"], ["punctuation", ";"], + ["keyword", "match"], ["keyword", "new"], ["punctuation", ";"], ["keyword", "or"], ["keyword", "parent"], + ["keyword", "parent"], ["operator", "::"], ["keyword", "print"], ["keyword", "private"], ["keyword", "protected"], @@ -129,10 +135,14 @@ yield ["keyword", "require"], ["keyword", "require_once"], ["keyword", "return"], + ["keyword", "self"], + ["keyword", "new"], ["keyword", "self"], + ["keyword", "self"], ["operator", "::"], ["keyword", "static"], + ["keyword", "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 e1d3e5f25c..297f3a022e 100644 --- a/tests/languages/php/package_feature.test +++ b/tests/languages/php/package_feature.test @@ -1,11 +1,16 @@ +namespace App namespace \foo namespace \foo\bar\baz use \foo use \foo\bar\baz +use function \foo +use function \foo\bar\baz ---------------------------------------------------- [ + ["keyword", "namespace"], + ["package", ["App"]], ["keyword", "namespace"], ["package", [["punctuation", "\\"], "foo"]], ["keyword", "namespace"], @@ -17,6 +22,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/property_feature.test b/tests/languages/php/property_feature.test index f7790197a5..031529cb95 100644 --- a/tests/languages/php/property_feature.test +++ b/tests/languages/php/property_feature.test @@ -1,17 +1,19 @@ -$variable->property -$foo->bar->baz +$variable->property; +$foo->bar->baz; ---------------------------------------------------- [ ["variable", "$variable"], - ["operator", "-"], ["operator", ">"], + ["operator", "->"], ["property", "property"], + ["punctuation", ";"], ["variable", "$foo"], - ["operator", "-"], ["operator", ">"], + ["operator", "->"], ["property", "bar"], - ["operator", "-"], ["operator", ">"], - ["property", "baz"] + ["operator", "->"], + ["property", "baz"], + ["punctuation", ";"] ] ---------------------------------------------------- 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/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 b0d57f894c..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", "-"], ["operator", ">"], ["property", "bar"]]], + ["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,50 +76,50 @@ FOO_BAR; ]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"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", "}"] ]], "\"" ]], - ["double-quoted-string", [ + ["string", [ "\"", ["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", "}"] ]], "\"" ]], - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<"], "FOO" ]], "\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", [ "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 cac7a947cc..5e5942af9e 100644 --- a/tests/languages/php/string_feature.test +++ b/tests/languages/php/string_feature.test @@ -14,11 +14,13 @@ NOWDOC; string" 'multi-line string' +`multi-line +shell exec string` ---------------------------------------------------- [ - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<"], "FOO_BAR" ]], @@ -27,7 +29,7 @@ string' "FOO_BAR", ["punctuation", ";"] ]] ]], - ["heredoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<\""], "FOO", ["punctuation", "\""] ]], @@ -36,7 +38,7 @@ string' "FOO", ["punctuation", ";"] ]] ]], - ["nowdoc-string", [ + ["string", [ ["delimiter", [ ["punctuation", "<<<'"], "NOWDOC", ["punctuation", "'"] ]], @@ -45,10 +47,11 @@ 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'"] + ["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 new file mode 100644 index 0000000000..c1d69b97e3 --- /dev/null +++ b/tests/languages/php/type_feature.test @@ -0,0 +1,63 @@ +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) {} + +---------------------------------------------------- + +[ + ["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", "("], + ["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", "}"] +] + +---------------------------------------------------- + +Checks for types. \ No newline at end of file