From 738869d7d439d301529992529e4a445880318444 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Mon, 18 Jul 2022 19:49:50 -0400 Subject: [PATCH 1/6] improve python queries --- runtime/queries/python/highlights.scm | 81 +++++++++++++++++++-------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 93e08d58482b..d8b6194e106e 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -1,3 +1,6 @@ +(dotted_name + (identifier)* @namespace) + ; Builtin functions ((call @@ -8,6 +11,11 @@ ; Function calls +[ + "def" + "lambda" +] @keyword.function + (call function: (attribute attribute: (identifier) @constructor) (#match? @constructor "^[A-Z]")) @@ -49,6 +57,13 @@ (parameters (typed_default_parameter name: (identifier) @variable.parameter)) (keyword_argument name: (identifier) @variable.parameter) +(parameters + (list_splat_pattern ; *args + (identifier) @parameter)) +(parameters + (dictionary_splat_pattern ; **kwargs + (identifier) @parameter)) + ; Types ((identifier) @type.builtin @@ -81,12 +96,11 @@ (identifier) @variable ; Literals - +(none) @constant.builtin [ - (none) (true) (false) -] @constant.builtin +] @constant.builtin.boolean (integer) @constant.numeric.integer (float) @constant.numeric.float @@ -135,24 +149,39 @@ "as" "assert" "await" - "break" - "continue" + "from" + "pass" + + "with" +] @keyword.control + +[ + "if" "elif" "else" - "except" - "finally" +] @keyword.control.conditional + +[ + "while" "for" - "from" - "if" - "import" - "pass" - "raise" + "break" + "continue" +] @keyword.control.repeat + +[ "return" - "try" - "while" - "with" "yield" -] @keyword.control +] @keyword.control.return +(yield "from" @keyword.control.return) + +[ + "raise" + "try" + "except" + "finally" +] @keyword.control.except +(raise_statement "from" @keyword.control.except) +"import" @keyword.control.import (for_statement "in" @keyword.control) (for_in_clause "in" @keyword.control) @@ -161,16 +190,22 @@ "and" "async" "class" - "def" - "del" "exec" "global" - "in" - "is" - "lambda" "nonlocal" - "not" - "or" "print" ] @keyword +[ + "and" + "or" + "in" + "not" + "del" + "is" +] @keyword.operator + +((identifier) @type.builtin + (#match? @type.builtin + "^(BaseException|Exception|ArithmeticError|BufferError|LookupError|AssertionError|AttributeError|EOFError|FloatingPointError|GeneratorExit|ImportError|ModuleNotFoundError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RecursionError|ReferenceError|RuntimeError|StopIteration|StopAsyncIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|ZeroDivisionError|EnvironmentError|IOError|WindowsError|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning)$")) +(ERROR) @error From 75c390e032893d33f40a66c1ba10b1c5544e7ae6 Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Mon, 18 Jul 2022 19:50:28 -0400 Subject: [PATCH 2/6] update python grammar to `0.20.2` --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index f9dac467ea2c..a693e3f92f56 100644 --- a/languages.toml +++ b/languages.toml @@ -423,7 +423,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "python" -source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "d6210ceab11e8d812d4ab59c07c81458ec6e5184" } +source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "de221eccf9a221f5b85474a553474a69b4b5784d" } [[language]] name = "nickel" From 160bcb48d615784b6ad27a38530abf207d0a863d Mon Sep 17 00:00:00 2001 From: Kirawi <67773714+kirawi@users.noreply.github.com> Date: Mon, 18 Jul 2022 21:43:11 -0400 Subject: [PATCH 3/6] fix variadic parameter scope --- runtime/queries/python/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index d8b6194e106e..d97b642f2f45 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -59,10 +59,10 @@ (parameters (list_splat_pattern ; *args - (identifier) @parameter)) + (identifier) @variable.parameter)) (parameters (dictionary_splat_pattern ; **kwargs - (identifier) @parameter)) + (identifier) @variable.parameter)) ; Types From e4ed974bcbd5c43ef7f588566c9f79eb5ed56cbf Mon Sep 17 00:00:00 2001 From: Kirawi <67773714+kirawi@users.noreply.github.com> Date: Tue, 19 Jul 2022 22:39:34 -0400 Subject: [PATCH 4/6] add punctuation scopes --- runtime/queries/python/highlights.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index d97b642f2f45..4d367fa06430 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -108,9 +108,11 @@ (string) @string (escape_sequence) @constant.character.escape +"(" ")" "[" "]" "{" "}"] @punctuation.bracket +["," "." ":" ";" (ellipsis)] @punctuation.delimiter (interpolation "{" @punctuation.special - "}" @punctuation.special) @embedded + "}" @punctuation.special) [ "-" From 01bc6fec4c39e512a9db870a9f0df45456cbbfb5 Mon Sep 17 00:00:00 2001 From: Kirawi <67773714+kirawi@users.noreply.github.com> Date: Tue, 19 Jul 2022 22:42:05 -0400 Subject: [PATCH 5/6] fix order of punctuation scopes --- runtime/queries/python/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 4d367fa06430..5b82e0bc3270 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -108,11 +108,11 @@ (string) @string (escape_sequence) @constant.character.escape -"(" ")" "[" "]" "{" "}"] @punctuation.bracket ["," "." ":" ";" (ellipsis)] @punctuation.delimiter (interpolation "{" @punctuation.special "}" @punctuation.special) +"(" ")" "[" "]" "{" "}"] @punctuation.bracket [ "-" From d9a7292c84cfcddc27ef2333c0d9c8f40b2ca3c7 Mon Sep 17 00:00:00 2001 From: Kirawi <67773714+kirawi@users.noreply.github.com> Date: Tue, 19 Jul 2022 22:48:02 -0400 Subject: [PATCH 6/6] undo `embedded` delete --- runtime/queries/python/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm index 5b82e0bc3270..b622ced220e8 100644 --- a/runtime/queries/python/highlights.scm +++ b/runtime/queries/python/highlights.scm @@ -111,7 +111,7 @@ ["," "." ":" ";" (ellipsis)] @punctuation.delimiter (interpolation "{" @punctuation.special - "}" @punctuation.special) + "}" @punctuation.special) @embedded "(" ")" "[" "]" "{" "}"] @punctuation.bracket [