fix: parser fixes for spacing

This commit is contained in:
Kasey White 2022-06-06 23:28:36 -04:00
parent 60a920a0ac
commit 895f279be0
2 changed files with 34 additions and 29 deletions

View File

@ -1,3 +1,7 @@
(program 11.22.33 (program 11.22.33
(lam x (lam x y)) [
(
lam x (lam x y)) (con string "PT8"
)
]
) )

View File

@ -131,10 +131,8 @@ where
between( between(
token('('), token('('),
token(')'), token(')'),
string("delay") (spaces(), string("delay"), skip_many1(space()), term())
.skip(skip_many1(space())) .map(|(_, _, _, term)| Term::Delay(Box::new(term))),
.with(term())
.map(|term| Term::Delay(Box::new(term))),
) )
} }
@ -146,10 +144,8 @@ where
between( between(
token('('), token('('),
token(')'), token(')'),
string("force") (spaces(), string("force"), skip_many1(space()), term())
.skip(skip_many1(space())) .map(|(_, _, _, term)| Term::Force(Box::new(term))),
.with(term())
.map(|term| Term::Force(Box::new(term))),
) )
} }
@ -161,10 +157,15 @@ where
between( between(
token('('), token('('),
token(')'), token(')'),
string("lam") (
.with(skip_many1(space())) spaces(),
.with((name(), skip_many1(space()), term())) string("lam"),
.map(|(parameter_name, _, term)| Term::Lambda { skip_many1(space()),
name(),
skip_many1(space()),
term(),
)
.map(|(_, _, _, parameter_name, _, term)| Term::Lambda {
parameter_name, parameter_name,
body: Box::new(term), body: Box::new(term),
}), }),
@ -179,7 +180,7 @@ where
between( between(
token('['), token('['),
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), function: Box::new(function),
argument: Box::new(argument), argument: Box::new(argument),
}), }),
@ -192,7 +193,7 @@ where
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{ {
between( between(
token('('), token('(').skip(spaces()),
token(')'), token(')'),
string("builtin") string("builtin")
.with(skip_many1(space())) .with(skip_many1(space()))
@ -209,7 +210,7 @@ where
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{ {
between( between(
token('('), token('(').skip(spaces()),
token(')'), token(')'),
string("error") string("error")
.with(skip_many1(space())) .with(skip_many1(space()))
@ -223,18 +224,22 @@ where
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{ {
between( between(
token('('), token('(').skip(spaces()),
token(')'), token(')'),
string("con") (
.with(skip_many1(space())) spaces(),
.with(choice(( string("con"),
skip_many1(space()),
choice((
attempt(constant_integer()), attempt(constant_integer()),
attempt(constant_bytestring()), attempt(constant_bytestring()),
attempt(constant_string()), attempt(constant_string()),
attempt(constant_unit()), attempt(constant_unit()),
attempt(constant_bool()), attempt(constant_bool()),
))) )),
.map(Term::Constant), spaces(),
)
.map(|(_, _, _, con, _)| Term::Constant(con)),
) )
} }
@ -301,13 +306,9 @@ where
{ {
look_ahead(letter()) look_ahead(letter())
.with(many1(alpha_num().or(token('_').or(token('\''))))) .with(many1(alpha_num().or(token('_').or(token('\'')))))
.map_input(|text: String, input: &mut StateStream<Input>| { .map_input(|text: String, input: &mut StateStream<Input>| Name {
println!("{:?}", text); unique: input.state.intern(&text),
text,
Name {
unique: input.state.intern(&text),
text,
}
}) })
} }