diff --git a/example/plutus-core b/example/plutus-core index f060918b..aa257de7 100644 --- a/example/plutus-core +++ b/example/plutus-core @@ -1,3 +1,3 @@ (program 1.0.0 - (con bool False) -) \ No newline at end of file + [(lam x (con integer 4)) (con bool False)] +) diff --git a/src/parser.rs b/src/parser.rs index 10523e34..24936aeb 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -52,11 +52,19 @@ where Input: Stream, Input::Error: ParseError, { - between( - token('('), - token(')'), - choice((attempt(constant()), attempt(delay()), attempt(force()))), - ) + choice(( + attempt(between(token('['), token(']'), apply())), + attempt(between( + token('('), + token(')'), + 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() -> impl Parser +where + Input: Stream, + Input::Error: ParseError, +{ + 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() -> impl Parser +where + Input: Stream, + Input::Error: ParseError, +{ + println!("daid"); + (term_(), skip_many1(space()), term_()).map(|(function, _, argument)| Term::Apply { + function: Box::new(function), + argument: Box::new(argument), + }) +} + pub fn constant() -> impl Parser where Input: Stream,