From 605ad5fae28d01fe3ec4283278eda6833ba04770 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 | 329 ++++++++++++++++++++++++++--------- 1 file changed, 246 insertions(+), 83 deletions(-) diff --git a/grammars/tree-sitter-go.cson b/grammars/tree-sitter-go.cson index 533dd20..b7e57bb 100644 --- a/grammars/tree-sitter-go.cson +++ b/grammars/tree-sitter-go.cson @@ -43,88 +43,251 @@ 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.symbolic' + '"-"': 'keyword.operator.arithmetic.symbolic' + 'binary_expression > "*"': 'keyword.operator.arithmetic.symbolic' + '"/"': 'keyword.operator.arithmetic.symbolic' + '"%"': 'keyword.operator.arithmetic.symbolic' + '"++"': 'keyword.operator.arithmetic.symbolic' + '"--"': 'keyword.operator.arithmetic.symbolic' + + 'binary_expression > "&"': 'keyword.operator.bitwise.symbolic' + '"|"': 'keyword.operator.bitwise.symbolic' + '"^"': 'keyword.operator.bitwise.symbolic' + '"&^"': 'keyword.operator.bitwise.symbolic' + '"<<"': 'keyword.operator.bitwise.shift.symbolic' + '">>"': 'keyword.operator.bitwise.shift.symbolic' + + '"="': 'keyword.operator.assignment.symbolic' + '":="': 'keyword.operator.assignment.symbolic' + '"+="': 'keyword.operator.assignment.compound.symbolic' + '"-="': 'keyword.operator.assignment.compound.symbolic' + '"*="': 'keyword.operator.assignment.compound.symbolic' + '"/="': 'keyword.operator.assignment.compound.symbolic' + '"%="': 'keyword.operator.assignment.compound.symbolic' + '"&="': 'keyword.operator.assignment.compound.symbolic' + '"|="': 'keyword.operator.assignment.compound.symbolic' + '"^="': 'keyword.operator.assignment.compound.symbolic' + '"<<="': 'keyword.operator.assignment.compound.symbolic' + '">>="': 'keyword.operator.assignment.compound.symbolic' + + '"=="': 'keyword.operator.comparison.symbolic' + '"!="': 'keyword.operator.comparison.symbolic' + '"<"': 'keyword.operator.comparison.symbolic' + '">"': 'keyword.operator.comparison.symbolic' + '"<="': 'keyword.operator.comparison.symbolic' + '">="': 'keyword.operator.comparison.symbolic' + + '"!"': 'keyword.operator.logical.symbolic' + '"&&"': 'keyword.operator.logical.symbolic' + '"||"': 'keyword.operator.logical.symbolic' + + '"&"': 'keyword.operator.pointer.reference.symbolic' + '"*"': 'keyword.operator.pointer.dereference.symbolic' + + '"<-"': 'keyword.operator.channel.symbolic' + + '"var"': 'keyword.storage.declaration' + '"const"': 'keyword.storage.declaration' + '"map"': 'keyword.storage.declaration' + '"chan"': 'keyword.storage.declaration' + '"func"': 'keyword.storage.declaration' + '"type"': 'keyword.storage.declaration' + '"struct"': 'keyword.storage.declaration' + '"interface"': 'keyword.storage.declaration' + + # 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: '^\\\\[uUxftvnrab0-9]', + scopes: 'constant.character.escape.code' + }, + '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.accessor.member' + '";"': 'punctuation.delimiter.statement' + '":"': 'punctuation.delimiter' + '","': 'punctuation.delimiter' + '"("': 'punctuation.delimiter' + '")"': 'punctuation.delimiter' + '"{"': 'punctuation.delimiter' + '"}"': 'punctuation.delimiter' + '"["': 'punctuation.definition' + '"]"': 'punctuation.definition' + '"\\""': 'punctuation.definition.string' + + 'variadic_parameter_declaration > "..."': 'punctuation.alteration.variadic' + 'variadic_argument > "..."': 'punctuation.alteration.variadic.unpack' + 'implicit_length_array_type > "..."': 'punctuation.definition.collection.array' + + 'slice_expression > ":"': 'punctuation.delimiter.slice' + 'keyed_element > ":"': 'punctuation.delimiter.pair' + + 'parenthesized_expression > "("': 'punctuation.delimiter.expression' + 'parenthesized_expression > ")"': 'punctuation.delimiter.expression' + + 'parameter_list > "("': 'punctuation.delimiter.parameters' + 'parameter_list > ")"': 'punctuation.delimiter.parameters' + + 'argument_list > "("': 'punctuation.delimiter.arguments' + 'argument_list > ")"': 'punctuation.delimiter.arguments' + 'special_argument_list > "("': 'punctuation.delimiter.arguments' + 'special_argument_list > ")"': 'punctuation.delimiter.arguments' + 'type_switch_statement > "("': 'punctuation.delimiter.arguments' + 'type_switch_statement > ")"': 'punctuation.delimiter.arguments' + 'type_assertion_expression > "("': 'punctuation.delimiter.arguments' + 'type_assertion_expression > ")"': 'punctuation.delimiter.arguments' + 'type_conversion_expression > "("': 'punctuation.delimiter.arguments' + 'type_conversion_expression > ")"': 'punctuation.delimiter.arguments' + + 'import_spec_list > "("': 'punctuation.delimiter.package' + 'import_spec_list > ")"': 'punctuation.delimiter.package' + + 'const_declaration > "("': 'punctuation.delimiter.variable' + 'const_declaration > ")"': 'punctuation.delimiter.variable' + 'var_declaration > "("': 'punctuation.delimiter.variable' + 'var_declaration > ")"': 'punctuation.delimiter.variable' + + 'type_declaration > "("': 'punctuation.delimiter.type' + 'type_declaration > ")"': 'punctuation.delimiter.type' + 'parenthesized_type > "("': 'punctuation.delimiter.type' + 'parenthesized_type > ")"': 'punctuation.delimiter.type' + + 'literal_value > "{"': 'punctuation.definition.collection' + 'literal_value > "}"': 'punctuation.definition.collection' + + 'field_declaration_list > "{"': 'punctuation.delimiter.body.structure' + 'field_declaration_list > "}"': 'punctuation.delimiter.body.structure' + + 'method_spec_list > "{"': 'punctuation.delimiter.body.class.abstract' + 'method_spec_list > "}"': 'punctuation.delimiter.body.class.abstract' + + 'block > "{"': 'punctuation.delimiter.statement' + 'block > "}"': 'punctuation.delimiter.statement' + 'select_statement > "{"': 'punctuation.delimiter.statement' + 'select_statement > "}"': 'punctuation.delimiter.statement' + 'type_switch_statement > "{"': 'punctuation.delimiter.statement' + 'type_switch_statement > "}"': 'punctuation.delimiter.statement' + 'expression_switch_statement > "{"': 'punctuation.delimiter.statement' + 'expression_switch_statement > "}"': 'punctuation.delimiter.statement' + + 'func_literal > block > "{"': 'punctuation.delimiter.body.function' + 'func_literal > block > "}"': 'punctuation.delimiter.body.function' + 'function_declaration > block > "{"': 'punctuation.delimiter.body.function' + 'function_declaration > block > "}"': 'punctuation.delimiter.body.function' + 'method_declaration > block > "{"': 'punctuation.delimiter.body.function.method' + 'method_declaration > block > "}"': 'punctuation.delimiter.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.accessor.member.invalid.illegal' + 'ERROR > ";"': 'punctuation.delimiter.statement.invalid.illegal' + 'ERROR > ":"': 'punctuation.delimiter.invalid.illegal' + 'ERROR > ","': 'punctuation.delimiter.invalid.illegal' + 'ERROR > "("': 'punctuation.delimiter.invalid.illegal' + 'ERROR > ")"': 'punctuation.delimiter.invalid.illegal' + 'ERROR > "{"': 'punctuation.delimiter.invalid.illegal' + 'ERROR > "}"': 'punctuation.delimiter.invalid.illegal' + 'ERROR > "["': 'punctuation.definition.invalid.illegal' + 'ERROR > "]"': 'punctuation.definition.invalid.illegal' + 'ERROR > "..."': 'punctuation.alteration.invalid.illegal' + 'ERROR > "\\""': 'punctuation.definition.string.invalid.illegal'