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

Commit

Permalink
Implement naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
chbk committed Mar 16, 2020
1 parent d4a8e73 commit 29e1106
Showing 1 changed file with 272 additions and 99 deletions.
371 changes: 272 additions & 99 deletions grammars/tree-sitter-python.cson
Original file line number Diff line number Diff line change
Expand Up @@ -65,115 +65,288 @@ comments:
scopes:
'module': 'source.python'

'comment': 'comment.line'
'string': 'string.quoted'
'escape_sequence': 'constant.character.escape'
'interpolation': 'meta.embedded'
'interpolation > "{"': 'punctuation.section.embedded'
'interpolation > "}"': 'punctuation.section.embedded'
# Keyword
'"if"': 'keyword.control.condition'
'"else"': 'keyword.control.condition'
'"elif"': 'keyword.control.condition'
'"while"': 'keyword.control.loop'
'"for"': 'keyword.control.loop'
'"return"': 'keyword.control.jump'
'"break"': 'keyword.control.jump'
'"continue"': 'keyword.control.jump'
'"pass"': 'keyword.control.jump'
'"yield"': 'keyword.control.jump'
'"raise"': 'keyword.control.jump'
'"await"': 'keyword.control.jump'
'"try"': 'keyword.control.exception'
'"except"': 'keyword.control.exception'
'"finally"': 'keyword.control.exception'
'"import"': 'keyword.control.package'
'"from"': 'keyword.control.package'
'"with"': 'keyword.control.evaluate'
'"as"': 'keyword.control.evaluate'
'"assert"': 'keyword.control.evaluate'

'"print"': 'keyword.control.print'
'"exec"': 'keyword.control.exec'

'"+"': 'keyword.operator.symbol'
'"-"': 'keyword.operator.symbol'
'"*"': 'keyword.operator.symbol'
'"/"': 'keyword.operator.symbol'
'"%"': 'keyword.operator.symbol'
'"**"': 'keyword.operator.symbol'
'"//"': 'keyword.operator.symbol'
'"=="': 'keyword.operator.symbol'
'"!="': 'keyword.operator.symbol'
'"<>"': 'keyword.operator.symbol'
'">"': 'keyword.operator.symbol'
'"<"': 'keyword.operator.symbol'
'">="': 'keyword.operator.symbol'
'"<="': 'keyword.operator.symbol'
'"="': 'keyword.operator.symbol'
'":="': 'keyword.operator.symbol'
'"+="': 'keyword.operator.symbol'
'"-="': 'keyword.operator.symbol'
'"*="': 'keyword.operator.symbol'
'"/="': 'keyword.operator.symbol'
'"%="': 'keyword.operator.symbol'
'"**="': 'keyword.operator.symbol'
'"//="': 'keyword.operator.symbol'
'"&"': 'keyword.operator.symbol'
'"|"': 'keyword.operator.symbol'
'"^"': 'keyword.operator.symbol'
'"~"': 'keyword.operator.symbol'
'"<<"': 'keyword.operator.symbol'
'">>"': 'keyword.operator.symbol'
'binary_operator > "@"': 'keyword.operator.symbol'
'binary_operator > "@="': 'keyword.operator.symbol'
'"in"': 'keyword.operator.comparison'
'"is"': 'keyword.operator.comparison'
'"and"': 'keyword.operator.logical'
'"or"': 'keyword.operator.logical'
'"not"': 'keyword.operator.logical'
'"del"': 'keyword.operator.delete'

# Storage
'"global"': 'storage.modifier.global'
'"nonlocal"': 'storage.modifier.nonlocal'
'"async"': 'storage.modifier.async'

'"def"': 'storage.declaration.function'
'"lambda"': 'storage.declaration.function'
'"class"': 'storage.declaration.datatype.class'

'''
type > identifier,
type > subscript > identifier
''': [
{
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
scopes: 'storage.type.language'
},
'storage.type.entity'
]

# Entity
'''
identifier,
class_definition > argument_list > identifier,
class_definition > argument_list > keyword_argument > identifier:nth-child(2)
''': [
{
exact: 'cls',
scopes: 'entity.variable.support.cls'
},
{
exact: 'self',
scopes: 'entity.variable.support.self'
}
]

'''
parameters > identifier,
parameters > list_splat > identifier,
parameters > dictionary_splat > identifier,
default_parameter > identifier:nth-child(0),
keyword_argument > identifier:nth-child(0)
''': [
{
exact: 'cls',
scopes: 'entity.variable.support.parameter.cls'
},
{
exact: 'self',
scopes: 'entity.variable.support.parameter.self'
},
'entity.variable.parameter'
]

'identifier': [
{
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)$',
scopes: 'entity.type.class.exception.support'
},
{
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
scopes: 'entity.type.language'
},
'entity.variable'
]

'''
class_definition > argument_list > identifier,
class_definition > argument_list > keyword_argument > identifier:nth-child(2)
''': {
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)$',
scopes: 'entity.type.class.exception.inherited.support'
}

'class_definition > identifier': 'entity.name.type.class'
'function_definition > identifier': 'entity.name.function'
'call > identifier:nth-child(0)': [
{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__)$',
scopes: 'support.function'},
'entity.name.function'
]
'call > attribute > identifier:nth-child(2)': 'entity.name.function'
{
match: '^(bool|bytearray|bytes|complex|dict|float|frozenset|int|list|memoryview|object|range|set|str|tuple)$',
scopes: 'entity.type.constructor.language.call'
},
{
exact: 'super',
scopes: 'entity.function.support.call.super'
},
{
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__)$',
scopes: 'entity.function.support.call'
},
'entity.function.call'
]

'decorator > dotted_name > identifier': [
{
match: '^(classmethod|property|staticmethod)$',
scopes: 'entity.function.decorator.support'
},
'entity.decorator'
]

'identifier':
{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)$'
scopes: 'support.type.exception'}
'call > attribute > identifier:nth-child(2)': 'entity.function.method.call'

'attribute > identifier:nth-child(2)': 'variable.other.object.property'
'function_definition > identifier': 'entity.function.definition'

'decorator': 'entity.name.function.decorator'
'attribute > identifier:nth-child(2)': 'entity.variable.member'

'class_definition > identifier': 'entity.type.class.definition'

'''
class_definition > argument_list > identifier,
class_definition > argument_list > attribute > identifier:nth-child(2),
class_definition > argument_list > keyword_argument > identifier:nth-child(2),
class_definition > argument_list > keyword_argument > attribute > identifier:nth-child(2)
''': 'entity.type.class.inherited'

# String
'string': 'string.quoted'
'format_specifier': 'string.format'
'interpolation': 'string.interpolation'

# Constant
'escape_sequence': [
{
match: '[tf]',
scopes: 'constant.character.escape.whitespace'
},
{
match: '[nr]',
scopes: 'constant.character.escape.whitespace.newline'
},
'constant.character.escape'
]

'none': 'constant.language'
'true': 'constant.language'
'false': 'constant.language'
'integer': 'constant.numeric'
'float': 'constant.numeric'

'type > identifier': 'support.storage.type'
'none': 'constant.language.null'
'true': 'constant.language.boolean'
'false': 'constant.language.boolean'
'ellipsis': 'constant.language.ellipsis.symbol'

'class_definition > argument_list > attribute': 'entity.other.inherited-class'
'class_definition > argument_list > identifier': 'entity.other.inherited-class'
'class_definition > argument_list > keyword_argument > attribute': 'entity.other.inherited-class'
'class_definition > argument_list > keyword_argument > identifier:nth-child(2)': 'entity.other.inherited-class'
# Comment
'comment': 'comment.line'

'"class"': 'storage.type.class'
'"def"': 'storage.type.function'
'"lambda"': 'storage.type.function'
# Punctuation
'"."': 'punctuation.accessor'
'","': 'punctuation.separator'
'";"': 'punctuation.terminator'
'":"': 'punctuation.definition'
'"("': 'punctuation.definition'
'")"': 'punctuation.definition'
'"{"': 'punctuation.definition'
'"}"': 'punctuation.definition'
'"["': 'punctuation.definition'
'"]"': 'punctuation.definition'
'"\\""': 'punctuation.definition.string'

'"global"': 'storage.modifier.global'
'"nonlocal"': 'storage.modifier.nonlocal'
'import_prefix > "."': 'punctuation.definition.import.relative'

'typed_default_parameter > ":"': 'punctuation.definition.type'
'assignment > ":"': 'punctuation.definition.type'
'typed_parameters > ":"': 'punctuation.definition.type'
'"->"': 'punctuation.definition.type.return'

'slice > ":"': 'punctuation.separator.slice'
'pair > ":"': 'punctuation.separator.pair'

'decorator > "@"': 'punctuation.definition.decorator'

'future_import_statement > "("': 'punctuation.definition.package'
'future_import_statement > ")"': 'punctuation.definition.package'
'import_from_statement > "("': 'punctuation.definition.package'
'import_from_statement > ")"': 'punctuation.definition.package'

'parameters > "("': 'punctuation.definition.parameters'
'parameters > ")"': 'punctuation.definition.parameters'

'argument_list > "("': 'punctuation.definition.arguments'
'argument_list > ")"': 'punctuation.definition.arguments'

'parenthesized_expression > "("': 'punctuation.definition.expression'
'parenthesized_expression > ")"': 'punctuation.definition.expression'
'generator_expression > "("': 'punctuation.definition.generator'
'generator_expression > ")"': 'punctuation.definition.generator'

'tuple > "("': 'punctuation.definition.tuple'
'tuple > ")"': 'punctuation.definition.tuple'

'subscript > "["': 'punctuation.accessor'
'subscript > "]"': 'punctuation.accessor'

'list > "["': 'punctuation.definition.list'
'list > "]"': 'punctuation.definition.list'
'list_comprehension > "["': 'punctuation.definition.list'
'list_comprehension > "]"': 'punctuation.definition.list'

'dictionary > "{"': 'punctuation.definition.dictionary'
'dictionary > "}"': 'punctuation.definition.dictionary'
'dictionary_comprehension > "{"': 'punctuation.definition.dictionary'
'dictionary_comprehension > "}"': 'punctuation.definition.dictionary'

'set > "{"': 'punctuation.definition.set'
'set > "}"': 'punctuation.definition.set'
'set_comprehension > "{"': 'punctuation.definition.set'
'set_comprehension > "}"': 'punctuation.definition.set'

'interpolation > "{"': 'punctuation.definition.interpolation'
'interpolation > "}"': 'punctuation.definition.interpolation'

'format_expression > "{"': 'punctuation.definition.format'
'format_expression > "}"': 'punctuation.definition.format'
'format_specifier > ":"': 'punctuation.definition.format'

'parameters > identifier': 'variable.parameter.function'
'parameters > list_splat > identifier': 'variable.parameter.function'
'parameters > dictionary_splat > identifier': 'variable.parameter.function'
'default_parameter > identifier:nth-child(0)': 'variable.parameter.function'
'keyword_argument > identifier:nth-child(0)': 'variable.parameter.function'

'"if"': 'keyword.control'
'"else"': 'keyword.control'
'"elif"': 'keyword.control'
'"while"': 'keyword.control'
'"for"': 'keyword.control'
'"return"': 'keyword.control'
'"break"': 'keyword.control'
'"continue"': 'keyword.control'
'"pass"': 'keyword.control'
'"raise"': 'keyword.control'
'"yield"': 'keyword.control'
'"await"': 'keyword.control'
'"async"': 'keyword.control'
'"try"': 'keyword.control'
'"except"': 'keyword.control'
'"with"': 'keyword.control'
'"as"': 'keyword.control'
'"finally"': 'keyword.control'
'"import"': 'keyword.control'
'"from"': 'keyword.control'

'"print"': 'keyword.other'
'"assert"': 'keyword.other'
'"exec"': 'keyword.other'
'"del"': 'keyword.other'

'"+"': 'keyword.operator'
'"-"': 'keyword.operator'
'"*"': 'keyword.operator'
'"/"': 'keyword.operator'
'"%"': 'keyword.operator'
'"**"': 'keyword.operator'
'"//"': 'keyword.operator'
'"=="': 'keyword.operator'
'"!="': 'keyword.operator'
'"<>"': 'keyword.operator'
'">"': 'keyword.operator'
'"<"': 'keyword.operator'
'">="': 'keyword.operator'
'"<="': 'keyword.operator'
'"="': 'keyword.operator'
'"+="': 'keyword.operator'
'"-="': 'keyword.operator'
'"*="': 'keyword.operator'
'"/="': 'keyword.operator'
'"%="': 'keyword.operator'
'"**="': 'keyword.operator'
'"//="': 'keyword.operator'
'"&"': 'keyword.operator'
'"|"': 'keyword.operator'
'"^"': 'keyword.operator'
'"~"': 'keyword.operator'
'"<<"': 'keyword.operator'
'">>"': 'keyword.operator'
'binary_operator > "@"': 'keyword.operator'
'binary_operator > "@="': 'keyword.operator'
'"in"': 'keyword.operator.logical.python'
'"and"': 'keyword.operator.logical.python'
'"or"': 'keyword.operator.logical.python'
'"not"': 'keyword.operator.logical.python'
'"is"': 'keyword.operator.logical.python'
'ERROR > "."': 'punctuation.accessor.invalid.illegal'
'ERROR > ","': 'punctuation.separator.invalid.illegal'
'ERROR > ";"': 'punctuation.terminator.invalid.illegal'
'ERROR > ":"': 'punctuation.definition.invalid.illegal'
'ERROR > "{"': 'punctuation.definition.invalid.illegal'
'ERROR > "}"': 'punctuation.definition.invalid.illegal'
'ERROR > "("': 'punctuation.definition.invalid.illegal'
'ERROR > ")"': 'punctuation.definition.invalid.illegal'
'ERROR > "["': 'punctuation.definition.invalid.illegal'
'ERROR > "]"': 'punctuation.definition.invalid.illegal'
'ERROR > "\\""': 'punctuation.definition.string.invalid.illegal'

0 comments on commit 29e1106

Please sign in to comment.