fix: different attempt

This commit is contained in:
rvcas 2022-06-09 00:44:52 -04:00
parent 474df4a3ae
commit 86089b4bee
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
1 changed files with 12 additions and 11 deletions

View File

@ -71,19 +71,21 @@ fn version() -> impl Parser<char, (usize, usize, usize), Error = Simple<char>> {
fn term() -> impl Parser<char, Term<Name>, Error = Simple<char>> { fn term() -> impl Parser<char, Term<Name>, Error = Simple<char>> {
recursive(|term| { recursive(|term| {
let atom = || var().or(term.clone());
let delay = keyword("delay") let delay = keyword("delay")
.ignore_then(term.clone().padded()) .ignore_then(atom().padded())
.delimited_by(just('(').padded(), just(')').padded()) .delimited_by(just('(').padded(), just(')').padded())
.map(|t| dbg!(Term::Delay(Box::new(t)))); .map(|t| dbg!(Term::Delay(Box::new(t))));
let force = keyword("force") let force = keyword("force")
.ignore_then(term.clone().padded()) .ignore_then(atom().padded())
.delimited_by(just('(').padded(), just(')').padded()) .delimited_by(just('(').padded(), just(')').padded())
.map(|t| dbg!(Term::Force(Box::new(t)))); .map(|t| dbg!(Term::Force(Box::new(t))));
let lambda = keyword("lam") let lambda = keyword("lam")
.ignore_then(name().padded()) .ignore_then(name().padded())
.then(term.clone()) .then(atom())
.delimited_by(just('(').padded(), just(')').padded()) .delimited_by(just('(').padded(), just(')').padded())
.map(|(parameter_name, t)| { .map(|(parameter_name, t)| {
dbg!(Term::Lambda { dbg!(Term::Lambda {
@ -92,17 +94,16 @@ fn term() -> impl Parser<char, Term<Name>, Error = Simple<char>> {
}) })
}); });
let apply = recursive(|a| { let apply = atom()
var()
.or(term.clone())
.padded() .padded()
.then(a) .then(atom())
.map(|(function, argument)| Term::Apply { .delimited_by(just('[').padded(), just(']').padded())
.map(|(function, argument)| {
dbg!(Term::Apply {
function: Box::new(function), function: Box::new(function),
argument: Box::new(argument), argument: Box::new(argument),
}) })
}) });
.delimited_by(just('[').padded(), just(']').padded());
constant() constant()
.or(builtin()) .or(builtin())