on master help sign in
Improve python highlighting (#3103)
0a2646eKirawi
languages.toml+1−1
@@ -437,7 +437,7 @@ indent = { tab-width = 4, unit = " " }
437
437
438[[grammar]]
438[[grammar]]
439name = "python"
439name = "python"
440−source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "d6210ceab11e8d812d4ab59c07c81458ec6e5184" }
440+source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "de221eccf9a221f5b85474a553474a69b4b5784d" }
441
441
442[[language]]
442[[language]]
443name = "nickel"
443name = "nickel"
runtime/queries/python/highlights.scm+60−23
@@ -1,3 +1,6 @@
1+(dotted_name
2+ (identifier)* @namespace)
3+
1; Builtin functions
4; Builtin functions
2
5
3((call
6((call
@@ -8,6 +11,11 @@
8
11
9; Function calls
12; Function calls
10
13
14+[
15+ "def"
16+ "lambda"
17+] @keyword.function
18+
11(call
19(call
12 function: (attribute attribute: (identifier) @constructor)
20 function: (attribute attribute: (identifier) @constructor)
13 (#match? @constructor "^[A-Z]"))
21 (#match? @constructor "^[A-Z]"))
@@ -49,6 +57,13 @@
49(parameters (typed_default_parameter name: (identifier) @variable.parameter))
57(parameters (typed_default_parameter name: (identifier) @variable.parameter))
50(keyword_argument name: (identifier) @variable.parameter)
58(keyword_argument name: (identifier) @variable.parameter)
51
59
60+(parameters
61+ (list_splat_pattern ; *args
62+ (identifier) @variable.parameter))
63+(parameters
64+ (dictionary_splat_pattern ; **kwargs
65+ (identifier) @variable.parameter))
66+
52; Types
67; Types
53
68
54((identifier) @type.builtin
69((identifier) @type.builtin
@@ -81,12 +96,11 @@
81(identifier) @variable
96(identifier) @variable
82
97
83; Literals
98; Literals
84−
99+(none) @constant.builtin
85[
100[
86− (none)
87 (true)
101 (true)
88 (false)
102 (false)
89−] @constant.builtin
103+] @constant.builtin.boolean
90
104
91(integer) @constant.numeric.integer
105(integer) @constant.numeric.integer
92(float) @constant.numeric.float
106(float) @constant.numeric.float
@@ -94,9 +108,11 @@
94(string) @string
108(string) @string
95(escape_sequence) @constant.character.escape
109(escape_sequence) @constant.character.escape
96
110
111+["," "." ":" ";" (ellipsis)] @punctuation.delimiter
97(interpolation
112(interpolation
98 "{" @punctuation.special
113 "{" @punctuation.special
99 "}" @punctuation.special) @embedded
114 "}" @punctuation.special) @embedded
115+"(" ")" "[" "]" "{" "}"] @punctuation.bracket
100
116
101[
117[
102 "-"
118 "-"
@@ -135,24 +151,39 @@
135 "as"
151 "as"
136 "assert"
152 "assert"
137 "await"
153 "await"
138− "break"
154+ "from"
139− "continue"
155+ "pass"
156+
157+ "with"
158+] @keyword.control
159+
160+[
161+ "if"
140 "elif"
162 "elif"
141 "else"
163 "else"
142− "except"
164+] @keyword.control.conditional
143− "finally"
165+
166+[
167+ "while"
144 "for"
168 "for"
145− "from"
169+ "break"
146− "if"
170+ "continue"
147− "import"
171+] @keyword.control.repeat
148− "pass"
172+
149− "raise"
173+[
150 "return"
174 "return"
151− "try"
152− "while"
153− "with"
154 "yield"
175 "yield"
155−] @keyword.control
176+] @keyword.control.return
177+(yield "from" @keyword.control.return)
178+
179+[
180+ "raise"
181+ "try"
182+ "except"
183+ "finally"
184+] @keyword.control.except
185+(raise_statement "from" @keyword.control.except)
186+"import" @keyword.control.import
156
187
157(for_statement "in" @keyword.control)
188(for_statement "in" @keyword.control)
158(for_in_clause "in" @keyword.control)
189(for_in_clause "in" @keyword.control)
@@ -161,16 +192,22 @@
161 "and"
192 "and"
162 "async"
193 "async"
163 "class"
194 "class"
164− "def"
165− "del"
166 "exec"
195 "exec"
167 "global"
196 "global"
168− "in"
169− "is"
170− "lambda"
171 "nonlocal"
197 "nonlocal"
172− "not"
173− "or"
174 "print"
198 "print"
175] @keyword
199] @keyword
200+[
201+ "and"
202+ "or"
203+ "in"
204+ "not"
205+ "del"
206+ "is"
207+] @keyword.operator
208+
209+((identifier) @type.builtin
210+ (#match? @type.builtin
211+ "^(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)$"))
176
212
213+(ERROR) @error