From 622f90a157cd3cdac71437851d4a2a2bd38e0a79 Mon Sep 17 00:00:00 2001 From: Erasin Wang Date: Wed, 8 Mar 2023 08:28:44 +0800 Subject: [PATCH] Update highlight for PHP (#6203) - update tree-sitter-php - add basic types, operator - refine keyword --- languages.toml | 2 +- runtime/queries/php/highlights.scm | 267 ++++++++++++++++++++++++----- 2 files changed, 228 insertions(+), 41 deletions(-) diff --git a/languages.toml b/languages.toml index c34135244..d8b57e976 100644 --- a/languages.toml +++ b/languages.toml @@ -571,7 +571,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "php" -source = { git = "https://github.com/tree-sitter/tree-sitter-php", rev = "57f855461aeeca73bd4218754fb26b5ac143f98f" } +source = { git = "https://github.com/tree-sitter/tree-sitter-php", rev = "f860e598194f4a71747f91789bf536b393ad4a56" } [[language]] name = "twig" diff --git a/runtime/queries/php/highlights.scm b/runtime/queries/php/highlights.scm index 77c9424fe..4bf313d84 100644 --- a/runtime/queries/php/highlights.scm +++ b/runtime/queries/php/highlights.scm @@ -2,15 +2,63 @@ "?>" @tag ; Types +[ + (primitive_type) + (cast_type) +] @type.builtin -(primitive_type) @type.builtin -(cast_type) @type.builtin -(named_type (name) @type) @type -(named_type (qualified_name) @type) @type +(named_type + [ (name) @type + (qualified_name (name) @type)]) + +(base_clause + [ (name) @type + (qualified_name (name) @type)]) + +(enum_declaration + name: (name) @type.enum) + +(interface_declaration + name: (name) @constructor) + +(class_declaration + name: (name) @constructor) + +(trait_declaration + name:(name) @constructor) (namespace_definition name: (namespace_name (name) @namespace)) +(namespace_name_as_prefix + (namespace_name (name) @namespace)) + +(namespace_use_clause + [ (name) @namespace + (qualified_name (name) @type) ]) + +(namespace_aliasing_clause (name) @namespace) + +(class_interface_clause + [(name) @type + (qualified_name (name) @type)]) + +(scoped_call_expression + scope: [(name) @type + (qualified_name (name) @type)]) + +(class_constant_access_expression + . [(name) @constructor + (qualified_name (name) @constructor)] + (name) @constant) + +(use_declaration (name) @type) + +(binary_expression + operator: "instanceof" + right: [(name) @type + (qualified_name (name) @type)]) + ; Superglobals (subscript_expression (variable_name(name) @constant.builtin @@ -36,6 +84,21 @@ (function_definition name: (name) @function) +(nullsafe_member_call_expression + name: (name) @function.method) + +(object_creation_expression + [(name) @constructor + (qualified_name (name) @constructor)]) + +; Parameters +[ + (simple_parameter) + (variadic_parameter) +] @variable.parameter + +(argument + (name) @variable.parameter) ; Member @@ -62,68 +125,192 @@ (variable_name) @variable +; Attributes +(attribute_list) @attribute + ; Basic tokens -(string) @string -(heredoc) @string +[ + (string) + (encapsed_string) + (heredoc_body) + (nowdoc_body) + (shell_command_expression) +] @string +(escape_sequence) @constant.character.escape + (boolean) @constant.builtin.boolean (null) @constant.builtin (integer) @constant.numeric.integer (float) @constant.numeric.float (comment) @comment -"$" @operator +(goto_statement (name) @label) +(named_label_statement (name) @label) ; Keywords [ - "abstract" - "as" - "break" - "case" - "catch" - "class" - "const" - "continue" - "declare" "default" - "do" "echo" - "else" - "elseif" - "enddeclare" - "endforeach" - "endif" - "endswitch" - "endwhile" "enum" "extends" "final" - "finally" - "foreach" - "fn" - "function" + "goto" "global" - "if" "implements" - "include_once" - "include" "insteadof" - "interface" - "match" - "namespace" "new" "private" "protected" "public" +] @keyword + +[ + "if" + "else" + "elseif" + "endif" + "switch" + "endswitch" + "case" + "match" + "declare" + "enddeclare" + "??" +] @keyword.control.conditional + +[ + "for" + "endfor" + "foreach" + "endforeach" + "while" + "endwhile" + "do" +] @keyword.control.repeat + +[ + + "include_once" + "include" "require_once" "require" + "use" +] @keyword.control.import + +[ "return" - "static" - "switch" + "break" + "continue" + "yield" +] @keyword.control.return + +[ "throw" - "trait" "try" - "use" - "while" -] @keyword + "catch" + "finally" +] @keyword.control.exception + +[ + "as" + "or" + "xor" + "and" + "instanceof" +] @keyword.operator + +[ + "fn" + "function" +] @keyword.function + +[ + "namespace" + "class" + "interface" + "trait" + "abstract" +] @keyword.storage.type + +[ + "static" + "const" +] @keyword.storage.modifier + +[ + "," + ";" + ":" + "\\" + ] @punctuation.delimiter + +[ + (php_tag) + "?>" + "(" + ")" + "[" + "]" + "{" + "}" + "#[" +] @punctuation.bracket + +[ + "=" + + "." + "-" + "*" + "/" + "+" + "%" + "**" + + "~" + "|" + "^" + "&" + "<<" + ">>" + + "->" + "?->" + + "=>" + + "<" + "<=" + ">=" + ">" + "<>" + "==" + "!=" + "===" + "!==" + + "!" + "&&" + "||" + + ".=" + "-=" + "+=" + "*=" + "/=" + "%=" + "**=" + "&=" + "|=" + "^=" + "<<=" + ">>=" + "??=" + "--" + "++" + + "@" + "::" +] @operator