From 8a88bab8e55aa1edae42439bd7ddd155df347217 Mon Sep 17 00:00:00 2001 From: chbk Date: Tue, 17 Mar 2020 00:21:35 +0100 Subject: [PATCH] Implement naming conventions --- grammars/tree-sitter-go.cson | 334 ++++++++++++++++++++++++++--------- 1 file changed, 251 insertions(+), 83 deletions(-) diff --git a/grammars/tree-sitter-go.cson b/grammars/tree-sitter-go.cson index 533dd20..9b0add1 100644 --- a/grammars/tree-sitter-go.cson +++ b/grammars/tree-sitter-go.cson @@ -43,88 +43,256 @@ folds: [ scopes: 'source_file': 'source.go' - 'comment': 'comment.block' + # Keyword + '"if"': 'keyword.control.condition' + '"else"': 'keyword.control.condition' + '"switch"': 'keyword.control.condition' + '"select"': 'keyword.control.condition' + '"case"': 'keyword.control.condition' + '"fallthrough"': 'keyword.control.condition' + '"default"': 'keyword.control.condition' + '"for"': 'keyword.control.loop' + '"range"': 'keyword.control.loop' + '"break"': 'keyword.control.jump' + '"return"': 'keyword.control.jump' + '"continue"': 'keyword.control.jump' + '"goto"': 'keyword.control.jump' + '"defer"': 'keyword.control.jump' + '"go"': 'keyword.control.jump' + '"package"': 'keyword.control.directive' + '"import"': 'keyword.control.package' + + '"+"': 'keyword.operator.arithmetic.symbol' + '"-"': 'keyword.operator.arithmetic.symbol' + 'binary_expression > "*"': 'keyword.operator.arithmetic.symbol' + '"/"': 'keyword.operator.arithmetic.symbol' + '"%"': 'keyword.operator.arithmetic.symbol' + '"++"': 'keyword.operator.arithmetic.symbol' + '"--"': 'keyword.operator.arithmetic.symbol' + + 'binary_expression > "&"': '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.comparison.symbol' + '"!="': 'keyword.operator.comparison.symbol' + '"<"': 'keyword.operator.comparison.symbol' + '">"': 'keyword.operator.comparison.symbol' + '"<="': 'keyword.operator.comparison.symbol' + '">="': 'keyword.operator.comparison.symbol' + + '"!"': 'keyword.operator.logical.symbol' + '"&&"': 'keyword.operator.logical.symbol' + '"||"': 'keyword.operator.logical.symbol' + + '"&"': 'keyword.operator.pointer.reference.symbol' + '"*"': 'keyword.operator.pointer.dereference.symbol' + + '"<-"': 'keyword.operator.channel.symbol' + + # Storage + '"var"': 'storage.declaration.variable' + '"const"': 'storage.declaration.variable.immutable' + '"map"': 'storage.declaration.map' + '"chan"': 'storage.declaration.channel' + '"func"': 'storage.declaration.function' + '"type"': 'storage.declaration.datatype' + '"struct"': 'storage.declaration.structure' + '"interface"': 'storage.declaration.interface' + + # Entity + 'type_identifier': [ + { + match: '^(bool|byte|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$', + scopes: 'entity.type.fundamental.support' + }, + 'entity.type' + ] + + 'package_identifier': 'entity.package' + + 'label_name': 'entity.label' + + 'identifier': [ + { + exact: 'iota', + scopes: 'entity.variable.support.iota' + }, + 'entity.variable' + ] + + 'parameter_declaration > identifier': [ + { + exact: 'iota', + scopes: 'entity.variable.support.parameter.iota' + }, + 'entity.variable.parameter' + ] + + 'field_identifier': 'entity.variable.member' + + 'call_expression > identifier': [ + { + match: '^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)$', + scopes: 'entity.function.support.call' + }, + { + match: '^(bool|byte|complex128|complex64|error|float32|float64|int|int16|int32|int64|int8|rune|string|uint|uint16|uint32|uint64|uint8|uintptr)$', + scopes: 'entity.type.fundamental.cast.support.call' + }, + 'entity.function.call' + ] + + 'call_expression > selector_expression > field_identifier': 'entity.function.call' + + 'function_declaration > identifier': 'entity.function.definition' + 'method_declaration > field_identifier': 'entity.function.method.definition' + 'type_declaration > type_spec > type_identifier': 'entity.type.definition' + + # String + 'interpreted_string_literal': 'string.quoted' + 'raw_string_literal': 'string.quoted' + + # Constant + 'escape_sequence': [ + { + match: '[tf]', + scopes: 'constant.character.escape.whitespace' + }, + { + match: '[nr]', + scopes: 'constant.character.escape.whitespace.newline' + }, + 'constant.character.escape' + ] + + 'rune_literal': 'constant.character.rune' - '"var"': 'keyword.import' - '"type"': 'keyword.type' - '"func"': 'keyword.function' - '"const"': 'keyword.const' - '"struct"': 'keyword.struct' - '"interface"': 'keyword.interface' - '"import"': 'keyword.import' - '"package"': 'keyword.package' - '"map"': 'keyword.map' - '"chan"': 'keyword.chan' - - 'type_identifier': 'support.storage.type' - 'field_identifier': 'variable.other.object.property' - 'package_identifier': 'entity.name.package' - - '"if"': 'keyword.control' - '"for"': 'keyword.control' - '"else"': 'keyword.control' - '"case"': 'keyword.control' - '"break"': 'keyword.control' - '"switch"': 'keyword.control' - '"select"': 'keyword.control' - '"return"': 'keyword.control' - '"default"': 'keyword.control' - '"continue"': 'keyword.control' - '"goto"': 'keyword.control' - '"fallthrough"': 'keyword.control' - '"defer"': 'keyword.control' - '"range"': 'keyword.control' - '"go"': 'keyword.control' - - 'interpreted_string_literal': 'string.quoted.double' - 'raw_string_literal': 'string.quoted.double' - 'escape_sequence': 'constant.character.escape' - 'rune_literal': 'constant.other.rune' 'int_literal': 'constant.numeric.integer' - 'float_literal': 'constant.numeric.float' - 'imaginary_literal': 'constant.numeric.integer' - 'nil': 'constant.language.nil' - 'false': 'constant.language.false' - 'true': 'constant.language.true' - - 'call_expression > identifier': 'entity.name.function' - 'function_declaration > identifier': 'entity.name.function' - 'method_declaration > field_identifier': 'entity.name.function' - 'call_expression > selector_expression > field_identifier': 'entity.name.function' - - '"+"': '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' - '"|="': 'keyword.operator' - '":="': 'keyword.operator' - '"&"': 'keyword.operator' - '"*"': 'keyword.operator' - '"&&"': 'keyword.operator' - '"||"': 'keyword.operator' - '"..."': 'keyword.operator' - '"<-"': 'keyword.operator' + 'float_literal': 'constant.numeric.decimal' + 'imaginary_literal': 'constant.numeric.complex' + + 'nil': 'constant.language.null' + 'true': 'constant.language.boolean.true' + 'false': 'constant.language.boolean.false' + + # Comment + 'comment': 'comment.block' + + # 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' + + 'variadic_parameter_declaration > "..."': 'punctuation.definition.variadic' + 'variadic_argument > "..."': 'punctuation.definition.variadic.unpack' + 'implicit_length_array_type > "..."': 'punctuation.definition.collection.array' + + 'slice_expression > ":"': 'punctuation.separator.slice' + 'keyed_element > ":"': 'punctuation.separator.pair' + + 'parenthesized_expression > "("': 'punctuation.definition.expression' + 'parenthesized_expression > ")"': 'punctuation.definition.expression' + + 'parameter_list > "("': 'punctuation.definition.parameters' + 'parameter_list > ")"': 'punctuation.definition.parameters' + + 'argument_list > "("': 'punctuation.definition.arguments' + 'argument_list > ")"': 'punctuation.definition.arguments' + 'special_argument_list > "("': 'punctuation.definition.arguments' + 'special_argument_list > ")"': 'punctuation.definition.arguments' + 'type_switch_statement > "("': 'punctuation.definition.arguments' + 'type_switch_statement > ")"': 'punctuation.definition.arguments' + 'type_assertion_expression > "("': 'punctuation.definition.arguments' + 'type_assertion_expression > ")"': 'punctuation.definition.arguments' + 'type_conversion_expression > "("': 'punctuation.definition.arguments' + 'type_conversion_expression > ")"': 'punctuation.definition.arguments' + + 'import_spec_list > "("': 'punctuation.definition.package' + 'import_spec_list > ")"': 'punctuation.definition.package' + + 'const_declaration > "("': 'punctuation.definition.variable' + 'const_declaration > ")"': 'punctuation.definition.variable' + 'var_declaration > "("': 'punctuation.definition.variable' + 'var_declaration > ")"': 'punctuation.definition.variable' + + 'type_declaration > "("': 'punctuation.definition.type' + 'type_declaration > ")"': 'punctuation.definition.type' + 'parenthesized_type > "("': 'punctuation.definition.type' + 'parenthesized_type > ")"': 'punctuation.definition.type' + + 'literal_value > "{"': 'punctuation.definition.literal' + 'literal_value > "}"': 'punctuation.definition.literal' + + 'field_declaration_list > "{"': 'punctuation.definition.body.structure' + 'field_declaration_list > "}"': 'punctuation.definition.body.structure' + + 'method_spec_list > "{"': 'punctuation.definition.body.class.abstract' + 'method_spec_list > "}"': 'punctuation.definition.body.class.abstract' + + 'block > "{"': 'punctuation.definition.statement' + 'block > "}"': 'punctuation.definition.statement' + 'select_statement > "{"': 'punctuation.definition.statement' + 'select_statement > "}"': 'punctuation.definition.statement' + 'type_switch_statement > "{"': 'punctuation.definition.statement' + 'type_switch_statement > "}"': 'punctuation.definition.statement' + 'expression_switch_statement > "{"': 'punctuation.definition.statement' + 'expression_switch_statement > "}"': 'punctuation.definition.statement' + + 'func_literal > block > "{"': 'punctuation.definition.body.function' + 'func_literal > block > "}"': 'punctuation.definition.body.function' + 'function_declaration > block > "{"': 'punctuation.definition.body.function' + 'function_declaration > block > "}"': 'punctuation.definition.body.function' + 'method_declaration > block > "{"': 'punctuation.definition.body.function.method' + 'method_declaration > block > "}"': 'punctuation.definition.body.function.method' + + 'map_type > "["': 'punctuation.definition.collection.map' + 'map_type > "]"': 'punctuation.definition.collection.map' + 'slice_type > "["': 'punctuation.definition.collection.slice' + 'slice_type > "]"': 'punctuation.definition.collection.slice' + 'array_type > "["': 'punctuation.definition.collection.array' + 'array_type > "]"': 'punctuation.definition.collection.array' + 'implicit_length_array_type > "["': 'punctuation.definition.collection.array' + 'implicit_length_array_type > "]"': 'punctuation.definition.collection.array' + + 'index_expression > "["': 'punctuation.accessor.subscript.index' + 'index_expression > "]"': 'punctuation.accessor.subscript.index' + 'slice_expression > "["': 'punctuation.accessor.subscript.slice' + 'slice_expression > "]"': 'punctuation.accessor.subscript.slice' + + '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.invalid.illegal'