Skip to content

Commit

Permalink
feat: Add Tact language support (helix-editor#9512)
Browse files Browse the repository at this point in the history
Re-submitting
  • Loading branch information
novusnota authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 32f716a commit 2fc2cf0
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
| swift || | | `sourcekit-lsp` |
| t32 || | | |
| tablegen |||| |
| tact |||| |
| task || | | |
| templ || | | `templ` |
| tfvars || || `terraform-ls` |
Expand Down
19 changes: 19 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3042,3 +3042,22 @@ indent = { tab-width = 2, unit = " " }
[[grammar]]
name = "hocon"
source = { git = "https://github.com/antosha417/tree-sitter-hocon", rev = "c390f10519ae69fdb03b3e5764f5592fb6924bcc" }

[[language]]
name = "tact"
scope = "source.tact"
injection-regex = "tact"
file-types = ["tact"]
comment-token = "//"
indent = { tab-width = 4, unit = " " }

[language.auto-pairs]
'"' = '"'
'{' = '}'
'(' = ')'
'<' = '>'

[[grammar]]
name = "tact"
source = { git = "https://github.com/tact-lang/tree-sitter-tact", rev = "ec57ab29c86d632639726631fb2bb178d23e1c91" }

298 changes: 298 additions & 0 deletions runtime/queries/tact/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
; See: https://docs.helix-editor.com/master/themes.html#syntax-highlighting
; -------------------------------------------------------------------------

; attribute
; ---------

[
"@name"
"@interface"
] @attribute

; comment.line
; ------------

((comment) @comment.line
(#match? @comment.line "^//"))

; comment.block
; -------------

(comment) @comment.block

; function.builtin
; ----------------

((identifier) @function.builtin
(#any-of? @function.builtin
"send" "sender" "require" "now"
"myBalance" "myAddress" "newAddress"
"contractAddress" "contractAddressExt"
"emit" "cell" "ton"
"beginString" "beginComment" "beginTailString" "beginStringFromBuilder" "beginCell" "emptyCell"
"randomInt" "random"
"checkSignature" "checkDataSignature" "sha256"
"min" "max" "abs" "pow"
"throw" "dump" "getConfigParam"
"nativeThrowWhen" "nativeThrowUnless" "nativeReserve"
"nativeRandomize" "nativeRandomizeLt" "nativePrepareRandom" "nativeRandom" "nativeRandomInterval")
(#is-not? local))

; function.method
; ---------------

(method_call_expression
name: (identifier) @function.method)

; function
; --------

(func_identifier) @function

(native_function
name: (identifier) @function)

(static_function
name: (identifier) @function)

(static_call_expression
name: (identifier) @function)

(init_function
"init" @function.method)

(receive_function
"receive" @function.method)

(bounced_function
"bounced" @function.method)

(external_function
"external" @function.method)

(function
name: (identifier) @function.method)

; keyword.control.conditional
; ---------------------------

[
"if" "else"
] @keyword.control.conditional

; keyword.control.repeat
; ----------------------

[
"while" "repeat" "do" "until"
] @keyword.control.repeat

; keyword.control.import
; ----------------------

"import" @keyword.control.import

; keyword.control.return
; ----------------------

"return" @keyword.control.return

; keyword.operator
; ----------------

"initOf" @keyword.operator

; keyword.directive
; -----------------

"primitive" @keyword.directive

; keyword.function
; ----------------

[
"fun"
"native"
] @keyword.function

; keyword.storage.type
; --------------------

[
"contract" "trait" "struct" "message" "with"
"const" "let"
] @keyword.storage.type

; keyword.storage.modifier
; ------------------------

[
"get" "mutates" "extends" "virtual" "override" "inline" "abstract"
] @keyword.storage.modifier

; keyword
; -------

[
"with"
; "public" ; -- not used, but declared in grammar.ohm
; "extend" ; -- not used, but declared in grammar.ohm
] @keyword

; constant.builtin.boolean
; ------------------------

(boolean) @constant.builtin.boolean

; constant.builtin
; ----------------

((identifier) @constant.builtin
(#any-of? @constant.builtin
"SendPayGasSeparately"
"SendIgnoreErrors"
"SendDestroyIfZero"
"SendRemainingValue"
"SendRemainingBalance")
(#is-not? local))

(null) @constant.builtin

; constant.numeric.integer
; ------------------------

(integer) @constant.numeric.integer

; constant
; --------

(constant
name: (identifier) @constant)

; string.special.path
; -------------------

(import_statement
library: (string) @string.special.path)

; string
; ------

(string) @string

; type.builtin
; ------------

(tlb_serialization
"as" @keyword
type: (identifier) @type.builtin
(#any-of? @type.builtin
"int8" "int16" "int32" "int64" "int128" "int256" "int257"
"uint8" "uint16" "uint32" "uint64" "uint128" "uint256"
"coins" "remaining" "bytes32" "bytes64"))

((type_identifier) @type.builtin
(#any-of? @type.builtin
"Address" "Bool" "Builder" "Cell" "Int" "Slice" "String" "StringBuilder"))

(map_type
"map" @type.builtin
"<" @punctuation.bracket
">" @punctuation.bracket)

(bounced_type
"bounced" @type.builtin
"<" @punctuation.bracket
">" @punctuation.bracket)

((identifier) @type.builtin
(#eq? @type.builtin "SendParameters")
(#is-not? local))

; type
; ----

(type_identifier) @type

; constructor
; -----------

(instance_expression
name: (identifier) @constructor)

(initOf
name: (identifier) @constructor)

; operator
; --------

[
"-" "-="
"+" "+="
"*" "*="
"/" "/="
"%" "%="
"=" "=="
"!" "!=" "!!"
"<" "<=" "<<"
">" ">=" ">>"
"&" "|"
"&&" "||"
] @operator

; punctuation.bracket
; -------------------

[
"(" ")"
"{" "}"
] @punctuation.bracket

; punctuation.delimiter
; ---------------------

[
";"
","
"."
":"
"?"
] @punctuation.delimiter

; variable.other.member
; ---------------------

(field
name: (identifier) @variable.other.member)

(contract_body
(constant
name: (identifier) @variable.other.member))

(trait_body
(constant
name: (identifier) @variable.other.member))

(field_access_expression
name: (identifier) @variable.other.member)

(lvalue (_) (_) @variable.other.member)

(instance_argument
name: (identifier) @variable.other.member)

; variable.parameter
; ------------------

(parameter
name: (identifier) @variable.parameter)

; variable.builtin
; ----------------

(self) @variable.builtin

; variable
; --------

(identifier) @variable
38 changes: 38 additions & 0 deletions runtime/queries/tact/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; indent
; ------

[
; (..., ...)
(parameter_list)
(argument_list)

; {..., ...}
(instance_argument_list)

; {...; ...}
(message_body)
(struct_body)
(contract_body)
(trait_body)
(function_body)
(block_statement)

; misc.
(binary_expression)
(return_statement)
] @indent

; outdent
; -------

[
"}"
")"
">"
] @outdent

; indent.always
; outdent.always
; align
; extend
; extend.prevent-once
5 changes: 5 additions & 0 deletions runtime/queries/tact/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; See: https://docs.helix-editor.com/guides/injection.html

((comment) @injection.content
(#set! injection.language "comment")
(#match? @injection.content "^//"))
Loading

0 comments on commit 2fc2cf0

Please sign in to comment.