Parse a constructor
(&mut self)
| 187 | |
| 188 | /// Parse a constructor |
| 189 | fn parse_constructor(&mut self) -> crate::Result<Constructor> { |
| 190 | let name = self.parse_ident()?; |
| 191 | let params = self.parse_params()?; |
| 192 | |
| 193 | let type_ = if self.check(&TokenKind::Colon) { |
| 194 | self.advance(); |
| 195 | Some(Box::new(self.parse_expr()?)) |
| 196 | } else { |
| 197 | None |
| 198 | }; |
| 199 | |
| 200 | let end = type_.as_ref().map(|t| t.span()).unwrap_or(name.span); |
| 201 | |
| 202 | Ok(Constructor { |
| 203 | span: name.span.to(end), |
| 204 | name, |
| 205 | params, |
| 206 | type_, |
| 207 | }) |
| 208 | } |
| 209 | |
| 210 | /// Parse structure declaration |
| 211 | fn parse_structure(&mut self) -> crate::Result<StructureDecl> { |
no test coverage detected