Fix if-block parsing to handle newlines
This commit is contained in:
parent
baf51fb147
commit
de0e150536
@ -535,7 +535,10 @@ if a { is 15 -> "x", is 10 -> "y" }
|
|||||||
fn boolean_pattern() {
|
fn boolean_pattern() {
|
||||||
let source = r#"
|
let source = r#"
|
||||||
let a = true
|
let a = true
|
||||||
if a { is true -> "x", is false -> "y" }
|
if a {
|
||||||
|
is true -> "x",
|
||||||
|
is false -> "y"
|
||||||
|
}
|
||||||
"#;
|
"#;
|
||||||
test_in_fresh_env!(source, "\"x\"");
|
test_in_fresh_env!(source, "\"x\"");
|
||||||
}
|
}
|
||||||
|
@ -694,7 +694,25 @@ impl Parser {
|
|||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(guard_block(&mut self) -> ParseResult<IfExpressionBody> {
|
parse_method!(guard_block(&mut self) -> ParseResult<IfExpressionBody> {
|
||||||
let guards = delimited!(self, LCurlyBrace, guard_arm, Comma, RCurlyBrace);
|
//TODO - delimited! isn't sophisticated enough to do thisa
|
||||||
|
//let guards = delimited!(self, LCurlyBrace, guard_arm, Comma, RCurlyBrace);
|
||||||
|
expect!(self, LCurlyBrace);
|
||||||
|
let mut guards = vec![];
|
||||||
|
loop {
|
||||||
|
while let Newline = self.peek() {
|
||||||
|
self.next();
|
||||||
|
}
|
||||||
|
let guard_arm = self.guard_arm()?;
|
||||||
|
guards.push(guard_arm);
|
||||||
|
while let Newline = self.peek() {
|
||||||
|
self.next();
|
||||||
|
}
|
||||||
|
match self.peek() {
|
||||||
|
Comma => {self.next(); continue },
|
||||||
|
_ => break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect!(self, RCurlyBrace);
|
||||||
Ok(IfExpressionBody::GuardList(guards))
|
Ok(IfExpressionBody::GuardList(guards))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user