瀏覽代碼

Allow newlines in function parameters

David Peter 2 年之前
父節點
當前提交
ef314b2e39
共有 2 個文件被更改,包括 12 次插入4 次删除
  1. 5 1
      examples/thermal_conductivity.nbt
  2. 7 3
      numbat/src/parser.rs

+ 5 - 1
examples/thermal_conductivity.nbt

@@ -2,7 +2,11 @@
 
 dimension ThermalConductivity = Power / (Length × Temperature)
 
-fn heat_transfer(λ: ThermalConductivity, wall_area: Area, thickness: Length, temp_hot: Temperature, temp_cold: Temperature) -> Power =
+fn heat_transfer(λ: ThermalConductivity,
+                 wall_area: Area,
+                 thickness: Length,
+                 temp_hot: Temperature,
+                 temp_cold: Temperature) -> Power =
     λ × wall_area × (temp_hot - temp_cold) / thickness
 
 let λ_concrete: ThermalConductivity = 0.92 W / (m · K)

+ 7 - 3
numbat/src/parser.rs

@@ -370,9 +370,13 @@ impl<'a> Parser<'a> {
 
                         parameter_span = parameter_span.extend(&self.last().unwrap().span);
 
-                        if self.match_exact(TokenKind::Comma).is_none()
-                            && self.peek().kind != TokenKind::RightParen
-                        {
+                        let mut has_comma = || -> bool {
+                            let yes = self.match_exact(TokenKind::Comma).is_some();
+                            self.match_exact(TokenKind::Newline);
+                            yes
+                        };
+
+                        if !has_comma() && self.peek().kind != TokenKind::RightParen {
                             return Err(ParseError {
                                 kind: ParseErrorKind::ExpectedCommaEllipsisOrRightParenInFunctionDefinition,
                                 span: self.peek().span,