From b27d6806252c2a57fcd52afe2d7e9df3a82c1f8a 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 | 362 ++++++++++++++++++++++--------- 1 file changed, 263 insertions(+), 99 deletions(-) diff --git a/grammars/tree-sitter-python.cson b/grammars/tree-sitter-python.cson index 4951b02..1f69a1a 100644 --- a/grammars/tree-sitter-python.cson +++ b/grammars/tree-sitter-python.cson @@ -65,115 +65,279 @@ 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.conclusion' + '"break"': 'keyword.control.conclusion' + '"continue"': 'keyword.control.conclusion' + '"pass"': 'keyword.control.conclusion' + '"yield"': 'keyword.control.conclusion' + '"raise"': 'keyword.control.conclusion' + '"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' + '"await"': 'keyword.control.asynchronous' + '"async"': 'keyword.control.asynchronous' + + '"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' + + '"class"': 'storage.declaration.class' + '"def"': 'storage.declaration.function' + '"lambda"': 'storage.declaration.function' + + ''' + 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' + }, + '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' + }, + 'entity.type.class.inherited' + ] - '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.support' + }, + 'entity' + ] + + 'call > attribute > identifier:nth-child(2)': 'entity.function.method.call' + + 'function_definition > identifier': 'entity.function.definition' + + 'attribute > identifier:nth-child(2)': 'entity.variable.member' + + 'class_definition > identifier': 'entity.type.class.definition' - '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'} + ''' + 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' - 'attribute > identifier:nth-child(2)': 'variable.other.object.property' + # String + 'string': 'string.quoted' + 'format_specifier': 'string.format' + 'interpolation': 'string.interpolation' - 'decorator': 'entity.name.function.decorator' + # 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' + 'none': 'constant.language.null' + 'true': 'constant.language.boolean' + 'false': 'constant.language.boolean' 'integer': 'constant.numeric' 'float': 'constant.numeric' + 'ellipsis': 'constant.language.ellipsis.symbol' - 'type > identifier': 'support.storage.type' + # Comment + 'comment': 'comment.line' - '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' + # Punctuation + '"."': 'punctuation.accessor' + '","': 'punctuation.separator' + '":"': 'punctuation.definition' - '"class"': 'storage.type.class' - '"def"': 'storage.type.function' - '"lambda"': 'storage.type.function' + 'import_prefix > "."': 'punctuation.definition.import.relative' - '"global"': 'storage.modifier.global' - '"nonlocal"': 'storage.modifier.nonlocal' + '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.import' + 'future_import_statement > ")"': 'punctuation.definition.import' + 'import_from_statement > "("': 'punctuation.definition.import' + 'import_from_statement > ")"': 'punctuation.definition.import' + + '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' + + 'ERROR > "."': 'punctuation.invalid.illegal' + 'ERROR > ","': 'punctuation.invalid.illegal' + 'ERROR > ":"': 'punctuation.invalid.illegal' + 'ERROR > "{"': 'punctuation.invalid.illegal' + 'ERROR > "}"': 'punctuation.invalid.illegal' + 'ERROR > "("': 'punctuation.invalid.illegal' + 'ERROR > ")"': 'punctuation.invalid.illegal' + 'ERROR > "["': 'punctuation.invalid.illegal' + 'ERROR > "]"': 'punctuation.invalid.illegal' - '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' + # Meta + 'decorator': 'meta.decorator'