diff --git a/crates/aiken-lang/src/parser.rs b/crates/aiken-lang/src/parser.rs index f73b950c..7914487d 100644 --- a/crates/aiken-lang/src/parser.rs +++ b/crates/aiken-lang/src/parser.rs @@ -58,4 +58,30 @@ mod tests { // more comments"# ); } + + #[test] + fn function_ambiguous_sequence() { + assert_module!( + r#" + fn foo_1() { + let a = bar + (40) + } + + fn foo_2() { + let a = bar + {40} + } + + fn foo_3() { + let a = (40+2) + } + + fn foo_4() { + let a = bar(42) + (a + 14) * 42 + } + "# + ); + } } diff --git a/crates/aiken-lang/src/parser/expr/anonymous_binop.rs b/crates/aiken-lang/src/parser/expr/anonymous_binop.rs index 7eaa8ae4..e55da029 100644 --- a/crates/aiken-lang/src/parser/expr/anonymous_binop.rs +++ b/crates/aiken-lang/src/parser/expr/anonymous_binop.rs @@ -87,3 +87,28 @@ pub fn parser() -> impl Parser { } }) } + +#[cfg(test)] +mod tests { + use crate::assert_expr; + + #[test] + fn first_class_binop() { + assert_expr!( + r#" + compare_with(a, >, b) + compare_with(a, >=, b) + compare_with(a, <, b) + compare_with(a, <=, b) + compare_with(a, ==, b) + compare_with(a, !=, b) + combine_with(a, &&, b) + combine_with(a, ||, b) + compute_with(a, +, b) + compute_with(a, -, b) + compute_with(a, /, b) + compute_with(a, *, b) + compute_with(a, %, b)"# + ); + } +} diff --git a/crates/aiken-lang/src/parser/expr/snapshots/first_class_binop.snap b/crates/aiken-lang/src/parser/expr/snapshots/first_class_binop.snap new file mode 100644 index 00000000..45a675bd --- /dev/null +++ b/crates/aiken-lang/src/parser/expr/snapshots/first_class_binop.snap @@ -0,0 +1,1190 @@ +--- +source: crates/aiken-lang/src/parser/expr/anonymous_binop.rs +description: "Code:\n\ncompare_with(a, >, b)\ncompare_with(a, >=, b)\ncompare_with(a, <, b)\ncompare_with(a, <=, b)\ncompare_with(a, ==, b)\ncompare_with(a, !=, b)\ncombine_with(a, &&, b)\ncombine_with(a, ||, b)\ncompute_with(a, +, b)\ncompute_with(a, -, b)\ncompute_with(a, /, b)\ncompute_with(a, *, b)\ncompute_with(a, %, b)" +--- +Sequence { + location: 0..291, + expressions: [ + Call { + arguments: [ + CallArg { + label: None, + location: 13..14, + value: Var { + location: 13..14, + name: "a", + }, + }, + CallArg { + label: None, + location: 16..17, + value: Fn { + location: 16..17, + fn_style: BinOp( + GtInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 16..17, + is_validator_param: false, + }, + location: 16..17, + annotation: Some( + Constructor { + location: 16..17, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 16..17, + is_validator_param: false, + }, + location: 16..17, + annotation: Some( + Constructor { + location: 16..17, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 16..17, + name: GtInt, + left: Var { + location: 16..17, + name: "left", + }, + right: Var { + location: 16..17, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 16..17, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 19..20, + value: Var { + location: 19..20, + name: "b", + }, + }, + ], + fun: Var { + location: 0..12, + name: "compare_with", + }, + location: 0..21, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 35..36, + value: Var { + location: 35..36, + name: "a", + }, + }, + CallArg { + label: None, + location: 38..40, + value: Fn { + location: 38..40, + fn_style: BinOp( + GtEqInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 38..40, + is_validator_param: false, + }, + location: 38..40, + annotation: Some( + Constructor { + location: 38..40, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 38..40, + is_validator_param: false, + }, + location: 38..40, + annotation: Some( + Constructor { + location: 38..40, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 38..40, + name: GtEqInt, + left: Var { + location: 38..40, + name: "left", + }, + right: Var { + location: 38..40, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 38..40, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 42..43, + value: Var { + location: 42..43, + name: "b", + }, + }, + ], + fun: Var { + location: 22..34, + name: "compare_with", + }, + location: 22..44, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 58..59, + value: Var { + location: 58..59, + name: "a", + }, + }, + CallArg { + label: None, + location: 61..62, + value: Fn { + location: 61..62, + fn_style: BinOp( + LtInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 61..62, + is_validator_param: false, + }, + location: 61..62, + annotation: Some( + Constructor { + location: 61..62, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 61..62, + is_validator_param: false, + }, + location: 61..62, + annotation: Some( + Constructor { + location: 61..62, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 61..62, + name: LtInt, + left: Var { + location: 61..62, + name: "left", + }, + right: Var { + location: 61..62, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 61..62, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 64..65, + value: Var { + location: 64..65, + name: "b", + }, + }, + ], + fun: Var { + location: 45..57, + name: "compare_with", + }, + location: 45..66, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 80..81, + value: Var { + location: 80..81, + name: "a", + }, + }, + CallArg { + label: None, + location: 83..85, + value: Fn { + location: 83..85, + fn_style: BinOp( + LtEqInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 83..85, + is_validator_param: false, + }, + location: 83..85, + annotation: Some( + Constructor { + location: 83..85, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 83..85, + is_validator_param: false, + }, + location: 83..85, + annotation: Some( + Constructor { + location: 83..85, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 83..85, + name: LtEqInt, + left: Var { + location: 83..85, + name: "left", + }, + right: Var { + location: 83..85, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 83..85, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 87..88, + value: Var { + location: 87..88, + name: "b", + }, + }, + ], + fun: Var { + location: 67..79, + name: "compare_with", + }, + location: 67..89, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 103..104, + value: Var { + location: 103..104, + name: "a", + }, + }, + CallArg { + label: None, + location: 106..108, + value: Fn { + location: 106..108, + fn_style: BinOp( + Eq, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 106..108, + is_validator_param: false, + }, + location: 106..108, + annotation: None, + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 106..108, + is_validator_param: false, + }, + location: 106..108, + annotation: None, + tipo: (), + }, + ], + body: BinOp { + location: 106..108, + name: Eq, + left: Var { + location: 106..108, + name: "left", + }, + right: Var { + location: 106..108, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 106..108, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 110..111, + value: Var { + location: 110..111, + name: "b", + }, + }, + ], + fun: Var { + location: 90..102, + name: "compare_with", + }, + location: 90..112, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 126..127, + value: Var { + location: 126..127, + name: "a", + }, + }, + CallArg { + label: None, + location: 129..131, + value: Fn { + location: 129..131, + fn_style: BinOp( + NotEq, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 129..131, + is_validator_param: false, + }, + location: 129..131, + annotation: None, + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 129..131, + is_validator_param: false, + }, + location: 129..131, + annotation: None, + tipo: (), + }, + ], + body: BinOp { + location: 129..131, + name: NotEq, + left: Var { + location: 129..131, + name: "left", + }, + right: Var { + location: 129..131, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 129..131, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 133..134, + value: Var { + location: 133..134, + name: "b", + }, + }, + ], + fun: Var { + location: 113..125, + name: "compare_with", + }, + location: 113..135, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 149..150, + value: Var { + location: 149..150, + name: "a", + }, + }, + CallArg { + label: None, + location: 152..154, + value: Fn { + location: 152..154, + fn_style: BinOp( + And, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 152..154, + is_validator_param: false, + }, + location: 152..154, + annotation: Some( + Constructor { + location: 152..154, + module: None, + name: "Bool", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 152..154, + is_validator_param: false, + }, + location: 152..154, + annotation: Some( + Constructor { + location: 152..154, + module: None, + name: "Bool", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 152..154, + name: And, + left: Var { + location: 152..154, + name: "left", + }, + right: Var { + location: 152..154, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 152..154, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 156..157, + value: Var { + location: 156..157, + name: "b", + }, + }, + ], + fun: Var { + location: 136..148, + name: "combine_with", + }, + location: 136..158, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 172..173, + value: Var { + location: 172..173, + name: "a", + }, + }, + CallArg { + label: None, + location: 175..177, + value: Fn { + location: 175..177, + fn_style: BinOp( + Or, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 175..177, + is_validator_param: false, + }, + location: 175..177, + annotation: Some( + Constructor { + location: 175..177, + module: None, + name: "Bool", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 175..177, + is_validator_param: false, + }, + location: 175..177, + annotation: Some( + Constructor { + location: 175..177, + module: None, + name: "Bool", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 175..177, + name: Or, + left: Var { + location: 175..177, + name: "left", + }, + right: Var { + location: 175..177, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 175..177, + module: None, + name: "Bool", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 179..180, + value: Var { + location: 179..180, + name: "b", + }, + }, + ], + fun: Var { + location: 159..171, + name: "combine_with", + }, + location: 159..181, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 195..196, + value: Var { + location: 195..196, + name: "a", + }, + }, + CallArg { + label: None, + location: 198..199, + value: Fn { + location: 198..199, + fn_style: BinOp( + AddInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 198..199, + is_validator_param: false, + }, + location: 198..199, + annotation: Some( + Constructor { + location: 198..199, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 198..199, + is_validator_param: false, + }, + location: 198..199, + annotation: Some( + Constructor { + location: 198..199, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 198..199, + name: AddInt, + left: Var { + location: 198..199, + name: "left", + }, + right: Var { + location: 198..199, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 198..199, + module: None, + name: "Int", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 201..202, + value: Var { + location: 201..202, + name: "b", + }, + }, + ], + fun: Var { + location: 182..194, + name: "compute_with", + }, + location: 182..203, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 217..218, + value: Var { + location: 217..218, + name: "a", + }, + }, + CallArg { + label: None, + location: 220..221, + value: Fn { + location: 220..221, + fn_style: BinOp( + SubInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 220..221, + is_validator_param: false, + }, + location: 220..221, + annotation: Some( + Constructor { + location: 220..221, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 220..221, + is_validator_param: false, + }, + location: 220..221, + annotation: Some( + Constructor { + location: 220..221, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 220..221, + name: SubInt, + left: Var { + location: 220..221, + name: "left", + }, + right: Var { + location: 220..221, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 220..221, + module: None, + name: "Int", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 223..224, + value: Var { + location: 223..224, + name: "b", + }, + }, + ], + fun: Var { + location: 204..216, + name: "compute_with", + }, + location: 204..225, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 239..240, + value: Var { + location: 239..240, + name: "a", + }, + }, + CallArg { + label: None, + location: 242..243, + value: Fn { + location: 242..243, + fn_style: BinOp( + DivInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 242..243, + is_validator_param: false, + }, + location: 242..243, + annotation: Some( + Constructor { + location: 242..243, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 242..243, + is_validator_param: false, + }, + location: 242..243, + annotation: Some( + Constructor { + location: 242..243, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 242..243, + name: DivInt, + left: Var { + location: 242..243, + name: "left", + }, + right: Var { + location: 242..243, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 242..243, + module: None, + name: "Int", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 245..246, + value: Var { + location: 245..246, + name: "b", + }, + }, + ], + fun: Var { + location: 226..238, + name: "compute_with", + }, + location: 226..247, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 261..262, + value: Var { + location: 261..262, + name: "a", + }, + }, + CallArg { + label: None, + location: 264..265, + value: Fn { + location: 264..265, + fn_style: BinOp( + MultInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 264..265, + is_validator_param: false, + }, + location: 264..265, + annotation: Some( + Constructor { + location: 264..265, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 264..265, + is_validator_param: false, + }, + location: 264..265, + annotation: Some( + Constructor { + location: 264..265, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 264..265, + name: MultInt, + left: Var { + location: 264..265, + name: "left", + }, + right: Var { + location: 264..265, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 264..265, + module: None, + name: "Int", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 267..268, + value: Var { + location: 267..268, + name: "b", + }, + }, + ], + fun: Var { + location: 248..260, + name: "compute_with", + }, + location: 248..269, + }, + Call { + arguments: [ + CallArg { + label: None, + location: 283..284, + value: Var { + location: 283..284, + name: "a", + }, + }, + CallArg { + label: None, + location: 286..287, + value: Fn { + location: 286..287, + fn_style: BinOp( + ModInt, + ), + arguments: [ + Arg { + arg_name: Named { + name: "left", + label: "left", + location: 286..287, + is_validator_param: false, + }, + location: 286..287, + annotation: Some( + Constructor { + location: 286..287, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + Arg { + arg_name: Named { + name: "right", + label: "right", + location: 286..287, + is_validator_param: false, + }, + location: 286..287, + annotation: Some( + Constructor { + location: 286..287, + module: None, + name: "Int", + arguments: [], + }, + ), + tipo: (), + }, + ], + body: BinOp { + location: 286..287, + name: ModInt, + left: Var { + location: 286..287, + name: "left", + }, + right: Var { + location: 286..287, + name: "right", + }, + }, + return_annotation: Some( + Constructor { + location: 286..287, + module: None, + name: "Int", + arguments: [], + }, + ), + }, + }, + CallArg { + label: None, + location: 289..290, + value: Var { + location: 289..290, + name: "b", + }, + }, + ], + fun: Var { + location: 270..282, + name: "compute_with", + }, + location: 270..291, + }, + ], +} diff --git a/crates/aiken-lang/src/tests/snapshots/function_ambiguous_sequence.snap b/crates/aiken-lang/src/snapshots/function_ambiguous_sequence.snap similarity index 99% rename from crates/aiken-lang/src/tests/snapshots/function_ambiguous_sequence.snap rename to crates/aiken-lang/src/snapshots/function_ambiguous_sequence.snap index 48729512..0f6292b0 100644 --- a/crates/aiken-lang/src/tests/snapshots/function_ambiguous_sequence.snap +++ b/crates/aiken-lang/src/snapshots/function_ambiguous_sequence.snap @@ -1,5 +1,5 @@ --- -source: crates/aiken-lang/src/tests/parser.rs +source: crates/aiken-lang/src/parser.rs description: "Code:\n\nfn foo_1() {\n let a = bar\n (40)\n}\n\nfn foo_2() {\n let a = bar\n {40}\n}\n\nfn foo_3() {\n let a = (40+2)\n}\n\nfn foo_4() {\n let a = bar(42)\n (a + 14) * 42\n}\n" --- Module { diff --git a/crates/aiken-lang/src/tests/parser.rs b/crates/aiken-lang/src/tests/parser.rs index 54ffec99..7bc5c6c2 100644 --- a/crates/aiken-lang/src/tests/parser.rs +++ b/crates/aiken-lang/src/tests/parser.rs @@ -168,15 +168,6 @@ fn base16_bytearray_literals() { ); } -#[test] -fn function_def() { - assert_module!( - r#" - fn foo() {} - "# - ); -} - #[test] fn function_invoke() { assert_module!( @@ -188,55 +179,6 @@ fn function_invoke() { ); } -#[test] -fn function_ambiguous_sequence() { - assert_module!( - r#" - fn foo_1() { - let a = bar - (40) - } - - fn foo_2() { - let a = bar - {40} - } - - fn foo_3() { - let a = (40+2) - } - - fn foo_4() { - let a = bar(42) - (a + 14) * 42 - } - "# - ); -} - -#[test] -fn first_class_binop() { - assert_module!( - r#" - fn foo() { - compare_with(a, >, b) - compare_with(a, >=, b) - compare_with(a, <, b) - compare_with(a, <=, b) - compare_with(a, ==, b) - compare_with(a, !=, b) - combine_with(a, &&, b) - combine_with(a, ||, b) - compute_with(a, +, b) - compute_with(a, -, b) - compute_with(a, /, b) - compute_with(a, *, b) - compute_with(a, %, b) - } - "# - ); -} - #[test] fn parse_unicode_offset_1() { assert_module!( diff --git a/crates/aiken-lang/src/tests/snapshots/first_class_binop.snap b/crates/aiken-lang/src/tests/snapshots/first_class_binop.snap deleted file mode 100644 index 679c61cc..00000000 --- a/crates/aiken-lang/src/tests/snapshots/first_class_binop.snap +++ /dev/null @@ -1,1211 +0,0 @@ ---- -source: crates/aiken-lang/src/tests/parser.rs -description: "Code:\n\nfn foo() {\n compare_with(a, >, b)\n compare_with(a, >=, b)\n compare_with(a, <, b)\n compare_with(a, <=, b)\n compare_with(a, ==, b)\n compare_with(a, !=, b)\n combine_with(a, &&, b)\n combine_with(a, ||, b)\n compute_with(a, +, b)\n compute_with(a, -, b)\n compute_with(a, /, b)\n compute_with(a, *, b)\n compute_with(a, %, b)\n}\n" ---- -Module { - name: "", - docs: [], - type_info: (), - definitions: [ - Fn( - Function { - arguments: [], - body: Sequence { - location: 13..328, - expressions: [ - Call { - arguments: [ - CallArg { - label: None, - location: 26..27, - value: Var { - location: 26..27, - name: "a", - }, - }, - CallArg { - label: None, - location: 29..30, - value: Fn { - location: 29..30, - fn_style: BinOp( - GtInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 29..30, - is_validator_param: false, - }, - location: 29..30, - annotation: Some( - Constructor { - location: 29..30, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 29..30, - is_validator_param: false, - }, - location: 29..30, - annotation: Some( - Constructor { - location: 29..30, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 29..30, - name: GtInt, - left: Var { - location: 29..30, - name: "left", - }, - right: Var { - location: 29..30, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 29..30, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 32..33, - value: Var { - location: 32..33, - name: "b", - }, - }, - ], - fun: Var { - location: 13..25, - name: "compare_with", - }, - location: 13..34, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 50..51, - value: Var { - location: 50..51, - name: "a", - }, - }, - CallArg { - label: None, - location: 53..55, - value: Fn { - location: 53..55, - fn_style: BinOp( - GtEqInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 53..55, - is_validator_param: false, - }, - location: 53..55, - annotation: Some( - Constructor { - location: 53..55, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 53..55, - is_validator_param: false, - }, - location: 53..55, - annotation: Some( - Constructor { - location: 53..55, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 53..55, - name: GtEqInt, - left: Var { - location: 53..55, - name: "left", - }, - right: Var { - location: 53..55, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 53..55, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 57..58, - value: Var { - location: 57..58, - name: "b", - }, - }, - ], - fun: Var { - location: 37..49, - name: "compare_with", - }, - location: 37..59, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 75..76, - value: Var { - location: 75..76, - name: "a", - }, - }, - CallArg { - label: None, - location: 78..79, - value: Fn { - location: 78..79, - fn_style: BinOp( - LtInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 78..79, - is_validator_param: false, - }, - location: 78..79, - annotation: Some( - Constructor { - location: 78..79, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 78..79, - is_validator_param: false, - }, - location: 78..79, - annotation: Some( - Constructor { - location: 78..79, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 78..79, - name: LtInt, - left: Var { - location: 78..79, - name: "left", - }, - right: Var { - location: 78..79, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 78..79, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 81..82, - value: Var { - location: 81..82, - name: "b", - }, - }, - ], - fun: Var { - location: 62..74, - name: "compare_with", - }, - location: 62..83, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 99..100, - value: Var { - location: 99..100, - name: "a", - }, - }, - CallArg { - label: None, - location: 102..104, - value: Fn { - location: 102..104, - fn_style: BinOp( - LtEqInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 102..104, - is_validator_param: false, - }, - location: 102..104, - annotation: Some( - Constructor { - location: 102..104, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 102..104, - is_validator_param: false, - }, - location: 102..104, - annotation: Some( - Constructor { - location: 102..104, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 102..104, - name: LtEqInt, - left: Var { - location: 102..104, - name: "left", - }, - right: Var { - location: 102..104, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 102..104, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 106..107, - value: Var { - location: 106..107, - name: "b", - }, - }, - ], - fun: Var { - location: 86..98, - name: "compare_with", - }, - location: 86..108, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 124..125, - value: Var { - location: 124..125, - name: "a", - }, - }, - CallArg { - label: None, - location: 127..129, - value: Fn { - location: 127..129, - fn_style: BinOp( - Eq, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 127..129, - is_validator_param: false, - }, - location: 127..129, - annotation: None, - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 127..129, - is_validator_param: false, - }, - location: 127..129, - annotation: None, - tipo: (), - }, - ], - body: BinOp { - location: 127..129, - name: Eq, - left: Var { - location: 127..129, - name: "left", - }, - right: Var { - location: 127..129, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 127..129, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 131..132, - value: Var { - location: 131..132, - name: "b", - }, - }, - ], - fun: Var { - location: 111..123, - name: "compare_with", - }, - location: 111..133, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 149..150, - value: Var { - location: 149..150, - name: "a", - }, - }, - CallArg { - label: None, - location: 152..154, - value: Fn { - location: 152..154, - fn_style: BinOp( - NotEq, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 152..154, - is_validator_param: false, - }, - location: 152..154, - annotation: None, - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 152..154, - is_validator_param: false, - }, - location: 152..154, - annotation: None, - tipo: (), - }, - ], - body: BinOp { - location: 152..154, - name: NotEq, - left: Var { - location: 152..154, - name: "left", - }, - right: Var { - location: 152..154, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 152..154, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 156..157, - value: Var { - location: 156..157, - name: "b", - }, - }, - ], - fun: Var { - location: 136..148, - name: "compare_with", - }, - location: 136..158, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 174..175, - value: Var { - location: 174..175, - name: "a", - }, - }, - CallArg { - label: None, - location: 177..179, - value: Fn { - location: 177..179, - fn_style: BinOp( - And, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 177..179, - is_validator_param: false, - }, - location: 177..179, - annotation: Some( - Constructor { - location: 177..179, - module: None, - name: "Bool", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 177..179, - is_validator_param: false, - }, - location: 177..179, - annotation: Some( - Constructor { - location: 177..179, - module: None, - name: "Bool", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 177..179, - name: And, - left: Var { - location: 177..179, - name: "left", - }, - right: Var { - location: 177..179, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 177..179, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 181..182, - value: Var { - location: 181..182, - name: "b", - }, - }, - ], - fun: Var { - location: 161..173, - name: "combine_with", - }, - location: 161..183, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 199..200, - value: Var { - location: 199..200, - name: "a", - }, - }, - CallArg { - label: None, - location: 202..204, - value: Fn { - location: 202..204, - fn_style: BinOp( - Or, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 202..204, - is_validator_param: false, - }, - location: 202..204, - annotation: Some( - Constructor { - location: 202..204, - module: None, - name: "Bool", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 202..204, - is_validator_param: false, - }, - location: 202..204, - annotation: Some( - Constructor { - location: 202..204, - module: None, - name: "Bool", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 202..204, - name: Or, - left: Var { - location: 202..204, - name: "left", - }, - right: Var { - location: 202..204, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 202..204, - module: None, - name: "Bool", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 206..207, - value: Var { - location: 206..207, - name: "b", - }, - }, - ], - fun: Var { - location: 186..198, - name: "combine_with", - }, - location: 186..208, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 224..225, - value: Var { - location: 224..225, - name: "a", - }, - }, - CallArg { - label: None, - location: 227..228, - value: Fn { - location: 227..228, - fn_style: BinOp( - AddInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 227..228, - is_validator_param: false, - }, - location: 227..228, - annotation: Some( - Constructor { - location: 227..228, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 227..228, - is_validator_param: false, - }, - location: 227..228, - annotation: Some( - Constructor { - location: 227..228, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 227..228, - name: AddInt, - left: Var { - location: 227..228, - name: "left", - }, - right: Var { - location: 227..228, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 227..228, - module: None, - name: "Int", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 230..231, - value: Var { - location: 230..231, - name: "b", - }, - }, - ], - fun: Var { - location: 211..223, - name: "compute_with", - }, - location: 211..232, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 248..249, - value: Var { - location: 248..249, - name: "a", - }, - }, - CallArg { - label: None, - location: 251..252, - value: Fn { - location: 251..252, - fn_style: BinOp( - SubInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 251..252, - is_validator_param: false, - }, - location: 251..252, - annotation: Some( - Constructor { - location: 251..252, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 251..252, - is_validator_param: false, - }, - location: 251..252, - annotation: Some( - Constructor { - location: 251..252, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 251..252, - name: SubInt, - left: Var { - location: 251..252, - name: "left", - }, - right: Var { - location: 251..252, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 251..252, - module: None, - name: "Int", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 254..255, - value: Var { - location: 254..255, - name: "b", - }, - }, - ], - fun: Var { - location: 235..247, - name: "compute_with", - }, - location: 235..256, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 272..273, - value: Var { - location: 272..273, - name: "a", - }, - }, - CallArg { - label: None, - location: 275..276, - value: Fn { - location: 275..276, - fn_style: BinOp( - DivInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 275..276, - is_validator_param: false, - }, - location: 275..276, - annotation: Some( - Constructor { - location: 275..276, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 275..276, - is_validator_param: false, - }, - location: 275..276, - annotation: Some( - Constructor { - location: 275..276, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 275..276, - name: DivInt, - left: Var { - location: 275..276, - name: "left", - }, - right: Var { - location: 275..276, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 275..276, - module: None, - name: "Int", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 278..279, - value: Var { - location: 278..279, - name: "b", - }, - }, - ], - fun: Var { - location: 259..271, - name: "compute_with", - }, - location: 259..280, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 296..297, - value: Var { - location: 296..297, - name: "a", - }, - }, - CallArg { - label: None, - location: 299..300, - value: Fn { - location: 299..300, - fn_style: BinOp( - MultInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 299..300, - is_validator_param: false, - }, - location: 299..300, - annotation: Some( - Constructor { - location: 299..300, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 299..300, - is_validator_param: false, - }, - location: 299..300, - annotation: Some( - Constructor { - location: 299..300, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 299..300, - name: MultInt, - left: Var { - location: 299..300, - name: "left", - }, - right: Var { - location: 299..300, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 299..300, - module: None, - name: "Int", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 302..303, - value: Var { - location: 302..303, - name: "b", - }, - }, - ], - fun: Var { - location: 283..295, - name: "compute_with", - }, - location: 283..304, - }, - Call { - arguments: [ - CallArg { - label: None, - location: 320..321, - value: Var { - location: 320..321, - name: "a", - }, - }, - CallArg { - label: None, - location: 323..324, - value: Fn { - location: 323..324, - fn_style: BinOp( - ModInt, - ), - arguments: [ - Arg { - arg_name: Named { - name: "left", - label: "left", - location: 323..324, - is_validator_param: false, - }, - location: 323..324, - annotation: Some( - Constructor { - location: 323..324, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - Arg { - arg_name: Named { - name: "right", - label: "right", - location: 323..324, - is_validator_param: false, - }, - location: 323..324, - annotation: Some( - Constructor { - location: 323..324, - module: None, - name: "Int", - arguments: [], - }, - ), - tipo: (), - }, - ], - body: BinOp { - location: 323..324, - name: ModInt, - left: Var { - location: 323..324, - name: "left", - }, - right: Var { - location: 323..324, - name: "right", - }, - }, - return_annotation: Some( - Constructor { - location: 323..324, - module: None, - name: "Int", - arguments: [], - }, - ), - }, - }, - CallArg { - label: None, - location: 326..327, - value: Var { - location: 326..327, - name: "b", - }, - }, - ], - fun: Var { - location: 307..319, - name: "compute_with", - }, - location: 307..328, - }, - ], - }, - doc: None, - location: 0..8, - name: "foo", - public: false, - return_annotation: None, - return_type: (), - end_position: 329, - can_error: true, - }, - ), - ], - kind: Validator, -} diff --git a/crates/aiken-lang/src/tests/snapshots/function_def.snap b/crates/aiken-lang/src/tests/snapshots/function_def.snap deleted file mode 100644 index c9909b7e..00000000 --- a/crates/aiken-lang/src/tests/snapshots/function_def.snap +++ /dev/null @@ -1,36 +0,0 @@ ---- -source: crates/aiken-lang/src/tests/parser.rs -description: "Code:\n\nfn foo() {}\n" ---- -Module { - name: "", - docs: [], - type_info: (), - definitions: [ - Fn( - Function { - arguments: [], - body: Trace { - kind: Todo, - location: 0..11, - then: ErrorTerm { - location: 0..11, - }, - text: String { - location: 0..11, - value: "aiken::todo", - }, - }, - doc: None, - location: 0..8, - name: "foo", - public: false, - return_annotation: None, - return_type: (), - end_position: 10, - can_error: true, - }, - ), - ], - kind: Validator, -}