Selaa lähdekoodia

Allow for newlines after then/else

David Peter 1 vuosi sitten
vanhempi
sitoutus
fcae1d2328
1 muutettua tiedostoa jossa 7 lisäystä ja 3 poistoa
  1. 7 3
      numbat/src/parser.rs

+ 7 - 3
numbat/src/parser.rs

@@ -895,7 +895,7 @@ impl<'a> Parser<'a> {
             let span_if = self.last().unwrap().span;
             let span_if = self.last().unwrap().span;
             let condition_expr = self.conversion()?;
             let condition_expr = self.conversion()?;
 
 
-            self.match_exact(TokenKind::Newline);
+            self.skip_empty_lines();
 
 
             if self.match_exact(TokenKind::Then).is_none() {
             if self.match_exact(TokenKind::Then).is_none() {
                 return Err(ParseError::new(
                 return Err(ParseError::new(
@@ -904,9 +904,11 @@ impl<'a> Parser<'a> {
                 ));
                 ));
             }
             }
 
 
+            self.skip_empty_lines();
+
             let then_expr = self.condition()?;
             let then_expr = self.condition()?;
 
 
-            self.match_exact(TokenKind::Newline);
+            self.skip_empty_lines();
 
 
             if self.match_exact(TokenKind::Else).is_none() {
             if self.match_exact(TokenKind::Else).is_none() {
                 return Err(ParseError::new(
                 return Err(ParseError::new(
@@ -915,6 +917,8 @@ impl<'a> Parser<'a> {
                 ));
                 ));
             }
             }
 
 
+            self.skip_empty_lines();
+
             let else_expr = self.condition()?;
             let else_expr = self.condition()?;
 
 
             Ok(Expression::Condition(
             Ok(Expression::Condition(
@@ -2747,7 +2751,7 @@ mod tests {
             &[
             &[
                 "if 1 < 2 then 3 + 4 else 5 * 6",
                 "if 1 < 2 then 3 + 4 else 5 * 6",
                 "if (1 < 2) then (3 + 4) else (5 * 6)",
                 "if (1 < 2) then (3 + 4) else (5 * 6)",
-                "if 1 < 2\n  then 3 + 4\n  else 5 * 6",
+                "if 1 < 2\n  then\n    3 + 4\n  else\n    5 * 6",
             ],
             ],
             conditional!(
             conditional!(
                 binop!(scalar!(1.0), LessThan, scalar!(2.0)),
                 binop!(scalar!(1.0), LessThan, scalar!(2.0)),