Add type annotations

main
trivernis 4 months ago
parent 908d6e6a5f
commit 34261ac06b
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 7E6D18B61C8D2F4B

@ -3,10 +3,12 @@ file = {
}
statement = { (decl | type_decl | expr) ~ TERMINATE }
decl = { "let" ~ #name = ident ~ #args = (ident)* ~ "=" ~ expr }
decl = { "let" ~ #name = ident ~ #args = (ident)* ~ #type = type_annot? ~ "=" ~ expr }
block = { "{" ~ MLF ~ block_line ~ MLF ~ "}" }
block_line = _{ expr | (statement ~ MLF)* }
type_annot = { ":" ~ type_expr }
type_decl = { "type" ~ #name = type_ident ~ "=" ~ type_expr }
type_expr = { func | type_term | type_ident }
type_term = _{ tuple | rec | enum | type_ident }

@ -22,6 +22,13 @@ fn it_parses_decl_with_args() {
}
}
#[test]
fn it_parses_decl_with_type() {
if let Err(e) = (*TESTER).evaluate_strict("decl-with-type") {
panic!("{e}")
}
}
#[test]
fn it_parses_blocks() {
parses_to!(parser: SnekParser, input: "let a = { 1 + 1 }", rule: Rule::statement, tokens: [

@ -0,0 +1,66 @@
Declaration Test
======
let a: Num = 1 + 1
let add_a x: Num -> Num = x + a
======
(file
(statement
(decl
(ident: "a")
(type_annot
(type_expr
(type_ident
(ident: "Num")
)
)
)
(expr
(infix_expr
(literal
(integer: "1")
)
(operator: "+")
(expr
(literal
(integer: "1")
)
)
)
)
)
)
(statement
(decl
(ident: "add_a")
(ident: "x")
(type_annot
(type_expr
(func
(type_ident
(ident: "Num")
)
(type_expr
(type_ident
(ident: "Num")
)
)
)
)
)
(expr
(infix_expr
(ident: "x")
(operator: "+")
(expr
(ident: "a")
)
)
)
)
)
(EOI: "")
)
Loading…
Cancel
Save