forked from katzen-cafe/iowo
37 lines
1 KiB
Rust
37 lines
1 KiB
Rust
|
use crate::{syntax_error::SyntaxError, syntax_kind::SyntaxKind};
|
||
|
|
||
|
use super::{value, CompletedMarker, Parser};
|
||
|
|
||
|
pub(super) fn array(p: &mut Parser) -> Option<CompletedMarker> {
|
||
|
let array_start = p.start("array");
|
||
|
|
||
|
if !p.eat(SyntaxKind::BRACKET_OPEN) {
|
||
|
array_start.abandon(p);
|
||
|
return None;
|
||
|
}
|
||
|
|
||
|
let el = p.start("arr_el");
|
||
|
value(p);
|
||
|
el.complete(p, SyntaxKind::ELEMENT);
|
||
|
|
||
|
while p.at(SyntaxKind::COMMA) {
|
||
|
let potential_trailing_comma = p.start("potential_trailing_comma");
|
||
|
|
||
|
p.eat(SyntaxKind::COMMA);
|
||
|
let maybe_el = p.start("arr_el");
|
||
|
if !value(p) {
|
||
|
maybe_el.abandon(p);
|
||
|
potential_trailing_comma.complete(p, SyntaxKind::TRAILING_COMMA);
|
||
|
} else {
|
||
|
maybe_el.complete(p, SyntaxKind::ELEMENT);
|
||
|
potential_trailing_comma.abandon(p);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Some(if !p.eat(SyntaxKind::BRACKET_CLOSE) {
|
||
|
array_start.error(p, SyntaxError::UnclosedArray)
|
||
|
} else {
|
||
|
array_start.complete(p, SyntaxKind::ARRAY)
|
||
|
})
|
||
|
}
|