Skip to content

Commit

Permalink
fix(grammar): allow !! in chains of method calls (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Apr 15, 2024
1 parent 9c741b2 commit fab39a0
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 239 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

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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
76 changes: 76 additions & 0 deletions src/grammar/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5266,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",
}
`;
14 changes: 7 additions & 7 deletions src/grammar/grammar.ohm
Original file line number Diff line number Diff line change
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
229 changes: 0 additions & 229 deletions src/grammar/grammar.ohm-bundle.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/grammar/grammar.ohm-bundle.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ semantics.addOperation<ASTNode>("resolve_expression", {
ExpressionBracket(_arg0, arg1, _arg2) {
return arg1.resolve_expression();
},
ExpressionUnarySuffix_notNull(arg0, _arg1) {
ExpressionUnboxNotNull(arg0, _arg1) {
return createNode({
kind: "op_unary",
op: "!!",
Expand Down
3 changes: 3 additions & 0 deletions src/grammar/test/case-33.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun testFunc(m: map<Int, Int>): Int {
return m.asCell()!!.hash();
}

0 comments on commit fab39a0

Please sign in to comment.