aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirawi2022-07-26 01:17:51 +0000
committerGitHub2022-07-26 01:17:51 +0000
commit0a2646e720c4d3361e0ffa79aa5d2fd01e80568e (patch)
tree047c8504706ccdf3e5ca598c126a84bc246354f0
parent2ede98c4b4275cc2176836347b7c921a7f018d72 (diff)
Improve python highlighting (#3103)
* improve python queries * update python grammar to `0.20.2` * fix variadic parameter scope * add punctuation scopes * fix order of punctuation scopes * undo `embedded` delete
-rw-r--r--languages.toml2
-rw-r--r--runtime/queries/python/highlights.scm83
2 files changed, 61 insertions, 24 deletions
diff --git a/languages.toml b/languages.toml
index 1eaec8dd..b42f9cfd 100644
--- a/languages.toml
+++ b/languages.toml
@@ -437,7 +437,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"
diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm
index 93e08d58..b622ced2 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) @variable.parameter))
+(parameters
+ (dictionary_splat_pattern ; **kwargs
+ (identifier) @variable.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
@@ -94,9 +108,11 @@
(string) @string
(escape_sequence) @constant.character.escape
+["," "." ":" ";" (ellipsis)] @punctuation.delimiter
(interpolation
"{" @punctuation.special
"}" @punctuation.special) @embedded
+"(" ")" "[" "]" "{" "}"] @punctuation.bracket
[
"-"
@@ -135,24 +151,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 +192,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