From 62a634575540e2ee8241738a889b3318ee773984 Mon Sep 17 00:00:00 2001 From: Zeddicus414 <31261142+Zeddicus414@users.noreply.github.com> Date: Mon, 9 May 2022 22:50:00 -0500 Subject: [PATCH 1/6] Change python highlights.scm to more fully utilize the themes. Create type keywords Allow _CONSTANTS to start with _ Highlight constants before constructors Move some keywords into @keyword.control --- runtime/queries/python/highlights.scm | 51 +++++++++++++++++---------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 9131acc5b58b..88d9755cacc2 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -1,10 +1,19 @@ ; Identifier naming conventions +((identifier) @constant + (#match? @constant "^[A-Z_]*$")) + ((identifier) @constructor (#match? @constructor "^[A-Z]")) -((identifier) @constant - (#match? @constant "^[A-Z][A-Z_]*$")) +; Types + +((identifier) @type + (#match? + @type + "^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$")) + +(type (identifier)) @type ; Builtin functions @@ -12,7 +21,7 @@ function: (identifier) @function.builtin) (#match? @function.builtin - "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$")) + "^(abs|all|any|ascii|bin|breakpoint|bytearray|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|exec|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip|__import__)$")) ; Function calls @@ -30,7 +39,6 @@ (identifier) @variable (attribute attribute: (identifier) @variable.other.member) -(type (identifier) @type) ; Literals @@ -81,41 +89,48 @@ ">>" "|" "~" - "and" - "in" - "is" - "not" - "or" ] @operator [ "as" "assert" - "async" "await" "break" - "class" "continue" - "def" - "del" "elif" "else" "except" - "exec" "finally" "for" "from" - "global" "if" "import" - "lambda" - "nonlocal" "pass" - "print" "raise" "return" "try" "while" "with" "yield" +] @keyword.control + +(for_statement "in" @keyword.control) +(for_in_clause "in" @keyword.control) + +[ + "and" + "async" + "class" + "def" + "del" + "exec" + "global" + "in" + "is" + "lambda" + "nonlocal" + "not" + "or" + "print" ] @keyword + From 1e4a9da0a0fdb9e0fba76a94ae1936afdfad3b11 Mon Sep 17 00:00:00 2001 From: Zeddicus414 <31261142+Zeddicus414@users.noreply.github.com> Date: Mon, 9 May 2022 22:50:31 -0500 Subject: [PATCH 2/6] dark_plus theme constructor should be green. --- runtime/themes/dark_plus.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/themes/dark_plus.toml b/runtime/themes/dark_plus.toml index 6c9d59194c5b..c785dd388839 100644 --- a/runtime/themes/dark_plus.toml +++ b/runtime/themes/dark_plus.toml @@ -6,7 +6,7 @@ "type" = { fg = "type" } "type.builtin" = { fg = "type" } "type.enum.variant" = { fg = "constant" } -"constructor" = { fg = "constant" } +"constructor" = { fg = "type" } "variable.other.member" = { fg = "variable" } "keyword" = { fg = "blue2" } From d5b6bc441a2c6775738d550a46f3556ab5f73731 Mon Sep 17 00:00:00 2001 From: Paul Scott Date: Fri, 13 May 2022 16:21:38 +1000 Subject: [PATCH 3/6] Python highlight improvements: type, parameter etc * str, list, etc. handled as @function.builtin and @type.builtin * None and non-conforming type indentifiers as @type in type hints * class identifiers treated as @type * @constructor used for constructor definitions and calls rather than as a catch-all for type-like things * Parameters highlighted * self and cls as @variable.builtin * improved decorator highlighting as part of @function Re-ordering of some statements to give more accurate priority. --- runtime/queries/python/highlights.scm | 74 +++++++++++++++++++-------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 88d9755cacc2..fa622435a46a 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -1,44 +1,78 @@ -; Identifier naming conventions - -((identifier) @constant - (#match? @constant "^[A-Z_]*$")) - -((identifier) @constructor - (#match? @constructor "^[A-Z]")) - -; Types - -((identifier) @type - (#match? - @type - "^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$")) - -(type (identifier)) @type - ; Builtin functions ((call function: (identifier) @function.builtin) (#match? @function.builtin - "^(abs|all|any|ascii|bin|breakpoint|bytearray|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|exec|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip|__import__)$")) + "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$")) ; Function calls -(decorator) @function +(call + function: (attribute attribute: (identifier) @constructor) + (#match? @constructor "^[A-Z]")) +(call + function: (identifier) @constructor + (#match? @constructor "^[A-Z]")) (call function: (attribute attribute: (identifier) @function.method)) + (call function: (identifier) @function) ; Function definitions +(function_definition + name: (identifier) @constructor + (#match? @constructor "^(__new__|__init__)$")) + (function_definition name: (identifier) @function) -(identifier) @variable +; Decorators + +(decorator) @function +(decorator (identifier) @function) + +; Parameters + +((identifier) @variable.builtin + (#match? @variable.builtin "^(self|cls)$")) + +(parameters (identifier) @variable.parameter) +(parameters (typed_parameter (identifier) @variable.parameter)) + +; Types + +((identifier) @type.builtin + (#match? + @type.builtin + "^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$")) + +; In type hints make everything types to catch non-conforming identifiers +; (e.g., datetime.datetime) and None +(type [(identifier) (none)] @type) +; Handle [] . and | nesting 4 levels deep +(type + (_ [(identifier) (none)]? @type + (_ [(identifier) (none)]? @type + (_ [(identifier) (none)]? @type + (_ [(identifier) (none)]? @type))))) + +(class_definition name: (identifier) @type) +(class_definition superclasses: (argument_list (identifier) @type)) + +; Variables + +((identifier) @constant + (#match? @constant "^[A-Z_]{2,}$")) + +((identifier) @type + (#match? @type "^[A-Z]")) + (attribute attribute: (identifier) @variable.other.member) +(identifier) @variable ; Literals From 9da79d9dd8776ff2f3bfdd781c8c1788f0852a98 Mon Sep 17 00:00:00 2001 From: Paul Scott Date: Sat, 14 May 2022 12:39:36 +1000 Subject: [PATCH 4/6] Python handling highlighting parameters with defaults --- runtime/queries/python/highlights.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index fa622435a46a..75e76c6853c6 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -42,6 +42,8 @@ (parameters (identifier) @variable.parameter) (parameters (typed_parameter (identifier) @variable.parameter)) +(parameters (default_parameter name: (identifier) @variable.parameter)) +(parameters (typed_default_parameter name: (identifier) @variable.parameter)) ; Types From ef740fb96c39770db13038e058f4b03882c332e9 Mon Sep 17 00:00:00 2001 From: Paul Scott Date: Sat, 14 May 2022 12:50:08 +1000 Subject: [PATCH 5/6] Python highlight keyword argument as parameter --- runtime/queries/python/highlights.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 75e76c6853c6..352940727630 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -44,6 +44,7 @@ (parameters (typed_parameter (identifier) @variable.parameter)) (parameters (default_parameter name: (identifier) @variable.parameter)) (parameters (typed_default_parameter name: (identifier) @variable.parameter)) +(keyword_argument name: (identifier) @variable.parameter) ; Types From 41cfaedfcaa172412013024cd0e3195c00885be9 Mon Sep 17 00:00:00 2001 From: Paul Scott Date: Sun, 15 May 2022 00:03:53 +1000 Subject: [PATCH 6/6] Python highlight decorator attribute --- runtime/queries/python/highlights.scm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 352940727630..93e08d58482b 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -34,6 +34,9 @@ (decorator) @function (decorator (identifier) @function) +(decorator (attribute attribute: (identifier) @function)) +(decorator (call + function: (attribute attribute: (identifier) @function))) ; Parameters