From 895f279be0dec7c1cc21e86ae666edf79593fb99 Mon Sep 17 00:00:00 2001 From: Kasey White Date: Mon, 6 Jun 2022 23:28:36 -0400 Subject: [PATCH] fix: parser fixes for spacing --- crates/uplc/example/integer.uplc | 6 +++- crates/uplc/src/parser.rs | 57 ++++++++++++++++---------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/crates/uplc/example/integer.uplc b/crates/uplc/example/integer.uplc index 86df1598..f72bf9be 100644 --- a/crates/uplc/example/integer.uplc +++ b/crates/uplc/example/integer.uplc @@ -1,3 +1,7 @@ (program 11.22.33 - (lam x (lam x y)) + [ + ( + lam x (lam x y)) (con string "PT8" + ) + ] ) \ No newline at end of file diff --git a/crates/uplc/src/parser.rs b/crates/uplc/src/parser.rs index 3f71202e..68c725d5 100644 --- a/crates/uplc/src/parser.rs +++ b/crates/uplc/src/parser.rs @@ -131,10 +131,8 @@ where between( token('('), token(')'), - string("delay") - .skip(skip_many1(space())) - .with(term()) - .map(|term| Term::Delay(Box::new(term))), + (spaces(), string("delay"), skip_many1(space()), term()) + .map(|(_, _, _, term)| Term::Delay(Box::new(term))), ) } @@ -146,10 +144,8 @@ where between( token('('), token(')'), - string("force") - .skip(skip_many1(space())) - .with(term()) - .map(|term| Term::Force(Box::new(term))), + (spaces(), string("force"), skip_many1(space()), term()) + .map(|(_, _, _, term)| Term::Force(Box::new(term))), ) } @@ -161,10 +157,15 @@ where between( token('('), token(')'), - string("lam") - .with(skip_many1(space())) - .with((name(), skip_many1(space()), term())) - .map(|(parameter_name, _, term)| Term::Lambda { + ( + spaces(), + string("lam"), + skip_many1(space()), + name(), + skip_many1(space()), + term(), + ) + .map(|(_, _, _, parameter_name, _, term)| Term::Lambda { parameter_name, body: Box::new(term), }), @@ -179,7 +180,7 @@ where between( token('['), token(']'), - (term().skip(skip_many1(space())), term()).map(|(function, argument)| Term::Apply { + (spaces(), term(), spaces(), term()).map(|(_, function, _, argument)| Term::Apply { function: Box::new(function), argument: Box::new(argument), }), @@ -192,7 +193,7 @@ where Input::Error: ParseError, { between( - token('('), + token('(').skip(spaces()), token(')'), string("builtin") .with(skip_many1(space())) @@ -209,7 +210,7 @@ where Input::Error: ParseError, { between( - token('('), + token('(').skip(spaces()), token(')'), string("error") .with(skip_many1(space())) @@ -223,18 +224,22 @@ where Input::Error: ParseError, { between( - token('('), + token('(').skip(spaces()), token(')'), - string("con") - .with(skip_many1(space())) - .with(choice(( + ( + spaces(), + string("con"), + skip_many1(space()), + choice(( attempt(constant_integer()), attempt(constant_bytestring()), attempt(constant_string()), attempt(constant_unit()), attempt(constant_bool()), - ))) - .map(Term::Constant), + )), + spaces(), + ) + .map(|(_, _, _, con, _)| Term::Constant(con)), ) } @@ -301,13 +306,9 @@ where { look_ahead(letter()) .with(many1(alpha_num().or(token('_').or(token('\''))))) - .map_input(|text: String, input: &mut StateStream| { - println!("{:?}", text); - - Name { - unique: input.state.intern(&text), - text, - } + .map_input(|text: String, input: &mut StateStream| Name { + unique: input.state.intern(&text), + text, }) }