MCPcopy Create free account
hub / github.com/hashintel/hash / parse_array

Function parse_array

libs/@local/hashql/syntax-jexpr/src/parser/array/mod.rs:188–243  ·  view source on GitHub ↗
(
    state: &mut ParserState<'heap, 'source, '_>,
    token: Token<'source>,
)

Source from the content-addressed store, hash-verified

186}
187
188pub(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)]

Callers 1

parse_exprFunction · 0.85

Calls 15

visit_arrayFunction · 0.85
parse_labelled_argumentFunction · 0.85
OkInterface · 0.85
ErrInterface · 0.85
change_categoryMethod · 0.80
heapMethod · 0.80
insert_spanMethod · 0.80
current_pointerMethod · 0.80
collect_inMethod · 0.80
emptyFunction · 0.70
pushMethod · 0.65
parse_exprFunction · 0.50

Tested by

no test coverage detected