Skip to content

Commit

Permalink
Merge branch 'main' into newAddress-const-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Apr 17, 2024
2 parents 2cc6347 + fab39a0 commit 9f794a9
Show file tree
Hide file tree
Showing 21 changed files with 309 additions and 268 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules
coverage
dist
output/
output/
src/grammar/grammar.ohm-bundle.js
src/grammar/grammar.ohm-bundle.d.ts

4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Update the `dump` function to handle addresses: PR [#175](https://github.com/tact-lang/tact/pull/175)
- Support trailing commas for struct fields and function arguments: PR [#179](https://github.com/tact-lang/tact/pull/179)
- Support trailing commas in all comma-separated lists (struct instantiations, `initOf` arguments, `init()` parameters, inherited traits via `with`, function arguments and parameters): PR [#179](https://github.com/tact-lang/tact/pull/179) and PR [#246](https://github.com/tact-lang/tact/pull/246)
- The implicit empty `init` function is now present by default in the contract if not declared: PR [#167](https://github.com/tact-lang/tact/pull/167)
- `@stdlib/stoppable` now imports `@stdlib/ownable` so the programmer does not have to do it separately: PR [#193](https://github.com/tact-lang/tact/pull/193)
- Support escape sequences for strings (`\\`, `\"`, `\n`, `\r`, `\t`, `\v`, `\b`, `\f`, `\u{0}` through `\u{FFFFFF}`, `\u0000` through `\uFFFF`, `\x00` through `\xFF`): PR [#192](https://github.com/tact-lang/tact/pull/192)
Expand All @@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Incorrect "already exists" errors when using names such as `toString` or `valueOf`: PR [#208](https://github.com/tact-lang/tact/pull/208)
- Escape backticks in error messages for generated TypeScript code: PR [#192](https://github.com/tact-lang/tact/pull/192)
- Empty inherited trait lists after `with` keyword are now disallowed: PR [#246](https://github.com/tact-lang/tact/pull/246)
- Allow chaining method calls with `!!`, for instance, `map.asCell()!!.hash()` is grammatically correct now: PR [#257](ttps://github.com/tact-lang/tact/pull/257)

## [1.2.0] - 2024-02-29

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ yarn add @tact-lang/compiler

TACT doesn't have development environment dependencies and has everything built in. TACT's stdlib also distributed together with a compiler.

For Visual Studio Code syntax support, please download the [tact extension](https://marketplace.visualstudio.com/items?itemName=ton-community.tact-vscode).
For Visual Studio Code syntax support, please download the [Tact extension](https://marketplace.visualstudio.com/items?itemName=KonVik.tact-lang-vscode).

## 10 Commandments of Tact

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
maxWorkers: 1,
maxWorkers: "50%",
globalSetup: "./jest.setup.js",
globalTeardown: "./jest.teardown.js",
snapshotSerializers: ["@tact-lang/ton-jest/serializers"],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1",
"lint": "yarn eslint .",
"lint:schema": "ajv validate -s grammar/configSchema.json -d tact.config.json",
"fmt:check": "yarn prettier --check ."
"fmt:check": "yarn prettier --check .",
"all": "yarn clean && yarn gen && yarn build && yarn coverage && yarn lint && yarn fmt:check"
},
"files": [
"dist/**/*",
Expand Down
187 changes: 175 additions & 12 deletions src/grammar/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,52 @@ Line 2, col 31:
"
`;
exports[`grammar should fail case-27 1`] = `
"<unknown>:1:19: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 19:
> 1 | contract Name with, {}
^
2 |
"
`;
exports[`grammar should fail case-28 1`] = `
"<unknown>:1:16: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 16:
> 1 | trait Name with, {}
^
2 |
"
`;
exports[`grammar should fail case-29 1`] = `
"<unknown>:2:10: Empty parameter list should not have a dangling comma.
Line 2, col 10:
1 | contract Name {
> 2 | init(,) {}
^
3 | }
"
`;
exports[`grammar should fail case-30 1`] = `
"<unknown>:1:20: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 20:
> 1 | contract Name with {}
^
2 |
"
`;
exports[`grammar should fail case-31 1`] = `
"<unknown>:1:17: Syntax error: expected "_", "A".."Z", or "a".."z"
Line 1, col 17:
> 1 | trait Name with {}
^
2 |
"
`;
exports[`grammar should parse case-0 1`] = `
{
"entries": [
Expand Down Expand Up @@ -2727,8 +2773,8 @@ exports[`grammar should parse case-22 1`] = `
"id": 3,
"init": null,
"kind": "def_field",
"name": "a",
"ref": a: Int;,
"name": "c",
"ref": c: Int;,
"type": {
"id": 2,
"kind": "type_ref_simple",
Expand All @@ -2740,10 +2786,10 @@ exports[`grammar should parse case-22 1`] = `
],
"id": 4,
"kind": "def_trait",
"name": "SomeTrait",
"name": "OtherTrait",
"origin": "user",
"ref": trait SomeTrait {
a: Int;
"ref": trait OtherTrait {
c: Int;
},
"traits": [],
},
Expand All @@ -2755,8 +2801,8 @@ exports[`grammar should parse case-22 1`] = `
"id": 6,
"init": null,
"kind": "def_field",
"name": "b",
"ref": b: Int;,
"name": "a",
"ref": a: Int;,
"type": {
"id": 5,
"kind": "type_ref_simple",
Expand All @@ -2767,23 +2813,58 @@ exports[`grammar should parse case-22 1`] = `
},
],
"id": 8,
"kind": "def_trait",
"name": "SomeTrait",
"origin": "user",
"ref": trait SomeTrait with OtherTrait, {
a: Int;
},
"traits": [
{
"id": 7,
"kind": "id",
"ref": OtherTrait,
"value": "OtherTrait",
},
],
},
{
"attributes": [],
"declarations": [
{
"as": null,
"id": 10,
"init": null,
"kind": "def_field",
"name": "b",
"ref": b: Int;,
"type": {
"id": 9,
"kind": "type_ref_simple",
"name": "Int",
"optional": false,
"ref": Int,
},
},
],
"id": 12,
"kind": "def_contract",
"name": "Main",
"origin": "user",
"ref": contract Main with SomeTrait {
"ref": contract Main with SomeTrait, {
b: Int;
},
"traits": [
{
"id": 7,
"id": 11,
"kind": "id",
"ref": SomeTrait,
"value": "SomeTrait",
},
],
},
],
"id": 9,
"id": 13,
"kind": "program",
}
`;
Expand Down Expand Up @@ -3669,7 +3750,10 @@ exports[`grammar should parse case-25 1`] = `
],
"id": 76,
"kind": "def_init_function",
"ref": init(arg1: Int, arg2: Int) {},
"ref": init(
arg1: Int,
arg2: Int,
) {},
"statements": [],
},
],
Expand All @@ -3678,7 +3762,10 @@ exports[`grammar should parse case-25 1`] = `
"name": "TestContract",
"origin": "user",
"ref": contract TestContract {
init(arg1: Int, arg2: Int) {}
init(
arg1: Int,
arg2: Int,
) {}
},
"traits": [],
},
Expand Down Expand Up @@ -5179,3 +5266,79 @@ exports[`grammar should parse case-32 1`] = `
"kind": "program",
}
`;
exports[`grammar should parse case-33 1`] = `
{
"entries": [
{
"args": [
{
"id": 3,
"kind": "def_argument",
"name": "m",
"ref": m: map<Int, Int>,
"type": {
"id": 2,
"key": "Int",
"keyAs": null,
"kind": "type_ref_map",
"ref": map<Int, Int>,
"value": "Int",
"valueAs": null,
},
},
],
"attributes": [],
"id": 9,
"kind": "def_function",
"name": "testFunc",
"origin": "user",
"ref": fun testFunc(m: map<Int, Int>): Int {
return m.asCell()!!.hash();
},
"return": {
"id": 1,
"kind": "type_ref_simple",
"name": "Int",
"optional": false,
"ref": Int,
},
"statements": [
{
"expression": {
"args": [],
"id": 7,
"kind": "op_call",
"name": "hash",
"ref": m.asCell()!!.hash(),
"src": {
"id": 6,
"kind": "op_unary",
"op": "!!",
"ref": m.asCell()!!,
"right": {
"args": [],
"id": 5,
"kind": "op_call",
"name": "asCell",
"ref": m.asCell(),
"src": {
"id": 4,
"kind": "id",
"ref": m,
"value": "m",
},
},
},
},
"id": 8,
"kind": "statement_return",
"ref": return m.asCell()!!.hash();,
},
],
},
],
"id": 10,
"kind": "program",
}
`;
20 changes: 10 additions & 10 deletions src/grammar/grammar.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Tact {

// Contract
Contract = ContractAttribute* contract id "{" ContractBody* "}" --simple
| ContractAttribute* contract id with ListOf<id,","> "{" ContractBody* "}" --withTraits
ContractInit = "init" "(" ListOf<FunctionArg,","> ")" "{" Statement* "}"
| ContractAttribute* contract id with NonemptyListOf<id,","> ","? "{" ContractBody* "}" --withTraits
ContractInit = "init" "(" ListOf<FunctionArg,","> ","? ")" "{" Statement* "}"
ContractBody = Field
| ContractInit
| ReceiveFunction
Expand All @@ -55,7 +55,7 @@ Tact {

// Trait
Trait = ContractAttribute* trait id "{" TraitBody* "}" --originary
| ContractAttribute* trait id with ListOf<id,","> "{" TraitBody* "}" --withTraits
| ContractAttribute* trait id with NonemptyListOf<id,","> ","? "{" TraitBody* "}" --withTraits
TraitBody = Field
| ReceiveFunction
| Function
Expand Down Expand Up @@ -151,16 +151,15 @@ Tact {
| ExpressionMul "/" ExpressionUnary --div
| ExpressionMul "%" ExpressionUnary --rem
| ExpressionUnary
ExpressionUnary = "-" ExpressionUnarySuffix --neg
| "+" ExpressionUnarySuffix --add
| "!" ExpressionUnarySuffix --not
| ExpressionUnarySuffix
ExpressionUnarySuffix = ExpressionValue "!!" --notNull
| ExpressionValue
ExpressionUnary = "-" ExpressionValue --neg
| "+" ExpressionValue --add
| "!" ExpressionValue --not
| ExpressionValue
ExpressionBracket = "(" Expression ")"

// Order is important
ExpressionValue = ExpressionCall
ExpressionValue = ExpressionUnboxNotNull
| ExpressionCall
| ExpressionField
| ExpressionStaticCall
| ExpressionBracket
Expand All @@ -171,6 +170,7 @@ Tact {
| null
| ExpressionInitOf
| ExpressionString
ExpressionUnboxNotNull = ExpressionValue "!!"
ExpressionString = stringLiteral
ExpressionField = ExpressionValue "." id ~"("
ExpressionCall = ExpressionValue "." id "(" ListOf<Expression, ","> ","? ")"
Expand Down
Loading

0 comments on commit 9f794a9

Please sign in to comment.