feat: add lambda
This commit is contained in:
parent
b3318e5f24
commit
6da0c829df
|
@ -1,3 +1,3 @@
|
|||
(program 1.0.0
|
||||
(con bool False)
|
||||
[(lam x (con integer 4)) (con bool False)]
|
||||
)
|
|
@ -52,11 +52,19 @@ where
|
|||
Input: Stream<Token = char>,
|
||||
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
|
||||
{
|
||||
between(
|
||||
choice((
|
||||
attempt(between(token('['), token(']'), apply())),
|
||||
attempt(between(
|
||||
token('('),
|
||||
token(')'),
|
||||
choice((attempt(constant()), attempt(delay()), attempt(force()))),
|
||||
)
|
||||
choice((
|
||||
attempt(delay()),
|
||||
attempt(lambda()),
|
||||
attempt(constant()),
|
||||
attempt(force()),
|
||||
)),
|
||||
)),
|
||||
))
|
||||
.skip(spaces())
|
||||
}
|
||||
|
||||
|
@ -90,6 +98,32 @@ where
|
|||
.map(|term| Term::Force(Box::new(term)))
|
||||
}
|
||||
|
||||
pub fn lambda<Input>() -> impl Parser<Input, Output = Term>
|
||||
where
|
||||
Input: Stream<Token = char>,
|
||||
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
|
||||
{
|
||||
string("lam")
|
||||
.with(skip_many1(space()))
|
||||
.with((many1(alpha_num()), skip_many1(space()), term_()))
|
||||
.map(|(parameter_name, _, term)| Term::Lambda {
|
||||
parameter_name,
|
||||
body: Box::new(term),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn apply<Input>() -> impl Parser<Input, Output = Term>
|
||||
where
|
||||
Input: Stream<Token = char>,
|
||||
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
|
||||
{
|
||||
println!("daid");
|
||||
(term_(), skip_many1(space()), term_()).map(|(function, _, argument)| Term::Apply {
|
||||
function: Box::new(function),
|
||||
argument: Box::new(argument),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn constant<Input>() -> impl Parser<Input, Output = Term>
|
||||
where
|
||||
Input: Stream<Token = char>,
|
||||
|
|
Loading…
Reference in New Issue