feat(ast): handle the empty tuple type

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-10-14 12:22:31 +02:00
parent e2f0848773
commit d1ee66a747
2 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -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, [])
])
]
}
}