Skip to content

Commit

Permalink
feat: support Tact 1.5.0 (#40)
Browse files Browse the repository at this point in the history
* feat: `uint1-256` and `int1-256` through highlighting queries

* chore: remove highlighting of built-in functions, since functions in Tact aren't first-class

* feat: add new builtin constants and structs, and update tests

* feat: limited support of `asm` functions

With a note hinting at a possibility of using an external scanner
(lexer) to resolve the shortcomings of the current, parser-only approach

* chore: bump versions to 1.5.0

* feat: optional semicolon for the last field or function declaration in trait/contract bodies

* fix(CI): test tree-sitter-tact against the same version of the Tact compiler
  • Loading branch information
novusnota authored Sep 26, 2024
1 parent b3710fe commit d168040
Show file tree
Hide file tree
Showing 35 changed files with 11,201 additions and 6,342 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
test-swift: false # default

- name: Check correspondence to Ohm parser
if: ${{ runner.os != 'Windows' }}
run: |
git clone https://github.com/tact-lang/tact.git
git clone https://github.com/tact-lang/tact.git -b "v$(jq -r '.version' < package.json)"
npm run parse -- -q tact/src/grammar/test/*.tact
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-tact"
description = "Tact grammar for the tree-sitter"
version = "1.4.1"
version = "1.5.0"
authors = ["Novus Nota (https://github.com/novusnota)"]
license = "MIT"
keywords = ["incremental", "parsing", "tact"]
Expand Down
2 changes: 1 addition & 1 deletion Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ A fully-featured 🌳 [Tree-sitter](https://github.com/tree-sitter/tree-sitter)
- ⚙ Test-covered (including queries), reflects latest Tact language updates.
- 🚀 See guidelines on usage and integration in editors supporting Tree-sitter [below](#-usage).

Note, that the only limiting point are the `asm` functions introduced in Tact 1.5.0 — their bodies doesn't produce any highlighting and can be ill-parsed for now, so expect ERROR nodes in the parse tree. In the future, this is planned to be resolved by an external scanner — it can parse much more, and it can yield more tokens for subsequent highlighting.

## 🚀 Usage

### Neovim
Expand Down
33 changes: 9 additions & 24 deletions editor_queries/helix/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
">" ">=" ">>"
"&" "|" "^"
"&&" "||"
"->"
] @operator

; constructor
Expand All @@ -88,10 +89,8 @@
(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"))
(#match? @type.builtin
"^(coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))$"))

((type_identifier) @type.builtin
(#any-of? @type.builtin
Expand All @@ -108,7 +107,7 @@
">" @punctuation.bracket)

((identifier) @type.builtin
(#eq? @type.builtin "SendParameters")
(#any-of? @type.builtin "Context" "SendParameters" "StateInit" "StdAddress" "VarAddress")
(#is-not? local))

; string
Expand Down Expand Up @@ -152,6 +151,7 @@
"SendDestroyIfZero"
"SendRemainingValue"
"SendRemainingBalance"
"SendOnlyEstimateFee"
"ReserveExact"
"ReserveAllExcept"
"ReserveAtMost"
Expand Down Expand Up @@ -197,6 +197,7 @@
[
"fun"
"native"
"asm"
] @keyword.function

; keyword.directive
Expand Down Expand Up @@ -254,6 +255,9 @@
(native_function
name: (identifier) @function)

(asm_function
name: (identifier) @function)

(global_function
name: (identifier) @function)

Expand Down Expand Up @@ -281,25 +285,6 @@
(method_call_expression
name: (identifier) @function.method)

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

(static_call_expression
name: (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" "pow2" "log" "log2"
"throw" "dump" "dumpStack" "getConfigParam"
"nativeThrowIf" "nativeThrowUnless" "nativeReserve"
"nativeRandomize" "nativeRandomizeLt" "nativePrepareRandom" "nativeRandom" "nativeRandomInterval")
(#is-not? local))

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

Expand Down
2 changes: 2 additions & 0 deletions editor_queries/helix/indents.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
(trait_body)
(function_body)
(block_statement)
(asm_function_body)
(asm_list)

; misc.
(ternary_expression)
Expand Down
3 changes: 3 additions & 0 deletions editor_queries/helix/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
; function.inside & around
; ------------------------

(asm_function
body: (_) @function.inside) @function.around

(global_function
body: (_) @function.inside) @function.around

Expand Down
4 changes: 4 additions & 0 deletions editor_queries/neovim/context.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

; functions
; ---------
(asm_function
body: (_
(_) @context.end)) @context

(global_function
body: (_
(_) @context.end)) @context
Expand Down
2 changes: 2 additions & 0 deletions editor_queries/neovim/folds.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
(trait_body)
(function_body)
(block_statement)
(asm_function_body)
(asm_list)
] @fold
29 changes: 11 additions & 18 deletions editor_queries/neovim/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"^"
"&&"
"||"
"->"
] @operator

; constructor
Expand All @@ -78,7 +79,7 @@
; type.builtin
; ------------
((identifier) @type.builtin
(#eq? @type.builtin "SendParameters"))
(#any-of? @type.builtin "Context" "SendParameters" "StateInit" "StdAddress" "VarAddress"))

(bounced_type
"bounced" @type.builtin
Expand All @@ -96,9 +97,8 @@
(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"))
(#match? @type.builtin
"^(coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))$"))

; string
; ------
Expand Down Expand Up @@ -132,8 +132,9 @@
((identifier) @constant.builtin
(#any-of? @constant.builtin
"SendBounceIfActionFail" "SendPayGasSeparately" "SendIgnoreErrors" "SendDestroyIfZero"
"SendRemainingValue" "SendRemainingBalance" "ReserveExact" "ReserveAllExcept" "ReserveAtMost"
"ReserveAddOriginalBalance" "ReserveInvertSign" "ReserveBounceIfActionFail"))
"SendRemainingValue" "SendRemainingBalance" "SendOnlyEstimateFee" "ReserveExact"
"ReserveAllExcept" "ReserveAtMost" "ReserveAddOriginalBalance" "ReserveInvertSign"
"ReserveBounceIfActionFail"))

; property
; --------
Expand Down Expand Up @@ -177,6 +178,7 @@
[
"fun"
"native"
"asm"
] @keyword.function

; keyword.operator
Expand Down Expand Up @@ -244,6 +246,9 @@
(native_function
name: (identifier) @function)

(asm_function
name: (identifier) @function)

(global_function
name: (identifier) @function)

Expand Down Expand Up @@ -276,18 +281,6 @@
(method_call_expression
name: (identifier) @function.method.call)

; function.builtin
; ----------------
(static_call_expression
name: (identifier) @function.builtin
(#any-of? @function.builtin
"log" "log2" "send" "sender" "require" "now" "myBalance" "myAddress" "newAddress"
"contractAddress" "contractAddressExt" "emit" "cell" "ton" "dump" "dumpStack" "beginString"
"beginComment" "beginTailString" "beginStringFromBuilder" "beginCell" "emptyCell" "randomInt"
"random" "checkSignature" "checkDataSignature" "sha256" "min" "max" "abs" "pow" "pow2" "throw"
"nativeThrowIf" "nativeThrowUnless" "getConfigParam" "nativeRandomize" "nativeRandomizeLt"
"nativePrepareRandom" "nativeRandom" "nativeRandomInterval" "nativeReserve"))

; attribute
; ---------
[
Expand Down
2 changes: 2 additions & 0 deletions editor_queries/neovim/indents.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
(trait_body)
(function_body)
(block_statement)
(asm_function_body)
(asm_list)
; misc.
(binary_expression)
(ternary_expression)
Expand Down
5 changes: 5 additions & 0 deletions editor_queries/neovim/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
; Scopes @local.scope
; -------------------------
[
(asm_function)
(global_function)
(init_function)
(bounced_function)
Expand All @@ -30,6 +31,10 @@
name: (identifier) @local.definition.constant)

; functions
(asm_function
name: (identifier) @local.definition.function
(#set! definition.var.scope parent))

(global_function
name: (identifier) @local.definition.function
(#set! definition.var.scope parent))
Expand Down
21 changes: 20 additions & 1 deletion editor_queries/neovim/textobjects.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
; See: https://github.com/nvim-treesitter/nvim-treesitter-textobjects#built-in-textobjects
; function.inner & outer
; ----------------------
; asm
(asm_function
body: (_)) @function.outer

(asm_function
body: (asm_function_body
.
"{"
.
(_) @_start
(_)? @_end
.
"}")
(#make-range! "function.inner" @_start @_end))

; global
(global_function
body: (_)) @function.outer
Expand Down Expand Up @@ -149,7 +164,8 @@
; -----------------------
("@name"
"("
func_name: (func_identifier) @attribute.inner")") @attribute.outer
func_name: (func_identifier) @attribute.inner
")") @attribute.outer

(contract_attributes
("@interface"
Expand Down Expand Up @@ -255,6 +271,9 @@
(_
(block_statement) @block.inner) @block.outer

(_
(asm_list) @block.inner) @block.outer

; call.inner & outer
; ------------------
(method_call_expression) @call.outer
Expand Down
Loading

0 comments on commit d168040

Please sign in to comment.