add thunk syntax
This commit is contained in:
parent
818f9afb3c
commit
addec372fe
2 changed files with 31 additions and 0 deletions
|
|
@ -145,6 +145,14 @@ where
|
|||
.delimited_by(just(Token::OpenParen), just(Token::CloseParen))
|
||||
.labelled("block");
|
||||
|
||||
let thunk = expr
|
||||
.clone()
|
||||
.separated_by(semicolon.clone())
|
||||
.allow_trailing()
|
||||
.collect()
|
||||
.delimited_by(just(Token::OpenBracket), just(Token::CloseBracket))
|
||||
.labelled("thunk");
|
||||
|
||||
let map = expr
|
||||
.clone()
|
||||
.separated_by(semicolon.clone())
|
||||
|
|
@ -208,6 +216,11 @@ where
|
|||
ident.map(Ast::Var).labelled("variable"),
|
||||
map,
|
||||
block.map(Ast::Block),
|
||||
thunk.map(|body| Ast::Fn {
|
||||
inputs: vec![],
|
||||
outputs: vec![],
|
||||
body,
|
||||
}),
|
||||
))
|
||||
.boxed();
|
||||
|
||||
|
|
|
|||
|
|
@ -197,3 +197,21 @@ counter_b.dec {};
|
|||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thunks() {
|
||||
test(
|
||||
"
|
||||
if [wow = cool]() [
|
||||
then branch stuff; cool;
|
||||
] [
|
||||
else branch stuff; cool;
|
||||
]
|
||||
",
|
||||
"
|
||||
((((if (fn ([] []) (wow = cool))) ()) \
|
||||
(fn ([] []) ((then branch) stuff) cool)) \
|
||||
(fn ([] []) ((else branch) stuff) cool))
|
||||
",
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue