From d1ee66a7475803c4b2daf04b9b047471ed028a94 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 14 Oct 2020 12:22:31 +0200 Subject: [PATCH] feat(ast): handle the empty tuple type Signed-off-by: ljedrz --- ast/src/leo.pest | 2 +- ast/tests/tuple.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ast/src/leo.pest b/ast/src/leo.pest index f9b6c9f4cb..71024b6439 100644 --- a/ast/src/leo.pest +++ b/ast/src/leo.pest @@ -226,7 +226,7 @@ dimension_single = { // Declared in types/array_dimensions.rs dimension_multiple = { "(" ~ number_positive ~ ("," ~ number_positive)* ~ ")"} -type_tuple = { "(" ~ NEWLINE* ~ type_ ~ ("," ~ NEWLINE* ~ type_)+ ~ ","? ~ NEWLINE* ~ ")" } +type_tuple = { "(" ~ NEWLINE* ~ (type_ ~ ("," ~ NEWLINE* ~ type_)+ ~ ","?)? ~ NEWLINE* ~ ")" } /// Values diff --git a/ast/tests/tuple.rs b/ast/tests/tuple.rs index 284e1603cb..4b550214fe 100644 --- a/ast/tests/tuple.rs +++ b/ast/tests/tuple.rs @@ -59,7 +59,7 @@ fn access() { } #[test] -fn unit() { +fn implicit_unit() { parses_to! { parser: LanguageParser, input: "()", @@ -69,3 +69,23 @@ fn unit() { ] } } + +#[test] +fn explicit_unit() { + parses_to! { + parser: LanguageParser, + input: "let x: () = ();", + rule: Rule::statement_definition, + tokens: [ + statement_definition(0, 15, [ + declare(0, 4, [let_(0, 4, [])]), + variables(4, 9, [ + variable_name(4, 5, [identifier(4, 5, [])]), + type_(7, 9, [type_tuple(7, 9, [])]) + ]), + expression(12, 14, [expression_term(12, 14, [expression_tuple(12, 14, [])])]), + LINE_END(14, 15, []) + ]) + ] + } +}