Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit b27d680

Browse files
committed
Implement naming conventions
1 parent d4a8e73 commit b27d680

File tree

1 file changed

+263
-99
lines changed

1 file changed

+263
-99
lines changed

grammars/tree-sitter-python.cson

+263-99
Original file line numberDiff line numberDiff line change
@@ -65,115 +65,279 @@ comments:
6565
scopes:
6666
'module': 'source.python'
6767

68-
'comment': 'comment.line'
69-
'string': 'string.quoted'
70-
'escape_sequence': 'constant.character.escape'
71-
'interpolation': 'meta.embedded'
72-
'interpolation > "{"': 'punctuation.section.embedded'
73-
'interpolation > "}"': 'punctuation.section.embedded'
68+
# Keyword
69+
'"if"': 'keyword.control.condition'
70+
'"else"': 'keyword.control.condition'
71+
'"elif"': 'keyword.control.condition'
72+
'"while"': 'keyword.control.loop'
73+
'"for"': 'keyword.control.loop'
74+
'"return"': 'keyword.control.conclusion'
75+
'"break"': 'keyword.control.conclusion'
76+
'"continue"': 'keyword.control.conclusion'
77+
'"pass"': 'keyword.control.conclusion'
78+
'"yield"': 'keyword.control.conclusion'
79+
'"raise"': 'keyword.control.conclusion'
80+
'"try"': 'keyword.control.exception'
81+
'"except"': 'keyword.control.exception'
82+
'"finally"': 'keyword.control.exception'
83+
'"import"': 'keyword.control.package'
84+
'"from"': 'keyword.control.package'
85+
'"with"': 'keyword.control.evaluate'
86+
'"as"': 'keyword.control.evaluate'
87+
'"assert"': 'keyword.control.evaluate'
88+
'"await"': 'keyword.control.asynchronous'
89+
'"async"': 'keyword.control.asynchronous'
90+
91+
'"print"': 'keyword.control.print'
92+
'"exec"': 'keyword.control.exec'
93+
94+
'"+"': 'keyword.operator.symbol'
95+
'"-"': 'keyword.operator.symbol'
96+
'"*"': 'keyword.operator.symbol'
97+
'"/"': 'keyword.operator.symbol'
98+
'"%"': 'keyword.operator.symbol'
99+
'"**"': 'keyword.operator.symbol'
100+
'"//"': 'keyword.operator.symbol'
101+
'"=="': 'keyword.operator.symbol'
102+
'"!="': 'keyword.operator.symbol'
103+
'"<>"': 'keyword.operator.symbol'
104+
'">"': 'keyword.operator.symbol'
105+
'"<"': 'keyword.operator.symbol'
106+
'">="': 'keyword.operator.symbol'
107+
'"<="': 'keyword.operator.symbol'
108+
'"="': 'keyword.operator.symbol'
109+
'":="': 'keyword.operator.symbol'
110+
'"+="': 'keyword.operator.symbol'
111+
'"-="': 'keyword.operator.symbol'
112+
'"*="': 'keyword.operator.symbol'
113+
'"/="': 'keyword.operator.symbol'
114+
'"%="': 'keyword.operator.symbol'
115+
'"**="': 'keyword.operator.symbol'
116+
'"//="': 'keyword.operator.symbol'
117+
'"&"': 'keyword.operator.symbol'
118+
'"|"': 'keyword.operator.symbol'
119+
'"^"': 'keyword.operator.symbol'
120+
'"~"': 'keyword.operator.symbol'
121+
'"<<"': 'keyword.operator.symbol'
122+
'">>"': 'keyword.operator.symbol'
123+
'binary_operator > "@"': 'keyword.operator.symbol'
124+
'binary_operator > "@="': 'keyword.operator.symbol'
125+
'"in"': 'keyword.operator.comparison'
126+
'"is"': 'keyword.operator.comparison'
127+
'"and"': 'keyword.operator.logical'
128+
'"or"': 'keyword.operator.logical'
129+
'"not"': 'keyword.operator.logical'
130+
'"del"': 'keyword.operator.delete'
131+
132+
# Storage
133+
'"global"': 'storage.modifier.global'
134+
'"nonlocal"': 'storage.modifier.nonlocal'
135+
136+
'"class"': 'storage.declaration.class'
137+
'"def"': 'storage.declaration.function'
138+
'"lambda"': 'storage.declaration.function'
139+
140+
'''
141+
type > identifier,
142+
type > subscript > identifier
143+
''': [
144+
{
145+
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
146+
scopes: 'storage.type.language'
147+
},
148+
'storage.type.entity'
149+
]
150+
151+
# Entity
152+
'''
153+
identifier,
154+
class_definition > argument_list > identifier,
155+
class_definition > argument_list > keyword_argument > identifier:nth-child(2)
156+
''': [
157+
{
158+
exact: 'cls',
159+
scopes: 'entity.variable.support.cls'
160+
},
161+
{
162+
exact: 'self',
163+
scopes: 'entity.variable.support.self'
164+
}
165+
]
166+
167+
'''
168+
parameters > identifier,
169+
parameters > list_splat > identifier,
170+
parameters > dictionary_splat > identifier,
171+
default_parameter > identifier:nth-child(0),
172+
keyword_argument > identifier:nth-child(0)
173+
''': [
174+
{
175+
exact: 'cls',
176+
scopes: 'entity.variable.support.parameter.cls'
177+
},
178+
{
179+
exact: 'self',
180+
scopes: 'entity.variable.support.parameter.self'
181+
},
182+
'entity.variable.parameter'
183+
]
184+
185+
'identifier': [
186+
{
187+
match: '^(BaseException|Exception|TypeError|StopAsyncIteration|StopIteration|ImportError|ModuleNotFoundError|OSError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|BlockingIOError|ChildProcessError|FileExistsError|FileNotFoundError|IsADirectoryError|NotADirectoryError|InterruptedError|PermissionError|ProcessLookupError|TimeoutError|EOFError|RuntimeError|RecursionError|NotImplementedError|NameError|UnboundLocalError|AttributeError|SyntaxError|IndentationError|TabError|LookupError|IndexError|KeyError|ValueError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|AssertionError|ArithmeticError|FloatingPointError|OverflowError|ZeroDivisionError|SystemError|ReferenceError|BufferError|MemoryError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning|GeneratorExit|SystemExit|KeyboardInterrupt)$',
188+
scopes: 'entity.type.class.exception.support'
189+
},
190+
'entity.variable'
191+
]
192+
193+
'''
194+
class_definition > argument_list > identifier,
195+
class_definition > argument_list > keyword_argument > identifier:nth-child(2)
196+
''': [
197+
{
198+
match: '^(BaseException|Exception|TypeError|StopAsyncIteration|StopIteration|ImportError|ModuleNotFoundError|OSError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|BlockingIOError|ChildProcessError|FileExistsError|FileNotFoundError|IsADirectoryError|NotADirectoryError|InterruptedError|PermissionError|ProcessLookupError|TimeoutError|EOFError|RuntimeError|RecursionError|NotImplementedError|NameError|UnboundLocalError|AttributeError|SyntaxError|IndentationError|TabError|LookupError|IndexError|KeyError|ValueError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|AssertionError|ArithmeticError|FloatingPointError|OverflowError|ZeroDivisionError|SystemError|ReferenceError|BufferError|MemoryError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning|GeneratorExit|SystemExit|KeyboardInterrupt)$',
199+
scopes: 'entity.type.class.exception.inherited.support'
200+
},
201+
'entity.type.class.inherited'
202+
]
74203

75-
'class_definition > identifier': 'entity.name.type.class'
76-
'function_definition > identifier': 'entity.name.function'
77204
'call > identifier:nth-child(0)': [
78-
{match: '^(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__)$',
79-
scopes: 'support.function'},
80-
'entity.name.function'
81-
]
82-
'call > attribute > identifier:nth-child(2)': 'entity.name.function'
205+
{
206+
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
207+
scopes: 'entity.type.constructor.language.call'
208+
},
209+
{
210+
exact: 'super',
211+
scopes: 'entity.function.support.call.super'
212+
},
213+
{
214+
match: '^(abs|all|any|ascii|bin|breakpoint|callable|chr|classmethod|compile|delattr|dir|divmod|enumerate|eval|exec|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|min|next|oct|open|ord|pow|print|property|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|type|vars|zip|__import__)$',
215+
scopes: 'entity.function.support.call'
216+
},
217+
'entity.function.call'
218+
]
219+
220+
'decorator > dotted_name > identifier': [
221+
{
222+
match: '^(classmethod|property|staticmethod)$',
223+
scopes: 'entity.function.support'
224+
},
225+
'entity'
226+
]
227+
228+
'call > attribute > identifier:nth-child(2)': 'entity.function.method.call'
229+
230+
'function_definition > identifier': 'entity.function.definition'
231+
232+
'attribute > identifier:nth-child(2)': 'entity.variable.member'
233+
234+
'class_definition > identifier': 'entity.type.class.definition'
83235

84-
'identifier':
85-
{match:
86-
'^(BaseException|Exception|TypeError|StopAsyncIteration|StopIteration|ImportError|ModuleNotFoundError|OSError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|BlockingIOError|ChildProcessError|FileExistsError|FileNotFoundError|IsADirectoryError|NotADirectoryError|InterruptedError|PermissionError|ProcessLookupError|TimeoutError|EOFError|RuntimeError|RecursionError|NotImplementedError|NameError|UnboundLocalError|AttributeError|SyntaxError|IndentationError|TabError|LookupError|IndexError|KeyError|ValueError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|AssertionError|ArithmeticError|FloatingPointError|OverflowError|ZeroDivisionError|SystemError|ReferenceError|BufferError|MemoryError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning|GeneratorExit|SystemExit|KeyboardInterrupt)$'
87-
scopes: 'support.type.exception'}
236+
'''
237+
class_definition > argument_list > identifier,
238+
class_definition > argument_list > attribute > identifier:nth-child(2),
239+
class_definition > argument_list > keyword_argument > identifier:nth-child(2),
240+
class_definition > argument_list > keyword_argument > attribute > identifier:nth-child(2)
241+
''': 'entity.type.class.inherited'
88242

89-
'attribute > identifier:nth-child(2)': 'variable.other.object.property'
243+
# String
244+
'string': 'string.quoted'
245+
'format_specifier': 'string.format'
246+
'interpolation': 'string.interpolation'
90247

91-
'decorator': 'entity.name.function.decorator'
248+
# Constant
249+
'escape_sequence': [
250+
{
251+
match: '[tf]',
252+
scopes: 'constant.character.escape.whitespace'
253+
},
254+
{
255+
match: '[nr]',
256+
scopes: 'constant.character.escape.whitespace.newline'
257+
},
258+
'constant.character.escape'
259+
]
92260

93-
'none': 'constant.language'
94-
'true': 'constant.language'
95-
'false': 'constant.language'
261+
'none': 'constant.language.null'
262+
'true': 'constant.language.boolean'
263+
'false': 'constant.language.boolean'
96264
'integer': 'constant.numeric'
97265
'float': 'constant.numeric'
266+
'ellipsis': 'constant.language.ellipsis.symbol'
98267

99-
'type > identifier': 'support.storage.type'
268+
# Comment
269+
'comment': 'comment.line'
100270

101-
'class_definition > argument_list > attribute': 'entity.other.inherited-class'
102-
'class_definition > argument_list > identifier': 'entity.other.inherited-class'
103-
'class_definition > argument_list > keyword_argument > attribute': 'entity.other.inherited-class'
104-
'class_definition > argument_list > keyword_argument > identifier:nth-child(2)': 'entity.other.inherited-class'
271+
# Punctuation
272+
'"."': 'punctuation.accessor'
273+
'","': 'punctuation.separator'
274+
'":"': 'punctuation.definition'
105275

106-
'"class"': 'storage.type.class'
107-
'"def"': 'storage.type.function'
108-
'"lambda"': 'storage.type.function'
276+
'import_prefix > "."': 'punctuation.definition.import.relative'
109277

110-
'"global"': 'storage.modifier.global'
111-
'"nonlocal"': 'storage.modifier.nonlocal'
278+
'typed_default_parameter > ":"': 'punctuation.definition.type'
279+
'assignment > ":"': 'punctuation.definition.type'
280+
'typed_parameters > ":"': 'punctuation.definition.type'
281+
'"->"': 'punctuation.definition.type.return'
282+
283+
'slice > ":"': 'punctuation.separator.slice'
284+
'pair > ":"': 'punctuation.separator.pair'
285+
286+
'decorator > "@"': 'punctuation.definition.decorator'
287+
288+
'future_import_statement > "("': 'punctuation.definition.import'
289+
'future_import_statement > ")"': 'punctuation.definition.import'
290+
'import_from_statement > "("': 'punctuation.definition.import'
291+
'import_from_statement > ")"': 'punctuation.definition.import'
292+
293+
'parameters > "("': 'punctuation.definition.parameters'
294+
'parameters > ")"': 'punctuation.definition.parameters'
295+
296+
'argument_list > "("': 'punctuation.definition.arguments'
297+
'argument_list > ")"': 'punctuation.definition.arguments'
298+
299+
'parenthesized_expression > "("': 'punctuation.definition.expression'
300+
'parenthesized_expression > ")"': 'punctuation.definition.expression'
301+
'generator_expression > "("': 'punctuation.definition.generator'
302+
'generator_expression > ")"': 'punctuation.definition.generator'
303+
304+
'tuple > "("': 'punctuation.definition.tuple'
305+
'tuple > ")"': 'punctuation.definition.tuple'
306+
307+
'subscript > "["': 'punctuation.accessor'
308+
'subscript > "]"': 'punctuation.accessor'
309+
310+
'list > "["': 'punctuation.definition.list'
311+
'list > "]"': 'punctuation.definition.list'
312+
'list_comprehension > "["': 'punctuation.definition.list'
313+
'list_comprehension > "]"': 'punctuation.definition.list'
314+
315+
'dictionary > "{"': 'punctuation.definition.dictionary'
316+
'dictionary > "}"': 'punctuation.definition.dictionary'
317+
'dictionary_comprehension > "{"': 'punctuation.definition.dictionary'
318+
'dictionary_comprehension > "}"': 'punctuation.definition.dictionary'
319+
320+
'set > "{"': 'punctuation.definition.set'
321+
'set > "}"': 'punctuation.definition.set'
322+
'set_comprehension > "{"': 'punctuation.definition.set'
323+
'set_comprehension > "}"': 'punctuation.definition.set'
324+
325+
'interpolation > "{"': 'punctuation.definition.interpolation'
326+
'interpolation > "}"': 'punctuation.definition.interpolation'
327+
328+
'format_expression > "{"': 'punctuation.definition.format'
329+
'format_expression > "}"': 'punctuation.definition.format'
330+
'format_specifier > ":"': 'punctuation.definition.format'
331+
332+
'ERROR > "."': 'punctuation.invalid.illegal'
333+
'ERROR > ","': 'punctuation.invalid.illegal'
334+
'ERROR > ":"': 'punctuation.invalid.illegal'
335+
'ERROR > "{"': 'punctuation.invalid.illegal'
336+
'ERROR > "}"': 'punctuation.invalid.illegal'
337+
'ERROR > "("': 'punctuation.invalid.illegal'
338+
'ERROR > ")"': 'punctuation.invalid.illegal'
339+
'ERROR > "["': 'punctuation.invalid.illegal'
340+
'ERROR > "]"': 'punctuation.invalid.illegal'
112341

113-
'parameters > identifier': 'variable.parameter.function'
114-
'parameters > list_splat > identifier': 'variable.parameter.function'
115-
'parameters > dictionary_splat > identifier': 'variable.parameter.function'
116-
'default_parameter > identifier:nth-child(0)': 'variable.parameter.function'
117-
'keyword_argument > identifier:nth-child(0)': 'variable.parameter.function'
118-
119-
'"if"': 'keyword.control'
120-
'"else"': 'keyword.control'
121-
'"elif"': 'keyword.control'
122-
'"while"': 'keyword.control'
123-
'"for"': 'keyword.control'
124-
'"return"': 'keyword.control'
125-
'"break"': 'keyword.control'
126-
'"continue"': 'keyword.control'
127-
'"pass"': 'keyword.control'
128-
'"raise"': 'keyword.control'
129-
'"yield"': 'keyword.control'
130-
'"await"': 'keyword.control'
131-
'"async"': 'keyword.control'
132-
'"try"': 'keyword.control'
133-
'"except"': 'keyword.control'
134-
'"with"': 'keyword.control'
135-
'"as"': 'keyword.control'
136-
'"finally"': 'keyword.control'
137-
'"import"': 'keyword.control'
138-
'"from"': 'keyword.control'
139-
140-
'"print"': 'keyword.other'
141-
'"assert"': 'keyword.other'
142-
'"exec"': 'keyword.other'
143-
'"del"': 'keyword.other'
144-
145-
'"+"': 'keyword.operator'
146-
'"-"': 'keyword.operator'
147-
'"*"': 'keyword.operator'
148-
'"/"': 'keyword.operator'
149-
'"%"': 'keyword.operator'
150-
'"**"': 'keyword.operator'
151-
'"//"': 'keyword.operator'
152-
'"=="': 'keyword.operator'
153-
'"!="': 'keyword.operator'
154-
'"<>"': 'keyword.operator'
155-
'">"': 'keyword.operator'
156-
'"<"': 'keyword.operator'
157-
'">="': 'keyword.operator'
158-
'"<="': 'keyword.operator'
159-
'"="': 'keyword.operator'
160-
'"+="': 'keyword.operator'
161-
'"-="': 'keyword.operator'
162-
'"*="': 'keyword.operator'
163-
'"/="': 'keyword.operator'
164-
'"%="': 'keyword.operator'
165-
'"**="': 'keyword.operator'
166-
'"//="': 'keyword.operator'
167-
'"&"': 'keyword.operator'
168-
'"|"': 'keyword.operator'
169-
'"^"': 'keyword.operator'
170-
'"~"': 'keyword.operator'
171-
'"<<"': 'keyword.operator'
172-
'">>"': 'keyword.operator'
173-
'binary_operator > "@"': 'keyword.operator'
174-
'binary_operator > "@="': 'keyword.operator'
175-
'"in"': 'keyword.operator.logical.python'
176-
'"and"': 'keyword.operator.logical.python'
177-
'"or"': 'keyword.operator.logical.python'
178-
'"not"': 'keyword.operator.logical.python'
179-
'"is"': 'keyword.operator.logical.python'
342+
# Meta
343+
'decorator': 'meta.decorator'

0 commit comments

Comments
 (0)