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", "}"] ] ----------------------------------------------------