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

Commit 72c73b0

Browse files
committed
Implement naming conventions
1 parent d4a8e73 commit 72c73b0

File tree

1 file changed

+262
-99
lines changed

1 file changed

+262
-99
lines changed

Diff for: grammars/tree-sitter-python.cson

+262-99
Original file line numberDiff line numberDiff line change
@@ -65,115 +65,278 @@ 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+
'binary_operator > "@"': 'keyword.operator.symbol'
123+
'binary_operator > "@="': 'keyword.operator.symbol'
124+
'"in"': 'keyword.operator.comparison'
125+
'"is"': 'keyword.operator.comparison'
126+
'"and"': 'keyword.operator.logical'
127+
'"or"': 'keyword.operator.logical'
128+
'"not"': 'keyword.operator.logical'
129+
'"del"': 'keyword.operator.delete'
130+
131+
# Storage
132+
'"global"': 'storage.modifier.global'
133+
'"nonlocal"': 'storage.modifier.nonlocal'
134+
135+
'"class"': 'storage.declaration.class'
136+
'"def"': 'storage.declaration.function'
137+
'"lambda"': 'storage.declaration.function'
138+
139+
'''
140+
type > identifier,
141+
type > subscript > identifier
142+
''': [
143+
{
144+
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
145+
scopes: 'storage.type.language'
146+
},
147+
'storage.type.entity'
148+
]
149+
150+
# Entity
151+
'''
152+
identifier,
153+
class_definition > argument_list > identifier,
154+
class_definition > argument_list > keyword_argument > identifier:nth-child(2)
155+
''': [
156+
{
157+
exact: 'cls',
158+
scopes: 'entity.variable.support.cls'
159+
},
160+
{
161+
exact: 'self',
162+
scopes: 'entity.variable.support.self'
163+
}
164+
]
165+
166+
'''
167+
parameters > identifier,
168+
parameters > list_splat > identifier,
169+
parameters > dictionary_splat > identifier,
170+
default_parameter > identifier:nth-child(0),
171+
keyword_argument > identifier:nth-child(0)
172+
''': [
173+
{
174+
exact: 'cls',
175+
scopes: 'entity.variable.support.parameter.cls'
176+
},
177+
{
178+
exact: 'self',
179+
scopes: 'entity.variable.support.parameter.self'
180+
},
181+
'entity.variable.parameter'
182+
]
183+
184+
'identifier': [
185+
{
186+
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)$',
187+
scopes: 'entity.type.class.exception.support'
188+
},
189+
'entity.variable'
190+
]
191+
192+
'''
193+
class_definition > argument_list > identifier,
194+
class_definition > argument_list > keyword_argument > identifier:nth-child(2)
195+
''': [
196+
{
197+
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)$',
198+
scopes: 'entity.type.class.exception.inherited.support'
199+
},
200+
'entity.type.class.inherited'
201+
]
74202

75-
'class_definition > identifier': 'entity.name.type.class'
76-
'function_definition > identifier': 'entity.name.function'
77203
'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'
204+
{
205+
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
206+
scopes: 'entity.type.constructor.language.call'
207+
},
208+
{
209+
exact: 'super',
210+
scopes: 'entity.function.support.call.super'
211+
},
212+
{
213+
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__)$',
214+
scopes: 'entity.function.support.call'
215+
},
216+
'entity.function.call'
217+
]
218+
219+
'decorator > dotted_name > identifier': [
220+
{
221+
match: '^(classmethod|property|staticmethod)$',
222+
scopes: 'entity.function.support'
223+
},
224+
'entity'
225+
]
226+
227+
'call > attribute > identifier:nth-child(2)': 'entity.function.method.call'
228+
229+
'function_definition > identifier': 'entity.function.definition'
230+
231+
'attribute > identifier:nth-child(2)': 'entity.variable.member'
232+
233+
'class_definition > identifier': 'entity.type.class.definition'
83234

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'}
235+
'''
236+
class_definition > argument_list > identifier,
237+
class_definition > argument_list > attribute > identifier:nth-child(2),
238+
class_definition > argument_list > keyword_argument > identifier:nth-child(2),
239+
class_definition > argument_list > keyword_argument > attribute > identifier:nth-child(2)
240+
''': 'entity.type.class.inherited'
88241

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

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

93-
'none': 'constant.language'
94-
'true': 'constant.language'
95-
'false': 'constant.language'
260+
'none': 'constant.language.null'
261+
'true': 'constant.language.boolean'
262+
'false': 'constant.language.boolean'
96263
'integer': 'constant.numeric'
97264
'float': 'constant.numeric'
265+
'ellipsis': 'constant.language.ellipsis.symbol'
98266

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

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'
270+
# Punctuation
271+
'"."': 'punctuation.accessor'
272+
'","': 'punctuation.separator'
273+
'":"': 'punctuation.definition'
105274

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

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

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'
341+
# Meta
342+
'decorator': 'meta.decorator'

0 commit comments

Comments
 (0)