diff --git a/src/grammar/next/__snapshots__/grammar.spec.ts.snap b/src/grammar/next/__snapshots__/grammar.spec.ts.snap index 3db8059b8..63f4dc301 100644 --- a/src/grammar/next/__snapshots__/grammar.spec.ts.snap +++ b/src/grammar/next/__snapshots__/grammar.spec.ts.snap @@ -2364,6 +2364,498 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` } `; +exports[`grammar should parse expr-binary-chained-operators-1 1`] = ` +{ + "id": 25, + "imports": [], + "items": [ + { + "attributes": [], + "declarations": [ + { + "as": { + "id": 11, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 12, + "initializer": { + "id": 10, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "op_binary", + "left": { + "base": 10, + "id": 4, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 6, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 5, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 + +789, + "op": "+", + "right": { + "id": 9, + "kind": "op_unary", + "loc": +789, + "op": "+", + "operand": { + "base": 10, + "id": 8, + "kind": "number", + "loc": 789, + "value": 789n, + }, + }, + }, + "kind": "field_decl", + "loc": a: Int as coins = 123 + -456 + +789, + "name": { + "id": 2, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 22, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 23, + "initializer": { + "id": 21, + "kind": "op_binary", + "left": { + "id": 18, + "kind": "op_binary", + "left": { + "base": 10, + "id": 15, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 17, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 16, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 +- 789, + "op": "+", + "right": { + "id": 20, + "kind": "op_unary", + "loc": - 789, + "op": "-", + "operand": { + "base": 10, + "id": 19, + "kind": "number", + "loc": 789, + "value": 789n, + }, + }, + }, + "kind": "field_decl", + "loc": b: Int as coins = 123 + -456 +- 789, + "name": { + "id": 13, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 24, + "kind": "contract", + "loc": contract Foo { + a: Int as coins = 123 + -456 + +789; + b: Int as coins = 123 + -456 +- 789; +}, + "name": { + "id": 1, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + ], + "kind": "module", +} +`; + +exports[`grammar should parse expr-binary-chained-operators-2 1`] = ` +{ + "id": 31, + "imports": [], + "items": [ + { + "attributes": [], + "declarations": [ + { + "as": { + "id": 14, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 15, + "initializer": { + "id": 13, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "op_binary", + "left": { + "base": 10, + "id": 4, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 6, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 5, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 + +(987 * -654), + "op": "+", + "right": { + "id": 12, + "kind": "op_unary", + "loc": +(987 * -654), + "op": "+", + "operand": { + "id": 11, + "kind": "op_binary", + "left": { + "base": 10, + "id": 8, + "kind": "number", + "loc": 987, + "value": 987n, + }, + "loc": 987 * -654, + "op": "*", + "right": { + "id": 10, + "kind": "op_unary", + "loc": -654, + "op": "-", + "operand": { + "base": 10, + "id": 9, + "kind": "number", + "loc": 654, + "value": 654n, + }, + }, + }, + }, + }, + "kind": "field_decl", + "loc": a: Int as coins = 123 + -456 + +(987 * -654), + "name": { + "id": 2, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 28, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 29, + "initializer": { + "id": 27, + "kind": "op_binary", + "left": { + "id": 21, + "kind": "op_binary", + "left": { + "base": 10, + "id": 18, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 20, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 19, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 - -(987 / +654), + "op": "-", + "right": { + "id": 26, + "kind": "op_unary", + "loc": -(987 / +654), + "op": "-", + "operand": { + "id": 25, + "kind": "op_binary", + "left": { + "base": 10, + "id": 22, + "kind": "number", + "loc": 987, + "value": 987n, + }, + "loc": 987 / +654, + "op": "/", + "right": { + "id": 24, + "kind": "op_unary", + "loc": +654, + "op": "+", + "operand": { + "base": 10, + "id": 23, + "kind": "number", + "loc": 654, + "value": 654n, + }, + }, + }, + }, + }, + "kind": "field_decl", + "loc": b: Int as coins = 123 + -456 - -(987 / +654), + "name": { + "id": 16, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 17, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 30, + "kind": "contract", + "loc": contract Foo { + a: Int as coins = 123 + -456 + +(987 * -654); + b: Int as coins = 123 + -456 - -(987 / +654); +}, + "name": { + "id": 1, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + ], + "kind": "module", +} +`; + +exports[`grammar should parse expr-binary-operators 1`] = ` +{ + "id": 19, + "imports": [], + "items": [ + { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 9, + "initializer": { + "id": 7, + "kind": "op_binary", + "left": { + "base": 10, + "id": 4, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 - -456, + "op": "-", + "right": { + "id": 6, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 5, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "kind": "field_decl", + "loc": a: Int as coins = 123 - -456, + "name": { + "id": 2, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 16, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 17, + "initializer": { + "id": 15, + "kind": "op_binary", + "left": { + "base": 10, + "id": 12, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 14, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 13, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "kind": "field_decl", + "loc": b: Int as coins = 123 + -456, + "name": { + "id": 10, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 11, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 18, + "kind": "contract", + "loc": contract Foo { + a: Int as coins = 123 - -456; + b: Int as coins = 123 + -456; +}, + "name": { + "id": 1, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + ], + "kind": "module", +} +`; + exports[`grammar should parse expr-chaining-unbox 1`] = ` { "id": 18, diff --git a/src/grammar/prev/__snapshots__/grammar.spec.ts.snap b/src/grammar/prev/__snapshots__/grammar.spec.ts.snap index f94e2c7c0..9a42fbd4a 100644 --- a/src/grammar/prev/__snapshots__/grammar.spec.ts.snap +++ b/src/grammar/prev/__snapshots__/grammar.spec.ts.snap @@ -2416,6 +2416,498 @@ exports[`grammar should parse expr-arith-bool-var 1`] = ` } `; +exports[`grammar should parse expr-binary-chained-operators-1 1`] = ` +{ + "id": 25, + "imports": [], + "items": [ + { + "attributes": [], + "declarations": [ + { + "as": { + "id": 11, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 12, + "initializer": { + "id": 10, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "op_binary", + "left": { + "base": 10, + "id": 4, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 6, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 5, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 + +789, + "op": "+", + "right": { + "id": 9, + "kind": "op_unary", + "loc": +789, + "op": "+", + "operand": { + "base": 10, + "id": 8, + "kind": "number", + "loc": 789, + "value": 789n, + }, + }, + }, + "kind": "field_decl", + "loc": a: Int as coins = 123 + -456 + +789, + "name": { + "id": 2, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 22, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 23, + "initializer": { + "id": 21, + "kind": "op_binary", + "left": { + "id": 18, + "kind": "op_binary", + "left": { + "base": 10, + "id": 15, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 17, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 16, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 +- 789, + "op": "+", + "right": { + "id": 20, + "kind": "op_unary", + "loc": - 789, + "op": "-", + "operand": { + "base": 10, + "id": 19, + "kind": "number", + "loc": 789, + "value": 789n, + }, + }, + }, + "kind": "field_decl", + "loc": b: Int as coins = 123 + -456 +- 789, + "name": { + "id": 13, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 14, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 24, + "kind": "contract", + "loc": contract Foo { + a: Int as coins = 123 + -456 + +789; + b: Int as coins = 123 + -456 +- 789; +}, + "name": { + "id": 1, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + ], + "kind": "module", +} +`; + +exports[`grammar should parse expr-binary-chained-operators-2 1`] = ` +{ + "id": 31, + "imports": [], + "items": [ + { + "attributes": [], + "declarations": [ + { + "as": { + "id": 14, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 15, + "initializer": { + "id": 13, + "kind": "op_binary", + "left": { + "id": 7, + "kind": "op_binary", + "left": { + "base": 10, + "id": 4, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 6, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 5, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 + +(987 * -654), + "op": "+", + "right": { + "id": 12, + "kind": "op_unary", + "loc": +(987 * -654), + "op": "+", + "operand": { + "id": 11, + "kind": "op_binary", + "left": { + "base": 10, + "id": 8, + "kind": "number", + "loc": 987, + "value": 987n, + }, + "loc": 987 * -654, + "op": "*", + "right": { + "id": 10, + "kind": "op_unary", + "loc": -654, + "op": "-", + "operand": { + "base": 10, + "id": 9, + "kind": "number", + "loc": 654, + "value": 654n, + }, + }, + }, + }, + }, + "kind": "field_decl", + "loc": a: Int as coins = 123 + -456 + +(987 * -654), + "name": { + "id": 2, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 28, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 29, + "initializer": { + "id": 27, + "kind": "op_binary", + "left": { + "id": 21, + "kind": "op_binary", + "left": { + "base": 10, + "id": 18, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 20, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 19, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "loc": 123 + -456 - -(987 / +654), + "op": "-", + "right": { + "id": 26, + "kind": "op_unary", + "loc": -(987 / +654), + "op": "-", + "operand": { + "id": 25, + "kind": "op_binary", + "left": { + "base": 10, + "id": 22, + "kind": "number", + "loc": 987, + "value": 987n, + }, + "loc": 987 / +654, + "op": "/", + "right": { + "id": 24, + "kind": "op_unary", + "loc": +654, + "op": "+", + "operand": { + "base": 10, + "id": 23, + "kind": "number", + "loc": 654, + "value": 654n, + }, + }, + }, + }, + }, + "kind": "field_decl", + "loc": b: Int as coins = 123 + -456 - -(987 / +654), + "name": { + "id": 16, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 17, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 30, + "kind": "contract", + "loc": contract Foo { + a: Int as coins = 123 + -456 + +(987 * -654); + b: Int as coins = 123 + -456 - -(987 / +654); +}, + "name": { + "id": 1, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + ], + "kind": "module", +} +`; + +exports[`grammar should parse expr-binary-operators 1`] = ` +{ + "id": 19, + "imports": [], + "items": [ + { + "attributes": [], + "declarations": [ + { + "as": { + "id": 8, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 9, + "initializer": { + "id": 7, + "kind": "op_binary", + "left": { + "base": 10, + "id": 4, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 - -456, + "op": "-", + "right": { + "id": 6, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 5, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "kind": "field_decl", + "loc": a: Int as coins = 123 - -456, + "name": { + "id": 2, + "kind": "id", + "loc": a, + "text": "a", + }, + "type": { + "id": 3, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + { + "as": { + "id": 16, + "kind": "id", + "loc": coins, + "text": "coins", + }, + "id": 17, + "initializer": { + "id": 15, + "kind": "op_binary", + "left": { + "base": 10, + "id": 12, + "kind": "number", + "loc": 123, + "value": 123n, + }, + "loc": 123 + -456, + "op": "+", + "right": { + "id": 14, + "kind": "op_unary", + "loc": -456, + "op": "-", + "operand": { + "base": 10, + "id": 13, + "kind": "number", + "loc": 456, + "value": 456n, + }, + }, + }, + "kind": "field_decl", + "loc": b: Int as coins = 123 + -456, + "name": { + "id": 10, + "kind": "id", + "loc": b, + "text": "b", + }, + "type": { + "id": 11, + "kind": "type_id", + "loc": Int, + "text": "Int", + }, + }, + ], + "id": 18, + "kind": "contract", + "loc": contract Foo { + a: Int as coins = 123 - -456; + b: Int as coins = 123 + -456; +}, + "name": { + "id": 1, + "kind": "id", + "loc": Foo, + "text": "Foo", + }, + "traits": [], + }, + ], + "kind": "module", +} +`; + exports[`grammar should parse expr-chaining-unbox 1`] = ` { "id": 16, diff --git a/src/grammar/test/expr-binary-chained-operators-1.tact b/src/grammar/test/expr-binary-chained-operators-1.tact new file mode 100644 index 000000000..ebb91f6bd --- /dev/null +++ b/src/grammar/test/expr-binary-chained-operators-1.tact @@ -0,0 +1,4 @@ +contract Foo { + a: Int as coins = 123 + -456 + +789; + b: Int as coins = 123 + -456 +- 789; +} \ No newline at end of file diff --git a/src/grammar/test/expr-binary-chained-operators-2.tact b/src/grammar/test/expr-binary-chained-operators-2.tact new file mode 100644 index 000000000..b92298314 --- /dev/null +++ b/src/grammar/test/expr-binary-chained-operators-2.tact @@ -0,0 +1,4 @@ +contract Foo { + a: Int as coins = 123 + -456 + +(987 * -654); + b: Int as coins = 123 + -456 - -(987 / +654); +} \ No newline at end of file diff --git a/src/grammar/test/expr-binary-operators.tact b/src/grammar/test/expr-binary-operators.tact new file mode 100644 index 000000000..608f8acb1 --- /dev/null +++ b/src/grammar/test/expr-binary-operators.tact @@ -0,0 +1,4 @@ +contract Foo { + a: Int as coins = 123 - -456; + b: Int as coins = 123 + -456; +} \ No newline at end of file