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

Function parse_list

libs/@local/hashql/syntax-jexpr/src/parser/object/list.rs:75–113  ·  view source on GitHub ↗
(
    state: &mut ParserState<'heap, '_, '_>,
)

Source from the content-addressed store, hash-verified

73}
74
75fn parse_list<'heap>(
76 state: &mut ParserState<'heap, '_, '_>,
77) -> Result<ListExpr<'heap>, ParserDiagnostic> {
78 // We do not use the `expected` of advance here, so that we're able to give the user a better
79 // error message.
80 let token = state
81 .advance(Expected::hint(SyntaxKind::LBracket))
82 .change_category(From::from)?;
83
84 if token.kind.syntax() != SyntaxKind::LBracket {
85 return Err(
86 list_expected_array(state.insert_range(token.span), token.kind.syntax())
87 .map_category(From::from),
88 );
89 }
90
91 let mut elements = Vec::new();
92
93 let range = visit_array(state, token, |state| {
94 let expr = parse_expr(state)?;
95
96 let element = ListElement {
97 id: NodeId::PLACEHOLDER,
98 span: expr.span,
99 value: Box::new_in(expr, state.heap()),
100 };
101
102 elements.push(element);
103
104 Ok(())
105 })?;
106
107 Ok(ListExpr {
108 id: NodeId::PLACEHOLDER,
109 span: state.insert_range(range),
110 elements: elements.into_iter().collect_in(state.heap()),
111 r#type: None,
112 })
113}
114
115#[cfg(test)]
116mod tests {

Callers 1

parseMethod · 0.85

Calls 14

ErrInterface · 0.85
list_expected_arrayFunction · 0.85
visit_arrayFunction · 0.85
OkInterface · 0.85
change_categoryMethod · 0.80
syntaxMethod · 0.80
heapMethod · 0.80
collect_inMethod · 0.80
pushMethod · 0.65
parse_exprFunction · 0.50
advanceMethod · 0.45
map_categoryMethod · 0.45

Tested by

no test coverage detected