Add corpus tests

main
trivernis 2 months ago
parent 520fa3780d
commit a71af581e3
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -0,0 +1,24 @@
type Food = #[
Apple Num
Banana Num
Cereal Num
Milk #(String Num)
]
type Utils = #[
Paper Num
Detergent Num
Pencils Num
]
type Packaging = #[
Bag
PlasticBag
]
type ShoppingList = #{
food: Food
utils: Utils
packaging: Packaging
}

@ -1,9 +1,11 @@
file = { "hello world" }
file = {
SOI ~ MLF ~ (statement ~ MLF)* ~ EOI
}
block = { "{" ~ MLF ~ block_line ~ MLF ~ "}" }
block_line = _{ expr | (statement ~ MLF)* }
statement = { (decl | type_decl | expr) ~ TERMINATE }
decl = { "let" ~ #name = ident ~ #args = (ident)* ~ "=" ~ expr }
block = { "{" ~ MLF ~ block_line ~ MLF ~ "}" }
block_line = _{ expr | (statement ~ MLF)* }
type_decl = { "type" ~ #name = type_ident ~ "=" ~ type_expr }
type_expr = { tuple | rec | enum | type_ident }
@ -14,8 +16,8 @@ tuple_entry = _{ type_expr ~ MLF }
rec = { "#{" ~ MLF ~ (rec_field ~ TERMINATE ~ MLF)* ~ rec_field? ~ MLF ~ "}" }
rec_field = { #field_name = ident ~ ":" ~ #field_type = type_expr* }
enum = { "#[" ~ (enum_vrt ~ TERMINATE ~ MLF)* ~ enum_vrt? ~ "]" }
enum_vrt = { #vrt_name = ident ~ type_expr }
enum = { "#[" ~ MLF ~ (enum_vrt ~ TERMINATE ~ MLF)* ~ enum_vrt? ~ "]" }
enum_vrt = { #vrt_name = ident ~ type_expr? }
type_ident = ${ #name = ident ~ #args = type_args? }
type_args = { "<" ~ MLF ~ type_ident* ~ MLF ~ ">" }
@ -46,8 +48,10 @@ float = @{
byte = @{ "0x" ~ ASCII_HEX_DIGIT{1, 2} | "0b" ~ ASCII_BIN_DIGIT{0, 8} }
boolean = @{ "true" | "false" }
WHITESPACE = _{ " " | "\t" }
KEYWORD = _{ "let" }
TERMINATE = _{ LF | EOI | ";" }
MLF = _{ (LF)* }
LF = _{ "\n" | "\r" }
WHITESPACE = _{ " " | "\t" }
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }

@ -6,6 +6,10 @@ mod types;
use crate::parse;
#[test]
fn it_parses() {
parse("hello world").unwrap();
fn it_parse_types() {
let result = parse(include_str!("../../corpus/types.sk"));
if let Err(e) = result {
panic!("{e}")
}
}

Loading…
Cancel
Save