Skip to content

Commit d168040

Browse files
authored
feat: support Tact 1.5.0 (#40)
* 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
1 parent b3710fe commit d168040

35 files changed

+11201
-6342
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
test-swift: false # default
3737

3838
- name: Check correspondence to Ohm parser
39+
if: ${{ runner.os != 'Windows' }}
3940
run: |
40-
git clone https://github.com/tact-lang/tact.git
41+
git clone https://github.com/tact-lang/tact.git -b "v$(jq -r '.version' < package.json)"
4142
npm run parse -- -q tact/src/grammar/test/*.tact

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "tree-sitter-tact"
33
description = "Tact grammar for the tree-sitter"
4-
version = "1.4.1"
4+
version = "1.5.0"
55
authors = ["Novus Nota (https://github.com/novusnota)"]
66
license = "MIT"
77
keywords = ["incremental", "parsing", "tact"]

Makefile

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ A fully-featured 🌳 [Tree-sitter](https://github.com/tree-sitter/tree-sitter)
1111
- ⚙ Test-covered (including queries), reflects latest Tact language updates.
1212
- 🚀 See guidelines on usage and integration in editors supporting Tree-sitter [below](#-usage).
1313

14+
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.
15+
1416
## 🚀 Usage
1517

1618
### Neovim

editor_queries/helix/highlights.scm

+9-24
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
">" ">=" ">>"
6767
"&" "|" "^"
6868
"&&" "||"
69+
"->"
6970
] @operator
7071

7172
; constructor
@@ -88,10 +89,8 @@
8889
(tlb_serialization
8990
"as" @keyword
9091
type: (identifier) @type.builtin
91-
(#any-of? @type.builtin
92-
"int8" "int16" "int32" "int64" "int128" "int256" "int257"
93-
"uint8" "uint16" "uint32" "uint64" "uint128" "uint256"
94-
"coins" "remaining" "bytes32" "bytes64"))
92+
(#match? @type.builtin
93+
"^(coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))$"))
9594

9695
((type_identifier) @type.builtin
9796
(#any-of? @type.builtin
@@ -108,7 +107,7 @@
108107
">" @punctuation.bracket)
109108

110109
((identifier) @type.builtin
111-
(#eq? @type.builtin "SendParameters")
110+
(#any-of? @type.builtin "Context" "SendParameters" "StateInit" "StdAddress" "VarAddress")
112111
(#is-not? local))
113112

114113
; string
@@ -152,6 +151,7 @@
152151
"SendDestroyIfZero"
153152
"SendRemainingValue"
154153
"SendRemainingBalance"
154+
"SendOnlyEstimateFee"
155155
"ReserveExact"
156156
"ReserveAllExcept"
157157
"ReserveAtMost"
@@ -197,6 +197,7 @@
197197
[
198198
"fun"
199199
"native"
200+
"asm"
200201
] @keyword.function
201202

202203
; keyword.directive
@@ -254,6 +255,9 @@
254255
(native_function
255256
name: (identifier) @function)
256257

258+
(asm_function
259+
name: (identifier) @function)
260+
257261
(global_function
258262
name: (identifier) @function)
259263

@@ -281,25 +285,6 @@
281285
(method_call_expression
282286
name: (identifier) @function.method)
283287

284-
; function.builtin
285-
; ----------------
286-
287-
(static_call_expression
288-
name: (identifier) @function.builtin
289-
(#any-of? @function.builtin
290-
"send" "sender" "require" "now"
291-
"myBalance" "myAddress" "newAddress"
292-
"contractAddress" "contractAddressExt"
293-
"emit" "cell" "ton"
294-
"beginString" "beginComment" "beginTailString" "beginStringFromBuilder" "beginCell" "emptyCell"
295-
"randomInt" "random"
296-
"checkSignature" "checkDataSignature" "sha256"
297-
"min" "max" "abs" "pow" "pow2" "log" "log2"
298-
"throw" "dump" "dumpStack" "getConfigParam"
299-
"nativeThrowIf" "nativeThrowUnless" "nativeReserve"
300-
"nativeRandomize" "nativeRandomizeLt" "nativePrepareRandom" "nativeRandom" "nativeRandomInterval")
301-
(#is-not? local))
302-
303288
; attribute
304289
; ---------
305290

editor_queries/helix/indents.scm

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
(trait_body)
1919
(function_body)
2020
(block_statement)
21+
(asm_function_body)
22+
(asm_list)
2123

2224
; misc.
2325
(ternary_expression)

editor_queries/helix/textobjects.scm

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
; function.inside & around
44
; ------------------------
55

6+
(asm_function
7+
body: (_) @function.inside) @function.around
8+
69
(global_function
710
body: (_) @function.inside) @function.around
811

editor_queries/neovim/context.scm

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
; functions
2121
; ---------
22+
(asm_function
23+
body: (_
24+
(_) @context.end)) @context
25+
2226
(global_function
2327
body: (_
2428
(_) @context.end)) @context

editor_queries/neovim/folds.scm

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
(trait_body)
1515
(function_body)
1616
(block_statement)
17+
(asm_function_body)
18+
(asm_list)
1719
] @fold

editor_queries/neovim/highlights.scm

+11-18
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"^"
6262
"&&"
6363
"||"
64+
"->"
6465
] @operator
6566

6667
; constructor
@@ -78,7 +79,7 @@
7879
; type.builtin
7980
; ------------
8081
((identifier) @type.builtin
81-
(#eq? @type.builtin "SendParameters"))
82+
(#any-of? @type.builtin "Context" "SendParameters" "StateInit" "StdAddress" "VarAddress"))
8283

8384
(bounced_type
8485
"bounced" @type.builtin
@@ -96,9 +97,8 @@
9697
(tlb_serialization
9798
"as" @keyword
9899
type: (identifier) @type.builtin
99-
(#any-of? @type.builtin
100-
"int8" "int16" "int32" "int64" "int128" "int256" "int257" "uint8" "uint16" "uint32" "uint64"
101-
"uint128" "uint256" "coins" "remaining" "bytes32" "bytes64"))
100+
(#match? @type.builtin
101+
"^(coins|remaining|bytes32|bytes64|int257|u?int(?:2[0-5][0-6]|1[0-9][0-9]|[1-9][0-9]?))$"))
102102

103103
; string
104104
; ------
@@ -132,8 +132,9 @@
132132
((identifier) @constant.builtin
133133
(#any-of? @constant.builtin
134134
"SendBounceIfActionFail" "SendPayGasSeparately" "SendIgnoreErrors" "SendDestroyIfZero"
135-
"SendRemainingValue" "SendRemainingBalance" "ReserveExact" "ReserveAllExcept" "ReserveAtMost"
136-
"ReserveAddOriginalBalance" "ReserveInvertSign" "ReserveBounceIfActionFail"))
135+
"SendRemainingValue" "SendRemainingBalance" "SendOnlyEstimateFee" "ReserveExact"
136+
"ReserveAllExcept" "ReserveAtMost" "ReserveAddOriginalBalance" "ReserveInvertSign"
137+
"ReserveBounceIfActionFail"))
137138

138139
; property
139140
; --------
@@ -177,6 +178,7 @@
177178
[
178179
"fun"
179180
"native"
181+
"asm"
180182
] @keyword.function
181183

182184
; keyword.operator
@@ -244,6 +246,9 @@
244246
(native_function
245247
name: (identifier) @function)
246248

249+
(asm_function
250+
name: (identifier) @function)
251+
247252
(global_function
248253
name: (identifier) @function)
249254

@@ -276,18 +281,6 @@
276281
(method_call_expression
277282
name: (identifier) @function.method.call)
278283

279-
; function.builtin
280-
; ----------------
281-
(static_call_expression
282-
name: (identifier) @function.builtin
283-
(#any-of? @function.builtin
284-
"log" "log2" "send" "sender" "require" "now" "myBalance" "myAddress" "newAddress"
285-
"contractAddress" "contractAddressExt" "emit" "cell" "ton" "dump" "dumpStack" "beginString"
286-
"beginComment" "beginTailString" "beginStringFromBuilder" "beginCell" "emptyCell" "randomInt"
287-
"random" "checkSignature" "checkDataSignature" "sha256" "min" "max" "abs" "pow" "pow2" "throw"
288-
"nativeThrowIf" "nativeThrowUnless" "getConfigParam" "nativeRandomize" "nativeRandomizeLt"
289-
"nativePrepareRandom" "nativeRandom" "nativeRandomInterval" "nativeReserve"))
290-
291284
; attribute
292285
; ---------
293286
[

editor_queries/neovim/indents.scm

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
(trait_body)
1515
(function_body)
1616
(block_statement)
17+
(asm_function_body)
18+
(asm_list)
1719
; misc.
1820
(binary_expression)
1921
(ternary_expression)

editor_queries/neovim/locals.scm

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
; Scopes @local.scope
55
; -------------------------
66
[
7+
(asm_function)
78
(global_function)
89
(init_function)
910
(bounced_function)
@@ -30,6 +31,10 @@
3031
name: (identifier) @local.definition.constant)
3132

3233
; functions
34+
(asm_function
35+
name: (identifier) @local.definition.function
36+
(#set! definition.var.scope parent))
37+
3338
(global_function
3439
name: (identifier) @local.definition.function
3540
(#set! definition.var.scope parent))

editor_queries/neovim/textobjects.scm

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
; See: https://github.com/nvim-treesitter/nvim-treesitter-textobjects#built-in-textobjects
22
; function.inner & outer
33
; ----------------------
4+
; asm
5+
(asm_function
6+
body: (_)) @function.outer
7+
8+
(asm_function
9+
body: (asm_function_body
10+
.
11+
"{"
12+
.
13+
(_) @_start
14+
(_)? @_end
15+
.
16+
"}")
17+
(#make-range! "function.inner" @_start @_end))
18+
419
; global
520
(global_function
621
body: (_)) @function.outer
@@ -149,7 +164,8 @@
149164
; -----------------------
150165
("@name"
151166
"("
152-
func_name: (func_identifier) @attribute.inner")") @attribute.outer
167+
func_name: (func_identifier) @attribute.inner
168+
")") @attribute.outer
153169

154170
(contract_attributes
155171
("@interface"
@@ -255,6 +271,9 @@
255271
(_
256272
(block_statement) @block.inner) @block.outer
257273

274+
(_
275+
(asm_list) @block.inner) @block.outer
276+
258277
; call.inner & outer
259278
; ------------------
260279
(method_call_expression) @call.outer

0 commit comments

Comments
 (0)