From addec372feed98141ad0b2d9f8f6e1b6a439cd0d Mon Sep 17 00:00:00 2001 From: mehbark Date: Wed, 7 Jan 2026 01:13:25 -0500 Subject: [PATCH] add thunk syntax --- src/parser.rs | 13 +++++++++++++ src/tests/parser.rs | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 2e6dbc8..021c36a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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(); diff --git a/src/tests/parser.rs b/src/tests/parser.rs index 0be8736..c084063 100644 --- a/src/tests/parser.rs +++ b/src/tests/parser.rs @@ -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)) + ", + ); +}