Trait AtRuleParser

Source
pub trait AtRuleParser<'i>: Sized {
    type Prelude;
    type AtRule;
    type Error: 'i;

    // Provided methods
    fn parse_prelude<'t>(
        &mut self,
        name: CowRcStr<'i>,
        input: &mut Parser<'i, 't>,
        options: &ParserOptions<'_, 'i>,
    ) -> Result<Self::Prelude, ParseError<'i, Self::Error>> { ... }
    fn rule_without_block(
        &mut self,
        prelude: Self::Prelude,
        start: &ParserState,
        options: &ParserOptions<'_, 'i>,
        is_nested: bool,
    ) -> Result<Self::AtRule, ()> { ... }
    fn parse_block<'t>(
        &mut self,
        prelude: Self::Prelude,
        start: &ParserState,
        input: &mut Parser<'i, 't>,
        options: &ParserOptions<'_, 'i>,
        is_nested: bool,
    ) -> Result<Self::AtRule, ParseError<'i, Self::Error>> { ... }
}
Expand description

A trait to provide parsing of custom 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 declarations list with only qualified rules.

Note: this trait is copied from cssparser and modified to provide parser options.

Required Associated Types§

Source

type Prelude

The intermediate representation of prelude of an at-rule.

Source

type AtRule

The finished representation of an at-rule.

Source

type Error: 'i

The error type that is included in the ParseError value that can be returned.

Provided Methods§

Source

fn parse_prelude<'t>( &mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>, options: &ParserOptions<'_, 'i>, ) -> Result<Self::Prelude, 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.

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.)

Source

fn rule_without_block( &mut self, prelude: Self::Prelude, start: &ParserState, options: &ParserOptions<'_, 'i>, is_nested: bool, ) -> Result<Self::AtRule, ()>

End an at-rule which doesn’t have block. Return the finished representation of the at-rule.

The location passed in is source location of the start of the prelude. is_nested indicates whether the rule is nested inside a style rule.

This is only called when either the ; semicolon indeed follows the prelude, or parser is at the end of the input.

Source

fn parse_block<'t>( &mut self, prelude: Self::Prelude, start: &ParserState, input: &mut Parser<'i, 't>, options: &ParserOptions<'_, 'i>, is_nested: bool, ) -> Result<Self::AtRule, ParseError<'i, Self::Error>>

Parse the content of a { /* ... */ } block for the body of the at-rule.

The location passed in is source location of the start of the prelude. is_nested indicates whether the rule is nested inside a style 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 a block was found following the prelude.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§