Fix problem with parsing commas

I should probably rethink how delimited block expressions like if-blocks
(and eventually for-blocks) work
This commit is contained in:
greg 2018-11-05 13:07:08 -08:00
parent c394b81746
commit 1bd48ed5db
2 changed files with 18 additions and 11 deletions

View File

@ -677,7 +677,7 @@ if (1, 5) {
}
#[test]
fn need_to_fix_parser_to_make_work() {
fn tuple_pattern_4() {
let source = r#"
if (1, 5) {
is (10, x) -> x,

View File

@ -749,19 +749,26 @@ impl Parser {
//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
RCurlyBrace | EOF => break,
Semicolon | Newline => { self.next(); continue},
_ => {
let guard_arm = self.guard_arm()?;
guards.push(guard_arm);
loop {
match self.peek() {
Semicolon | Newline => { self.next(); continue; },
_ => break,
}
}
if let RCurlyBrace = self.peek() {
break;
}
expect!(self, Comma);
}
}
}
expect!(self, RCurlyBrace);