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

Function visit_array

libs/@local/hashql/syntax-jexpr/src/parser/array/visit.rs:36–119  ·  view source on GitHub ↗
(
    state: &mut ParserState<'arena, 'source, 'spans>,
    token: Token<'source>,
    mut on_item: impl FnMut(
        &mut ParserState<'arena, 'source, 'spans>,
    ) -> Result<(), Diagnostic<C, Spa

Source from the content-addressed store, hash-verified

34 specific token. Not that we hold it temporary, but instead that we consume it."
35)]
36pub(crate) fn visit_array<'arena, 'source, 'spans, C>(
37 state: &mut ParserState<'arena, 'source, 'spans>,
38 token: Token<'source>,
39 mut on_item: impl FnMut(
40 &mut ParserState<'arena, 'source, 'spans>,
41 ) -> Result<(), Diagnostic<C, SpanId, Critical>>,
42) -> Result<TextRange, Diagnostic<C, SpanId, Critical>>
43where
44 C: From<ArrayDiagnosticCategory>,
45{
46 debug_assert_eq!(token.kind.syntax(), SyntaxKind::LBracket);
47
48 let mut span = token.span;
49 let mut index: usize = 0;
50
51 loop {
52 let next = state
53 .peek_expect(SyntaxKindSet::COMPLETE)
54 .change_category(ArrayDiagnosticCategory::Lexer)
55 .change_category(C::from)?;
56
57 let (next_kind, next_span) = (next.kind.syntax(), next.span);
58
59 if next_kind == SyntaxKind::RBracket {
60 state
61 .advance(SyntaxKindSet::COMPLETE)
62 .change_category(ArrayDiagnosticCategory::Lexer)
63 .change_category(C::from)?;
64
65 span = span.cover(next_span);
66 break;
67 }
68
69 if index == 0 {
70 verify_no_repeat(
71 state,
72 SyntaxKindSet::from_slice(&[SyntaxKind::Comma]),
73 SyntaxKindSet::EMPTY,
74 |_, spans, _| leading_commas(&spans),
75 )
76 .change_category(C::from)?;
77 } else {
78 // we need to check if the next token is a comma
79 // in case it isn't we error out
80 if next_kind == SyntaxKind::Comma {
81 // advance the cursor to the next token and continue as it nothing has happened
82 state
83 .advance(SyntaxKindSet::COMPLETE)
84 .change_category(ArrayDiagnosticCategory::Lexer)
85 .change_category(C::from)?;
86
87 verify_no_repeat(
88 state,
89 SyntaxKindSet::from_slice(&[SyntaxKind::Comma]),
90 SyntaxKindSet::from_slice(&[SyntaxKind::RBracket]),
91 |state, mut spans, verify| match verify {
92 VerifyState::Trailing => {
93 // if trailing comma is found, then the first comma is also affected

Callers 15

empty_arrayFunction · 0.85
single_item_arrayFunction · 0.85
multiple_item_arrayFunction · 0.85
trailing_commaFunction · 0.85
missing_commaFunction · 0.85
error_in_callbackFunction · 0.85
unclosed_arrayFunction · 0.85
array_with_whitespaceFunction · 0.85
nested_arraysFunction · 0.85
process_nested_arrayFunction · 0.85

Calls 15

verify_no_repeatFunction · 0.85
ErrInterface · 0.85
unexpected_tokenFunction · 0.85
OkInterface · 0.85
change_categoryMethod · 0.80
peek_expectMethod · 0.80
syntaxMethod · 0.80
coverMethod · 0.80
insert_spanMethod · 0.80
current_pointerMethod · 0.80
leading_commasFunction · 0.70
trailing_commasFunction · 0.70

Tested by 15

empty_arrayFunction · 0.68
single_item_arrayFunction · 0.68
multiple_item_arrayFunction · 0.68
trailing_commaFunction · 0.68
missing_commaFunction · 0.68
error_in_callbackFunction · 0.68
unclosed_arrayFunction · 0.68
array_with_whitespaceFunction · 0.68
nested_arraysFunction · 0.68
deep_nestingFunction · 0.68