| 34 | specific token. Not that we hold it temporary, but instead that we consume it." |
| 35 | )] |
| 36 | pub(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>> |
| 43 | where |
| 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 |