tree-sitter-compact 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -11
- package/grammar.js +28 -10
- package/package.json +4 -4
- package/prebuilds/darwin-arm64/tree-sitter-compact.node +0 -0
- package/prebuilds/darwin-x64/tree-sitter-compact.node +0 -0
- package/prebuilds/linux-arm64/tree-sitter-compact.node +0 -0
- package/prebuilds/linux-x64/tree-sitter-compact.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-compact.node +0 -0
- package/queries/highlights.scm +2 -0
- package/src/grammar.json +70 -8
- package/src/node-types.json +52 -0
- package/src/parser.c +17281 -17458
- package/tree-sitter-compact.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[![CI][ci]](https://github.com/1NickPappas/compact-tree-sitter/actions/workflows/tests.yml)
|
|
4
4
|
[![crates][crates]](https://crates.io/crates/tree-sitter-compact)
|
|
5
|
+
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-compact)
|
|
6
|
+
[![pypi][pypi]](https://pypi.org/project/tree-sitter-compact/)
|
|
5
7
|
|
|
6
8
|
Compact grammar for [tree-sitter][].
|
|
7
9
|
|
|
@@ -10,17 +12,26 @@ based on the [formal grammar][grammar] published by the Midnight Foundation.
|
|
|
10
12
|
|
|
11
13
|
## Compatibility
|
|
12
14
|
|
|
13
|
-
This grammar
|
|
14
|
-
**0.31.1**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
body-less `circuit` declarations or the old `assert expr "msg";` statement.
|
|
18
|
-
See the [compatibility matrix][support-matrix] for details.
|
|
15
|
+
This grammar is a single **superset** grammar that accepts the Compact language
|
|
16
|
+
across all currently supported toolchains — from **0.31.1** (language 0.23.0,
|
|
17
|
+
runtime 0.16.0), the version on the current Midnight mainnet (ledger 8), through
|
|
18
|
+
**0.35.0** (language 0.27.0, runtime 0.20.0), which targets ledger 9.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
Support starts at **0.31.1**: the grammar does not accept legacy syntax such as
|
|
21
|
+
top-level body-less `circuit` declarations or the old `assert expr "msg";`
|
|
22
|
+
statement.
|
|
23
|
+
|
|
24
|
+
| Grammar | Compact language | Compact toolchain | Runtime | Ledger |
|
|
25
|
+
|---------|------------------|-------------------|-----------------|--------|
|
|
26
|
+
| 0.3.x | 0.23.0 – 0.27.0 | 0.31.1 – 0.35.0 | 0.16.0 – 0.20.0 | 8, 9 |
|
|
27
|
+
| 0.2.x | 0.23.0 | 0.31.1 | 0.16.0 | 8 |
|
|
28
|
+
| 0.1.x | 0.23.0 | 0.31.1 | 0.16.0 | 8 |
|
|
29
|
+
|
|
30
|
+
The grammar is version-agnostic: it does **not** evaluate `pragma
|
|
31
|
+
language_version` and accepts the union of supported syntax. Use the Compact
|
|
32
|
+
compiler to enforce the language version; the grammar is intended for parsing,
|
|
33
|
+
highlighting, and editor tooling. See [COMPATIBILITY.md](COMPATIBILITY.md) for
|
|
34
|
+
the full mapping and release/versioning policy.
|
|
24
35
|
|
|
25
36
|
The grammar follows independent [Semantic Versioning][semver]: the parse tree
|
|
26
37
|
is the public API, so adding nodes or fields is a minor release and breaking
|
|
@@ -67,7 +78,7 @@ parser.setLanguage(Compact);
|
|
|
67
78
|
```toml
|
|
68
79
|
[dependencies]
|
|
69
80
|
tree-sitter = "0.25"
|
|
70
|
-
tree-sitter-compact = "0.
|
|
81
|
+
tree-sitter-compact = "0.3"
|
|
71
82
|
```
|
|
72
83
|
|
|
73
84
|
### Python
|
|
@@ -94,3 +105,5 @@ import tree_sitter_compact
|
|
|
94
105
|
|
|
95
106
|
[ci]: https://img.shields.io/github/actions/workflow/status/1NickPappas/compact-tree-sitter/tests.yml?logo=github&label=CI
|
|
96
107
|
[crates]: https://img.shields.io/crates/v/tree-sitter-compact?logo=rust
|
|
108
|
+
[npm]: https://img.shields.io/npm/v/tree-sitter-compact?logo=npm
|
|
109
|
+
[pypi]: https://img.shields.io/pypi/v/tree-sitter-compact?logo=pypi&logoColor=ffd242
|
package/grammar.js
CHANGED
|
@@ -74,6 +74,7 @@ module.exports = grammar({
|
|
|
74
74
|
// → ecdecl
|
|
75
75
|
// → struct
|
|
76
76
|
// → enumdef
|
|
77
|
+
// → contract-implements-declaration
|
|
77
78
|
_pelt: ($) =>
|
|
78
79
|
choice(
|
|
79
80
|
$.pragma,
|
|
@@ -88,6 +89,7 @@ module.exports = grammar({
|
|
|
88
89
|
$.ecdecl,
|
|
89
90
|
$.struct,
|
|
90
91
|
$.enumdef,
|
|
92
|
+
$.contract_implements_declaration,
|
|
91
93
|
$.type_alias_declaration,
|
|
92
94
|
),
|
|
93
95
|
|
|
@@ -353,6 +355,17 @@ module.exports = grammar({
|
|
|
353
355
|
field('type', $.type),
|
|
354
356
|
),
|
|
355
357
|
|
|
358
|
+
// Contract-implements-declaration (contract-implements-declaration)
|
|
359
|
+
//
|
|
360
|
+
// contract-implements-declaration → contract implements type ;
|
|
361
|
+
contract_implements_declaration: ($) =>
|
|
362
|
+
seq(
|
|
363
|
+
'contract',
|
|
364
|
+
'implements',
|
|
365
|
+
field('type', $.type),
|
|
366
|
+
';',
|
|
367
|
+
),
|
|
368
|
+
|
|
356
369
|
// Structure-definition (struct)
|
|
357
370
|
//
|
|
358
371
|
// struct → export^opt struct struct-name gparams^opt { arg ; … ; arg ;^opt } ;^opt
|
|
@@ -682,6 +695,7 @@ module.exports = grammar({
|
|
|
682
695
|
$.slice_term, // Slice with size and range expressions
|
|
683
696
|
$.disclose_term, // Disclose with single expression
|
|
684
697
|
$.assert_term, // Assert with condition and message
|
|
698
|
+
$.emit_term, // Emit with a single expression
|
|
685
699
|
$.bytes_literal, // Bytes literal with optional spread
|
|
686
700
|
$.struct_term, // Struct literal with type reference
|
|
687
701
|
$.array_literal, // Array literal with optional spread
|
|
@@ -697,6 +711,7 @@ module.exports = grammar({
|
|
|
697
711
|
slice_term: ($) => seq('slice', '<', field('tsize', $.tsize), '>', '(', field('expr', $.expr), ',', field('expr', $.expr), ')'),
|
|
698
712
|
disclose_term: ($) => seq('disclose', '(', field('expr', $.expr), ')'),
|
|
699
713
|
assert_term: ($) => prec(2, seq('assert', '(', field('condition', $.expr), ',', field('message', $.str), ')')),
|
|
714
|
+
emit_term: ($) => prec(2, seq('emit', '(', field('value', $.expr), ')')),
|
|
700
715
|
array_literal: ($) => seq('[', commaSep(field('element', $.tuple_arg)), ']'),
|
|
701
716
|
bytes_literal: ($) => seq('Bytes', '[', commaSep(field('element', $.tuple_arg)), ']'),
|
|
702
717
|
tuple_arg: ($) => choice($.spread_element, field('expr', $.expr)),
|
|
@@ -781,16 +796,19 @@ module.exports = grammar({
|
|
|
781
796
|
|
|
782
797
|
// identifier (id, module-name, function-name, struct-name, enum-name, contract-name, tvar-name)
|
|
783
798
|
//
|
|
784
|
-
//
|
|
785
|
-
//
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
799
|
+
// Matches the compiler's identifier rule, which follows
|
|
800
|
+
// https://tc39.es/ecma262/#sec-names-and-keywords and
|
|
801
|
+
// https://www.unicode.org/reports/tr31/#Table_Lexical_Classes_for_Identifiers:
|
|
802
|
+
// an initial character in Lu, Ll, Lt, Lm, Lo, or Nl (or `_`/`$`), followed by
|
|
803
|
+
// those plus Mn, Mc, Nd, and Pc.
|
|
804
|
+
id: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
805
|
+
module_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
806
|
+
function_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
807
|
+
struct_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
808
|
+
enum_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
809
|
+
contract_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
810
|
+
tvar_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
811
|
+
type_name: ($) => /[\p{L}\p{Nl}_$][\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}$]*/,
|
|
794
812
|
|
|
795
813
|
// field-literal (nat)
|
|
796
814
|
//
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tree-sitter-compact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A zero-knowledge smart contract programming language",
|
|
5
5
|
"repository": "https://github.com/1NickPappas/compact-tree-sitter",
|
|
6
6
|
"homepage": "https://github.com/1NickPappas/compact-tree-sitter#readme",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
}
|
|
18
18
|
],
|
|
19
19
|
"compact": {
|
|
20
|
-
"language": "0.23.0",
|
|
21
|
-
"toolchain": "0.31.1",
|
|
22
|
-
"runtime": "0.16.0"
|
|
20
|
+
"language": ">=0.23.0 <=0.27.0",
|
|
21
|
+
"toolchain": ">=0.31.1 <=0.35.0",
|
|
22
|
+
"runtime": ">=0.16.0 <=0.20.0"
|
|
23
23
|
},
|
|
24
24
|
"main": "bindings/node",
|
|
25
25
|
"types": "bindings/node",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/queries/highlights.scm
CHANGED
package/src/grammar.json
CHANGED
|
@@ -88,6 +88,10 @@
|
|
|
88
88
|
"type": "SYMBOL",
|
|
89
89
|
"name": "enumdef"
|
|
90
90
|
},
|
|
91
|
+
{
|
|
92
|
+
"type": "SYMBOL",
|
|
93
|
+
"name": "contract_implements_declaration"
|
|
94
|
+
},
|
|
91
95
|
{
|
|
92
96
|
"type": "SYMBOL",
|
|
93
97
|
"name": "type_alias_declaration"
|
|
@@ -1522,6 +1526,31 @@
|
|
|
1522
1526
|
}
|
|
1523
1527
|
]
|
|
1524
1528
|
},
|
|
1529
|
+
"contract_implements_declaration": {
|
|
1530
|
+
"type": "SEQ",
|
|
1531
|
+
"members": [
|
|
1532
|
+
{
|
|
1533
|
+
"type": "STRING",
|
|
1534
|
+
"value": "contract"
|
|
1535
|
+
},
|
|
1536
|
+
{
|
|
1537
|
+
"type": "STRING",
|
|
1538
|
+
"value": "implements"
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
"type": "FIELD",
|
|
1542
|
+
"name": "type",
|
|
1543
|
+
"content": {
|
|
1544
|
+
"type": "SYMBOL",
|
|
1545
|
+
"name": "type"
|
|
1546
|
+
}
|
|
1547
|
+
},
|
|
1548
|
+
{
|
|
1549
|
+
"type": "STRING",
|
|
1550
|
+
"value": ";"
|
|
1551
|
+
}
|
|
1552
|
+
]
|
|
1553
|
+
},
|
|
1525
1554
|
"struct": {
|
|
1526
1555
|
"type": "SEQ",
|
|
1527
1556
|
"members": [
|
|
@@ -3434,6 +3463,10 @@
|
|
|
3434
3463
|
"type": "SYMBOL",
|
|
3435
3464
|
"name": "assert_term"
|
|
3436
3465
|
},
|
|
3466
|
+
{
|
|
3467
|
+
"type": "SYMBOL",
|
|
3468
|
+
"name": "emit_term"
|
|
3469
|
+
},
|
|
3437
3470
|
{
|
|
3438
3471
|
"type": "SYMBOL",
|
|
3439
3472
|
"name": "bytes_literal"
|
|
@@ -3900,6 +3933,35 @@
|
|
|
3900
3933
|
]
|
|
3901
3934
|
}
|
|
3902
3935
|
},
|
|
3936
|
+
"emit_term": {
|
|
3937
|
+
"type": "PREC",
|
|
3938
|
+
"value": 2,
|
|
3939
|
+
"content": {
|
|
3940
|
+
"type": "SEQ",
|
|
3941
|
+
"members": [
|
|
3942
|
+
{
|
|
3943
|
+
"type": "STRING",
|
|
3944
|
+
"value": "emit"
|
|
3945
|
+
},
|
|
3946
|
+
{
|
|
3947
|
+
"type": "STRING",
|
|
3948
|
+
"value": "("
|
|
3949
|
+
},
|
|
3950
|
+
{
|
|
3951
|
+
"type": "FIELD",
|
|
3952
|
+
"name": "value",
|
|
3953
|
+
"content": {
|
|
3954
|
+
"type": "SYMBOL",
|
|
3955
|
+
"name": "expr"
|
|
3956
|
+
}
|
|
3957
|
+
},
|
|
3958
|
+
{
|
|
3959
|
+
"type": "STRING",
|
|
3960
|
+
"value": ")"
|
|
3961
|
+
}
|
|
3962
|
+
]
|
|
3963
|
+
}
|
|
3964
|
+
},
|
|
3903
3965
|
"array_literal": {
|
|
3904
3966
|
"type": "SEQ",
|
|
3905
3967
|
"members": [
|
|
@@ -4413,35 +4475,35 @@
|
|
|
4413
4475
|
},
|
|
4414
4476
|
"id": {
|
|
4415
4477
|
"type": "PATTERN",
|
|
4416
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4478
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4417
4479
|
},
|
|
4418
4480
|
"module_name": {
|
|
4419
4481
|
"type": "PATTERN",
|
|
4420
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4482
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4421
4483
|
},
|
|
4422
4484
|
"function_name": {
|
|
4423
4485
|
"type": "PATTERN",
|
|
4424
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4486
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4425
4487
|
},
|
|
4426
4488
|
"struct_name": {
|
|
4427
4489
|
"type": "PATTERN",
|
|
4428
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4490
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4429
4491
|
},
|
|
4430
4492
|
"enum_name": {
|
|
4431
4493
|
"type": "PATTERN",
|
|
4432
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4494
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4433
4495
|
},
|
|
4434
4496
|
"contract_name": {
|
|
4435
4497
|
"type": "PATTERN",
|
|
4436
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4498
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4437
4499
|
},
|
|
4438
4500
|
"tvar_name": {
|
|
4439
4501
|
"type": "PATTERN",
|
|
4440
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4502
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4441
4503
|
},
|
|
4442
4504
|
"type_name": {
|
|
4443
4505
|
"type": "PATTERN",
|
|
4444
|
-
"value": "[\\p{L}_$][\\p{L}\\p{
|
|
4506
|
+
"value": "[\\p{L}\\p{Nl}_$][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$]*"
|
|
4445
4507
|
},
|
|
4446
4508
|
"nat": {
|
|
4447
4509
|
"type": "CHOICE",
|
package/src/node-types.json
CHANGED
|
@@ -803,6 +803,22 @@
|
|
|
803
803
|
}
|
|
804
804
|
}
|
|
805
805
|
},
|
|
806
|
+
{
|
|
807
|
+
"type": "contract_implements_declaration",
|
|
808
|
+
"named": true,
|
|
809
|
+
"fields": {
|
|
810
|
+
"type": {
|
|
811
|
+
"multiple": false,
|
|
812
|
+
"required": true,
|
|
813
|
+
"types": [
|
|
814
|
+
{
|
|
815
|
+
"type": "type",
|
|
816
|
+
"named": true
|
|
817
|
+
}
|
|
818
|
+
]
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
},
|
|
806
822
|
{
|
|
807
823
|
"type": "contract_name",
|
|
808
824
|
"named": true,
|
|
@@ -922,6 +938,22 @@
|
|
|
922
938
|
}
|
|
923
939
|
}
|
|
924
940
|
},
|
|
941
|
+
{
|
|
942
|
+
"type": "emit_term",
|
|
943
|
+
"named": true,
|
|
944
|
+
"fields": {
|
|
945
|
+
"value": {
|
|
946
|
+
"multiple": false,
|
|
947
|
+
"required": true,
|
|
948
|
+
"types": [
|
|
949
|
+
{
|
|
950
|
+
"type": "expr",
|
|
951
|
+
"named": true
|
|
952
|
+
}
|
|
953
|
+
]
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
},
|
|
925
957
|
{
|
|
926
958
|
"type": "enum_name",
|
|
927
959
|
"named": true,
|
|
@@ -1722,6 +1754,10 @@
|
|
|
1722
1754
|
"type": "cdefn",
|
|
1723
1755
|
"named": true
|
|
1724
1756
|
},
|
|
1757
|
+
{
|
|
1758
|
+
"type": "contract_implements_declaration",
|
|
1759
|
+
"named": true
|
|
1760
|
+
},
|
|
1725
1761
|
{
|
|
1726
1762
|
"type": "ecdecl",
|
|
1727
1763
|
"named": true
|
|
@@ -2441,6 +2477,10 @@
|
|
|
2441
2477
|
"type": "cdefn",
|
|
2442
2478
|
"named": true
|
|
2443
2479
|
},
|
|
2480
|
+
{
|
|
2481
|
+
"type": "contract_implements_declaration",
|
|
2482
|
+
"named": true
|
|
2483
|
+
},
|
|
2444
2484
|
{
|
|
2445
2485
|
"type": "ecdecl",
|
|
2446
2486
|
"named": true
|
|
@@ -2702,6 +2742,10 @@
|
|
|
2702
2742
|
"type": "disclose_term",
|
|
2703
2743
|
"named": true
|
|
2704
2744
|
},
|
|
2745
|
+
{
|
|
2746
|
+
"type": "emit_term",
|
|
2747
|
+
"named": true
|
|
2748
|
+
},
|
|
2705
2749
|
{
|
|
2706
2750
|
"type": "expr_seq_term",
|
|
2707
2751
|
"named": true
|
|
@@ -3179,6 +3223,10 @@
|
|
|
3179
3223
|
"type": "else",
|
|
3180
3224
|
"named": false
|
|
3181
3225
|
},
|
|
3226
|
+
{
|
|
3227
|
+
"type": "emit",
|
|
3228
|
+
"named": false
|
|
3229
|
+
},
|
|
3182
3230
|
{
|
|
3183
3231
|
"type": "enum",
|
|
3184
3232
|
"named": false
|
|
@@ -3215,6 +3263,10 @@
|
|
|
3215
3263
|
"type": "if",
|
|
3216
3264
|
"named": false
|
|
3217
3265
|
},
|
|
3266
|
+
{
|
|
3267
|
+
"type": "implements",
|
|
3268
|
+
"named": false
|
|
3269
|
+
},
|
|
3218
3270
|
{
|
|
3219
3271
|
"type": "import",
|
|
3220
3272
|
"named": false
|