From 908d6e6a5f1f34bbd218a9b70c1b02099344f6e5 Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 22 Jul 2024 21:41:07 +0200 Subject: [PATCH] Add function types --- src/grammar.pest | 2 +- src/test/types.rs | 7 ++++++ tests/corpus/types/functions.txt | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/corpus/types/functions.txt diff --git a/src/grammar.pest b/src/grammar.pest index e99471b..58f0e42 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -8,7 +8,7 @@ block = { "{" ~ MLF ~ block_line ~ MLF ~ "}" } block_line = _{ expr | (statement ~ MLF)* } type_decl = { "type" ~ #name = type_ident ~ "=" ~ type_expr } -type_expr = { type_term | func | type_ident } +type_expr = { func | type_term | type_ident } type_term = _{ tuple | rec | enum | type_ident } tuple = { "#(" ~ MLF ~ tuple_entry* ~ MLF ~ ")" } diff --git a/src/test/types.rs b/src/test/types.rs index 86a4fef..365d2ad 100644 --- a/src/test/types.rs +++ b/src/test/types.rs @@ -75,3 +75,10 @@ fn it_parses_generics() { panic!("{e}") } } + +#[test] +fn it_parses_functions() { + if let Err(e) = (*TESTER).evaluate_strict("functions") { + panic!("{e}") + } +} diff --git a/tests/corpus/types/functions.txt b/tests/corpus/types/functions.txt new file mode 100644 index 0000000..e73b823 --- /dev/null +++ b/tests/corpus/types/functions.txt @@ -0,0 +1,37 @@ +Recs Test + +====== + +type MyFn = Num -> Num -> Str + +====== + +(file + (statement + (type_decl + (type_ident + (ident: "MyFn") + ) + (type_expr + (func + (type_ident + (ident: "Num") + ) + (type_expr + (func + (type_ident + (ident: "Num") + ) + (type_expr + (type_ident + (ident: "Str") + ) + ) + ) + ) + ) + ) + ) + ) + (EOI: "") +)