oxc_css_parser/parser/at_rule/
layer.rs1use super::Parser;
2use crate::{
3 Parse, arena_vec,
4 ast::*,
5 bump, eat,
6 error::{Error, PResult},
7 peek,
8 pos::{Span, Spanned},
9 tokenizer::{Token, TokenWithSpan},
10 util,
11};
12
13impl<'a> Parse<'a> for LayerNames<'a> {
15 fn parse(input: &mut Parser<'a>) -> PResult<Self> {
16 let first = input.parse::<LayerName>()?;
17 let mut span = first.span.clone();
18
19 let mut names = arena_vec!(input; first);
20 let mut comma_spans = arena_vec!(input);
21 while let Some((_, comma_span)) = eat!(input, Comma) {
22 comma_spans.push(comma_span);
23 names.push(input.parse()?);
24 }
25
26 if let Some(last) = names.last() {
27 span.end = last.span.end;
28 }
29 Ok(LayerNames { names, comma_spans, span })
30 }
31}
32
33impl<'a> Parse<'a> for LayerName<'a> {
35 fn parse(input: &mut Parser<'a>) -> PResult<Self> {
36 let first = input.parse::<InterpolableIdent>()?;
37 let start = first.span().start;
38 let mut end = first.span().end;
39
40 let mut idents = arena_vec!(input; first);
41 while let TokenWithSpan { token: Token::Dot(..), span } = peek!(input) {
42 if span.start == end {
43 let span = bump!(input).span;
44 let ident = input.parse::<InterpolableIdent>()?;
45 util::assert_no_ws_or_comment(&span, ident.span())?;
46 end = ident.span().end;
47 idents.push(ident);
48 } else {
49 break;
50 }
51 }
52
53 let invalid_ident = idents.iter().find(|ident| match &ident {
54 InterpolableIdent::Literal(ident) => util::is_css_wide_keyword(ident.name),
55 _ => false,
56 });
57 if let Some(invalid_ident) = invalid_ident {
58 input.recoverable_errors.push(Error {
59 kind: crate::error::ErrorKind::CSSWideKeywordDisallowed,
60 span: invalid_ident.span().clone(),
61 });
62 }
63
64 let span = Span { start, end };
65 Ok(LayerName { idents, span })
66 }
67}