From 2b5e68cf2e037657ccdcdfe4ac4b9aa872931232 Mon Sep 17 00:00:00 2001 From: chbk Date: Fri, 22 Nov 2019 15:09:00 +0100 Subject: [PATCH] Implement naming conventions --- grammars/tree-sitter-python.cson | 385 +++++++++++++++++++++++-------- 1 file changed, 286 insertions(+), 99 deletions(-) diff --git a/grammars/tree-sitter-python.cson b/grammars/tree-sitter-python.cson index 4951b02..c6dd1de 100644 --- a/grammars/tree-sitter-python.cson +++ b/grammars/tree-sitter-python.cson @@ -65,115 +65,302 @@ 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.arithmetic.symbol' + '"-"': 'keyword.operator.arithmetic.symbol' + '"*"': 'keyword.operator.arithmetic.symbol' + '"/"': 'keyword.operator.arithmetic.symbol' + '"%"': 'keyword.operator.arithmetic.symbol' + '"**"': 'keyword.operator.arithmetic.symbol' + '"//"': 'keyword.operator.arithmetic.symbol' + '"@"': 'keyword.operator.arithmetic.symbol' + + '"&"': 'keyword.operator.bitwise.symbol' + '"|"': 'keyword.operator.bitwise.symbol' + '"^"': 'keyword.operator.bitwise.symbol' + '"~"': 'keyword.operator.bitwise.symbol' + '"<<"': 'keyword.operator.bitwise.shift.symbol' + '">>"': 'keyword.operator.bitwise.shift.symbol' + + '"="': 'keyword.operator.assignment.symbol' + '":="': 'keyword.operator.assignment.symbol' + '"+="': 'keyword.operator.assignment.compound.symbol' + '"-="': 'keyword.operator.assignment.compound.symbol' + '"*="': 'keyword.operator.assignment.compound.symbol' + '"/="': 'keyword.operator.assignment.compound.symbol' + '"%="': 'keyword.operator.assignment.compound.symbol' + '"**="': 'keyword.operator.assignment.compound.symbol' + '"//="': 'keyword.operator.assignment.compound.symbol' + '"@="': 'keyword.operator.assignment.compound.symbol' + '"&="': 'keyword.operator.assignment.compound.symbol' + '"|="': 'keyword.operator.assignment.compound.symbol' + '"^="': 'keyword.operator.assignment.compound.symbol' + '"<<="': 'keyword.operator.assignment.compound.symbol' + '">>="': 'keyword.operator.assignment.compound.symbol' + + '"=="': 'keyword.operator.comparison.symbol' + '"!="': 'keyword.operator.comparison.symbol' + '"<>"': 'keyword.operator.comparison.symbol' + '"<"': 'keyword.operator.comparison.symbol' + '">"': 'keyword.operator.comparison.symbol' + '"<="': 'keyword.operator.comparison.symbol' + '">="': 'keyword.operator.comparison.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' + + 'wildcard_import > "*"': 'keyword.operator.wildcard.symbol' + 'list_splat > "*"': 'keyword.operator.unpack.symbol' + 'dictionary_splat > "**"': 'keyword.operator.unpack.symbol' + + # Storage + '"global"': 'storage.modifier.global' + '"nonlocal"': 'storage.modifier.nonlocal' + '"async"': 'storage.modifier.async' + + '"def"': 'storage.declaration.function' + '"lambda"': 'storage.declaration.function' + '"class"': 'storage.declaration.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.cast.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' + ] + + 'call > attribute > identifier:nth-child(2)': 'entity.function.method.call' - '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'} + 'function_definition > identifier': 'entity.function.definition' - 'attribute > identifier:nth-child(2)': 'variable.other.object.property' + 'attribute > identifier:nth-child(2)': 'entity.variable.member' - 'decorator': 'entity.name.function.decorator' + '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.definition' + '"{"': 'punctuation.definition' + '"}"': 'punctuation.definition' + '"["': 'punctuation.definition' + '"]"': 'punctuation.definition' + '"("': 'punctuation.definition' + '")"': 'punctuation.definition' + '","': 'punctuation.separator' + '";"': 'punctuation.terminator' + '"."': 'punctuation.accessor.member' + '"\\""': 'punctuation.definition.string' - '"global"': 'storage.modifier.global' - '"nonlocal"': 'storage.modifier.nonlocal' + 'import_prefix > "."': 'punctuation.definition.import.relative' + + 'decorator > "@"': 'punctuation.definition.decorator' + + '"->"': 'punctuation.definition.type.return' + 'typed_default_parameter > ":"': 'punctuation.definition.type' + 'assignment > ":"': 'punctuation.definition.type' + 'typed_parameters > ":"': 'punctuation.definition.type' + + 'slice > ":"': 'punctuation.separator.slice' + 'pair > ":"': 'punctuation.separator.pair' + + 'format_specifier > ":"': 'punctuation.definition.string.format' + 'format_expression > "{"': 'punctuation.definition.string.format' + 'format_expression > "}"': 'punctuation.definition.string.format' + + 'interpolation > "{"': 'punctuation.definition.string.interpolation' + 'interpolation > "}"': 'punctuation.definition.string.interpolation' + + 'dictionary > "{"': 'punctuation.definition.collection.dictionary' + 'dictionary > "}"': 'punctuation.definition.collection.dictionary' + 'dictionary_comprehension > "{"': 'punctuation.definition.collection.dictionary' + 'dictionary_comprehension > "}"': 'punctuation.definition.collection.dictionary' + + 'set > "{"': 'punctuation.definition.collection.set' + 'set > "}"': 'punctuation.definition.collection.set' + 'set_comprehension > "{"': 'punctuation.definition.collection.set' + 'set_comprehension > "}"': 'punctuation.definition.collection.set' + + 'list > "["': 'punctuation.definition.collection.list' + 'list > "]"': 'punctuation.definition.collection.list' + 'list_comprehension > "["': 'punctuation.definition.collection.list' + 'list_comprehension > "]"': 'punctuation.definition.collection.list' + + 'subscript > "["': 'punctuation.accessor.subscript' + 'subscript > "]"': 'punctuation.accessor.subscript' + + 'tuple > "("': 'punctuation.definition.collection.tuple' + 'tuple > ")"': 'punctuation.definition.collection.tuple' + + '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.expression' + 'generator_expression > ")"': 'punctuation.definition.expression' - '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.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.separator.invalid.illegal' + 'ERROR > ";"': 'punctuation.terminator.invalid.illegal' + 'ERROR > "."': 'punctuation.accessor.member.invalid.illegal' + 'ERROR > "\\""': 'punctuation.definition.string.invalid.illegal' + 'ERROR > "->"': 'punctuation.definition.type.return.invalid.illegal'