Trait cssparser::AtRuleParser
[−]
[src]
pub trait AtRuleParser<'i> { type PreludeNoBlock; type PreludeBlock; type AtRule; type Error: 'i; fn parse_prelude<'t>(
&mut self,
name: CowRcStr<'i>,
input: &mut Parser<'i, 't>
) -> Result<AtRuleType<Self::PreludeNoBlock, Self::PreludeBlock>, ParseError<'i, Self::Error>> { ... } fn rule_without_block(
&mut self,
prelude: Self::PreludeNoBlock
) -> Self::AtRule { ... } fn parse_block<'t>(
&mut self,
prelude: Self::PreludeBlock,
input: &mut Parser<'i, 't>
) -> Result<Self::AtRule, ParseError<'i, Self::Error>> { ... } }
A trait to provide various parsing of at-rules.
For example, there could be different implementations for top-level at-rules
(@media
, @font-face
, …)
and for page-margin rules inside @page
.
Default implementations that reject all at-rules are provided,
so that impl AtRuleParser<(), ()> for ... {}
can be used
for using DeclarationListParser
to parse a declartions list with only qualified rules.
Associated Types
type PreludeNoBlock
The intermediate representation of prelude of an at-rule without block;
type PreludeBlock
The intermediate representation of prelude of an at-rule with block;
type AtRule
The finished representation of an at-rule.
type Error: 'i
The error type that is included in the ParseError value that can be returned.
Provided Methods
fn parse_prelude<'t>(
&mut self,
name: CowRcStr<'i>,
input: &mut Parser<'i, 't>
) -> Result<AtRuleType<Self::PreludeNoBlock, Self::PreludeBlock>, ParseError<'i, Self::Error>>
&mut self,
name: CowRcStr<'i>,
input: &mut Parser<'i, 't>
) -> Result<AtRuleType<Self::PreludeNoBlock, Self::PreludeBlock>, ParseError<'i, Self::Error>>
Parse the prelude of an at-rule with the given name
.
Return the representation of the prelude and the type of at-rule,
or Err(())
to ignore the entire at-rule as invalid.
See AtRuleType
’s documentation for the return value.
The prelude is the part after the at-keyword
and before the ;
semicolon or { /* ... */ }
block.
At-rule name matching should be case-insensitive in the ASCII range.
This can be done with std::ascii::Ascii::eq_ignore_ascii_case
,
or with the match_ignore_ascii_case!
macro.
The given input
is a "delimited" parser
that ends wherever the prelude should end.
(Before the next semicolon, the next {
, or the end of the current block.)
fn rule_without_block(&mut self, prelude: Self::PreludeNoBlock) -> Self::AtRule
End an at-rule which doesn't have block. Return the finished representation of the at-rule.
This is only called when parse_prelude
returned WithoutBlock
, and
either the ;
semicolon indeed follows the prelude, or parser is at
the end of the input.
fn parse_block<'t>(
&mut self,
prelude: Self::PreludeBlock,
input: &mut Parser<'i, 't>
) -> Result<Self::AtRule, ParseError<'i, Self::Error>>
&mut self,
prelude: Self::PreludeBlock,
input: &mut Parser<'i, 't>
) -> Result<Self::AtRule, ParseError<'i, Self::Error>>
Parse the content of a { /* ... */ }
block for the body of the at-rule.
Return the finished representation of the at-rule
as returned by RuleListParser::next
or DeclarationListParser::next
,
or Err(())
to ignore the entire at-rule as invalid.
This is only called when parse_prelude
returned WithBlock
, and a block
was indeed found following the prelude.