oxc_css_parser/parser/at_rule/
document.rs1use super::Parser;
2use crate::{Parse, Spanned, arena_vec, ast::*, eat, error::PResult};
3
4impl<'a> Parse<'a> for DocumentPrelude<'a> {
6 fn parse(input: &mut Parser<'a>) -> PResult<Self> {
7 let first = input.parse::<DocumentPreludeMatcher>()?;
8 let mut span = first.span().clone();
9
10 let mut matchers = arena_vec!(input; first);
11 let mut comma_spans = arena_vec!(input);
12 while let Some((_, comma_span)) = eat!(input, Comma) {
13 comma_spans.push(comma_span);
14 matchers.push(input.parse()?);
15 }
16 debug_assert_eq!(comma_spans.len() + 1, matchers.len());
17
18 if let Some(last) = matchers.last() {
19 span.end = last.span().end;
20 }
21 Ok(DocumentPrelude { matchers, comma_spans, span })
22 }
23}
24
25impl<'a> Parse<'a> for DocumentPreludeMatcher<'a> {
26 fn parse(input: &mut Parser<'a>) -> PResult<Self> {
27 if let Ok(url) = input.try_parse(Url::parse) {
28 Ok(DocumentPreludeMatcher::Url(url))
29 } else {
30 input.parse().map(DocumentPreludeMatcher::Function)
31 }
32 }
33}