feat!: drop modules, general refactor and cleanup

This commit is contained in:
Christian Clason 2023-06-12 09:54:30 -06:00
parent 310f0925ec
commit 692b051b09
1247 changed files with 6096 additions and 9074 deletions

View file

@ -0,0 +1,20 @@
[
(mod_item)
(function_item)
(struct_item)
(trait_item)
(enum_item)
(impl_item)
(type_item)
(const_item)
(let_declaration)
(for_expression)
(while_expression)
(if_expression)
(match_expression)
(call_expression)
(array_expression)
(attribute_item)
(block)
(use_declaration)+
] @fold

View file

@ -0,0 +1,336 @@
(type_identifier) @type
(identifier) @variable
(field_identifier) @variable.member
(escape_sequence) @string.escape
(primitive_type) @type.builtin
(boolean_literal) @boolean
(integer_literal) @number
(float_literal) @number.float
(char_literal) @character
; -------
; Paths
; -------
(use_declaration
argument: (identifier) @module)
(use_wildcard
(identifier) @module)
(mod_item
name: (identifier) @module)
(scoped_use_list
path: (identifier)? @module)
(use_list
(identifier) @module)
(use_as_clause
path: (identifier)? @module
alias: (identifier) @module)
; ---
; Remaining Paths
; ---
(scoped_identifier
path: (identifier)? @module
name: (identifier) @module)
(scoped_type_identifier
path: (identifier) @module)
[
"*"
"'"
"->"
"=>"
"<="
"="
"=="
"!"
"!="
"%"
"%="
"&"
"&="
"&&"
"|"
"|="
"||"
"^"
"^="
"*"
"*="
"-"
"-="
"+"
"+="
"/"
"/="
">"
"<"
">="
">>"
"<<"
">>="
"<<="
"@"
".."
"..="
"'"
"?"
] @operator
(use_wildcard
"*" @character.special)
[
(string_literal)
(raw_string_literal)
] @string
[
(line_comment)
(block_comment)
] @comment
; ---
; Extraneous
; ---
(self) @variable.builtin
(enum_variant
(identifier) @constant)
(field_initializer
(field_identifier) @variable.member)
(shorthand_field_initializer
(identifier) @variable.member)
(shorthand_field_identifier) @variable.member
(loop_label
"'" @label
(identifier) @label)
; ---
; Punctuation
; ---
[
"::"
":"
"."
";"
","
] @punctuation.delimiter
[
"("
")"
"["
"]"
"{"
"}"
"#"
] @punctuation.bracket
(type_arguments
[
"<"
">"
] @punctuation.bracket)
(type_parameters
[
"<"
">"
] @punctuation.bracket)
(closure_parameters
"|" @punctuation.bracket)
(let_declaration
pattern: [
(identifier) @variable
(tuple_pattern
(identifier) @variable)
])
; It needs to be anonymous to not conflict with `call_expression` further below.
(_
value: (field_expression
value: (identifier)? @variable
field: (field_identifier) @variable.member))
(parameter
pattern: (identifier) @variable.parameter)
(parameter
pattern: (ref_pattern
[
(mut_pattern
(identifier) @variable.parameter)
(identifier) @variable.parameter
]))
(closure_parameters
(identifier) @variable.parameter)
(for_expression
"for" @keyword.repeat)
"in" @keyword.repeat
[
"match"
"if"
"else"
] @keyword.conditional
"while" @keyword.repeat
[
"break"
"continue"
"return"
"yield"
] @keyword.return
"use" @keyword.import
(mod_item
"mod" @keyword.import
!body)
(use_as_clause
"as" @keyword.import)
(type_cast_expression
"as" @keyword.operator)
[
"as"
"mod"
"abi"
"impl"
"where"
"trait"
"for"
"let"
"contract"
"script"
"predicate"
"library"
] @keyword
[
"struct"
"enum"
"storage"
"configurable"
"type"
] @keyword.type
[
"fn"
"abi"
] @keyword.function
[
(mutable_specifier)
"const"
"ref"
"deref"
"move"
"pub"
] @keyword.modifier
(reference_type
"&" @keyword.modifier)
(self_parameter
"&" @keyword.modifier)
; -------
; Guess Other Types
; -------
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
; ---
; PascalCase identifiers in call_expressions (e.g. `Ok()`)
; are assumed to be enum constructors.
; ---
(call_expression
function: [
((identifier) @constant
(#lua-match? @constant "^[A-Z]"))
(scoped_identifier
name: ((identifier) @constant
(#lua-match? @constant "^[A-Z]")))
])
; ---
; Assume that types in match arms are enums and not
; tuple structs. Same for `if let` expressions.
; ---
(match_pattern
(scoped_identifier
name: (identifier) @constructor))
(tuple_struct_pattern
type: [
(identifier) @constructor
(scoped_identifier
name: (identifier) @constructor)
])
(struct_pattern
type: [
(type_identifier) @constructor
(scoped_type_identifier
name: (type_identifier) @constructor)
])
; ---
; Other PascalCase identifiers are assumed to be structs.
; ---
((identifier) @type
(#lua-match? @type "^[A-Z]"))
; -------
; Functions
; -------
(call_expression
function: [
(identifier) @function.call
(scoped_identifier
name: (identifier) @function.call)
(field_expression
field: (field_identifier) @function.method.call)
])
(generic_function
function: [
(identifier) @function.call
(scoped_identifier
name: (identifier) @function.call)
(field_expression
field: (field_identifier) @function.method.call)
])
(function_item
name: (identifier) @function)
(function_signature_item
name: (identifier) @function)

View file

@ -0,0 +1,95 @@
[
(mod_item)
(struct_item)
(enum_item)
(impl_item)
(struct_expression)
(struct_pattern)
(tuple_struct_pattern)
(tuple_expression)
(tuple_type)
(tuple_pattern)
(match_block)
(call_expression)
(asm_block)
(asm_parameters)
(assignment_expression)
(arguments)
(block)
(where_clause)
(use_list)
(array_expression)
(ordered_field_declaration_list)
(field_declaration_list)
(enum_variant_list)
(parameters)
(token_tree)
] @indent.begin
(trait_item
body: (_) @indent.begin)
(string_literal
(escape_sequence)) @indent.begin
(block
"}" @indent.end)
(asm_block
"}" @indent.end)
(enum_item
body: (enum_variant_list
"}" @indent.end))
(impl_item
body: (declaration_list
"}" @indent.end))
(match_expression
body: (match_block
"}" @indent.end))
(struct_item
body: (field_declaration_list
"}" @indent.end))
(struct_expression
body: (field_initializer_list
"}" @indent.end))
(struct_pattern
"}" @indent.end)
(tuple_struct_pattern
")" @indent.end)
(tuple_type
")" @indent.end)
(tuple_pattern
")" @indent.end)
(trait_item
body: (declaration_list
"}" @indent.end))
(impl_item
(where_clause) @indent.dedent)
[
"where"
")"
"]"
"}"
] @indent.branch
(impl_item
(declaration_list) @indent.branch)
[
(line_comment)
(string_literal)
] @indent.ignore
(raw_string_literal) @indent.auto

View file

@ -0,0 +1,5 @@
([
(line_comment)
(block_comment)
] @injection.content
(#set! injection.language "comment"))

View file

@ -0,0 +1,16 @@
; Scopes
[
(function_item)
(closure_expression)
(block)
] @local.scope
; Definitions
(parameter
(identifier) @local.definition)
(closure_parameters
(identifier) @local.definition)
; References
(identifier) @local.reference