-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(treesitter): add Move language syntax highlighting and parser setup
- Add tree-sitter parser configuration for Move language - Add syntax highlighting queries for Move language features
- Loading branch information
Showing
4 changed files
with
223 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
;; Highlights file for Move | ||
|
||
;; Types | ||
(type_parameters) @type | ||
(type_parameter) @type | ||
(type_parameter_identifier) @type | ||
(apply_type) @type | ||
(ref_type) @type.ref | ||
(primitive_type) @type.builtin | ||
|
||
;; Comments | ||
(line_comment) @comment | ||
(block_comment) @comment | ||
|
||
;; Annotations | ||
(annotation) @annotation | ||
(annotation_item) @annotation.item | ||
|
||
;; Constants | ||
(constant name: (constant_identifier) @constant.name) | ||
(constant expr: (num_literal) @constant.value) | ||
((identifier) @constant.name | ||
(#match? @constant.name "^[A-Z][A-Z\\d_]+$'")) | ||
|
||
;; Function definitions | ||
(function_definition name: (function_identifier) @function) | ||
(macro_function_definition name: (function_identifier) @macro) | ||
(native_function_definition name: (function_identifier) @function) | ||
(usual_spec_function name: (function_identifier) @function) | ||
(function_parameter name: (variable_identifier) @variable.parameter) | ||
|
||
;; Module definitions | ||
(module_identity address: (module_identifier) @namespace.module.address) | ||
(module_identity module: (module_identifier) @namespace.module.name) | ||
|
||
;; Function calls | ||
(call_expression (name_expression access: (module_access module: (module_identifier) @namespace.module.name))) | ||
(call_expression (name_expression access: (module_access member: (identifier) @function.call))) | ||
|
||
|
||
(label (identifier) @label) | ||
|
||
;; Macro calls | ||
(macro_call_expression access: (macro_module_access) @macro.call) | ||
|
||
;; Literals | ||
(num_literal) @number | ||
(bool_literal) @boolean | ||
(hex_string_literal) @string.hex | ||
(byte_string_literal) @string.byte | ||
(address_literal) @number.address | ||
|
||
;; Binders | ||
|
||
;; Uses | ||
(use_member member: (identifier) @include.member) | ||
(use_module alias: (module_identifier) @namespace.module.name) | ||
|
||
(use_fun (module_access module: (module_identifier) @namespace.module.name)) | ||
(use_fun (module_access member: (identifier) @include.member)) | ||
|
||
(function_identifier) @function.name | ||
|
||
;; Friends | ||
; (friend_access local_module: (identifier) @namespace.module.name) | ||
|
||
;; Structs | ||
(struct_definition name: (struct_identifier) @type.definition.struct) | ||
(ability) @type.ability | ||
(field_annotation field: (field_identifier) @field.identifier) | ||
(field_identifier) @field.identifier | ||
|
||
;; Enums | ||
(enum_definition name: (enum_identifier) @type.definition.struct) | ||
(variant variant_name: (variant_identifier) @constructor.name) | ||
|
||
;; Packs | ||
(pack_expression (name_expression access: (module_access) @constructor.name)) | ||
|
||
;; Unpacks | ||
;; TODO: go into variants | ||
(bind_unpack (name_expression) @type.name) | ||
(module_access "$" (identifier) @macro.variable) | ||
"$" @macro.variable | ||
|
||
(module_access module: (module_identifier) member: (identifier) @constructor.name) | ||
|
||
(abort_expression) @keyword | ||
(mut_ref) @keyword | ||
|
||
;; Lambdas | ||
; (lambda_binding bind: (bind_var (variable_identifier) @variable.parameter)) | ||
; (lambda_bindings (bind_var (variable_identifier) @variable.parameter)) | ||
|
||
|
||
;; Operators | ||
(binary_operator) @operator | ||
(unary_op) @operator | ||
"=>" @operator | ||
"@" @operator | ||
"->" @operator | ||
|
||
;; Specs | ||
(spec_block target: (identifier) @function.spec.target) | ||
(spec_pragma) @preproc.annotation.spec | ||
(spec_condition kind: (condition_kind) @condition.spec) | ||
(condition_properties) @preproc.spec.condition.properties | ||
|
||
; (match_expression "match") @keyword | ||
|
||
;; Spec keywords | ||
; "opaque" @keyword | ||
; "aborts_if" @keyword | ||
; "abstract" @keyword | ||
[ | ||
"pragma" | ||
] @keyword | ||
|
||
;; Source Language Keywords | ||
[ | ||
"fun" | ||
"return" | ||
"if" | ||
"else" | ||
"while" | ||
"native" | ||
"struct" | ||
"use" | ||
"public" | ||
"package" | ||
"spec" | ||
"module" | ||
"abort" | ||
"const" | ||
"let" | ||
"has" | ||
"as" | ||
"&" | ||
"friend" | ||
"entry" | ||
"mut" | ||
"macro" | ||
"enum" | ||
"break" | ||
"continue" | ||
"loop" | ||
] @keyword | ||
|
||
"match" @keyword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
; Function Scope | ||
; (function_definition | ||
; body: (block) @scope | ||
; parameters: (function_parameters (function_parameter name: (variable_identifier) @definition.var))) | ||
|
||
(function_definition body: (block) @scope) | ||
|
||
(function_parameter name: (variable_identifier) @definition.var) | ||
(function_parameter name: (variable_identifier) @local.definition) | ||
|
||
(identifier) @local.reference | ||
|
||
|
||
; Module and Struct Scope | ||
(module_definition | ||
(module_body) @scope) | ||
|
||
; (struct_definition | ||
; (struct_def_fields) @scope) | ||
|
||
; Spec Block Scope | ||
(spec_block | ||
body: (spec_body) @scope) | ||
|
||
; Local Variable Declarations in Function Blocks | ||
; (let_statement | ||
; binds: (bind_list | ||
; (bind_var (variable_identifier) @definition.var) | ||
; (bind_unpack | ||
; (bind_field (field_identifier) @definition.var)))) | ||
|
||
; Local Variable Declarations in Spec Blocks | ||
; (spec_block | ||
; (spec_variable name: (identifier) @definition.var)) | ||
|
||
; Parameters in Spec Functions | ||
; (spec_function | ||
; parameters: (function_parameters (function_parameter name: (identifier) @definition.var))) | ||
; | ||
; ; Type Parameters | ||
; (type_parameters | ||
; (type_parameter name: (identifier) @definition.type))) | ||
; | ||
; ; Struct Fields | ||
; (struct_definition | ||
; (struct_def_fields | ||
; (field_annotation | ||
; field: (identifier) @definition.field))) | ||
; | ||
; ; Function and Module Identifiers | ||
; (function_definition name: (identifier) @definition.function) | ||
; (module_definition name: (identifier) @definition.module) | ||
; |