use crate::{Cursor, Kind, NodeMetadata, NodeWithMetadata, Parse, Parser, Result, T};
use bumpalo::collections::Vec;
pub trait StyleSheet<'a, M: NodeMetadata>: Sized + Parse<'a> {
type Rule: Parse<'a> + NodeWithMetadata<M>;
fn parse_stylesheet<I>(p: &mut Parser<'a, I>) -> Result<(Vec<'a, Self::Rule>, M)>
where
I: Iterator<Item = Cursor> + Clone,
{
let mut rules: Vec<'a, Self::Rule> = Vec::new_in(p.bump());
let mut meta: M = Default::default();
loop {
if p.parse_if_peek::<T![' ']>()?.is_some() || p.parse_if_peek::<T![CdcOrCdo]>()?.is_some() {
continue;
}
if p.at_end() || p.peek_n(1) == Kind::Eof {
return Ok((rules, meta));
}
let rule = p.parse::<Self::Rule>()?;
meta = meta.merge(rule.metadata());
rules.push(rule);
}
}
}