(
state: &mut ParserState<'heap, 'source, '_>,
token: Token<'source>,
)
| 186 | } |
| 187 | |
| 188 | pub(crate) fn parse_array<'heap, 'source>( |
| 189 | state: &mut ParserState<'heap, 'source, '_>, |
| 190 | token: Token<'source>, |
| 191 | ) -> Result<Expr<'heap>, ParserDiagnostic> { |
| 192 | debug_assert_eq!(token.kind.syntax(), SyntaxKind::LBracket); |
| 193 | |
| 194 | let mut function = None; |
| 195 | let mut arguments = Vec::new(); |
| 196 | let mut labeled_arguments = Vec::new(); |
| 197 | |
| 198 | let span = visit_array(state, token, |state| { |
| 199 | match &mut function { |
| 200 | Some(_) => { |
| 201 | if let Some(labeled) = parse_labelled_argument(state)? { |
| 202 | labeled_arguments.extend(labeled); |
| 203 | return Ok(()); |
| 204 | } |
| 205 | |
| 206 | let expr = parse_expr(state)?; |
| 207 | |
| 208 | arguments.push(Argument { |
| 209 | id: NodeId::PLACEHOLDER, |
| 210 | span: expr.span, |
| 211 | value: Box::new_in(expr, state.heap()), |
| 212 | }); |
| 213 | } |
| 214 | function @ None => *function = Some(parse_expr(state)?), |
| 215 | } |
| 216 | |
| 217 | Ok(()) |
| 218 | }) |
| 219 | .change_category(From::from)?; |
| 220 | |
| 221 | let span = state.insert_span(Span { |
| 222 | range: span, |
| 223 | pointer: Some(state.current_pointer()), |
| 224 | }); |
| 225 | |
| 226 | let Some(function) = function else { |
| 227 | return Err(empty(span).map_category(From::from)); |
| 228 | }; |
| 229 | |
| 230 | let heap = state.heap(); |
| 231 | |
| 232 | Ok(Expr { |
| 233 | id: NodeId::PLACEHOLDER, |
| 234 | span, |
| 235 | kind: ExprKind::Call(CallExpr { |
| 236 | id: NodeId::PLACEHOLDER, |
| 237 | span, |
| 238 | function: Box::new_in(function, heap), |
| 239 | arguments: arguments.into_iter().collect_in(heap), |
| 240 | labeled_arguments: labeled_arguments.into_iter().collect_in(heap), |
| 241 | }), |
| 242 | }) |
| 243 | } |
| 244 | |
| 245 | #[cfg(test)] |
no test coverage detected