Trait Parse

Source
pub trait Parse<'a>: Sized {
    // Required method
    fn parse(p: &mut Parser<'a>) -> Result<Self>;

    // Provided method
    fn try_parse(p: &mut Parser<'a>) -> Result<Self> { ... }
}
Expand description

This trait allows AST nodes to construct themselves from a mutable Parser instance.

Nodes that implement this trait are entitled to consume any number of Cursors from Parser in order to construct themselves. They may also consume some amount of tokens and still return an Err - there is no need to try and reset the Parser state on failure (Parser::try_parse() exists for this reason).

When wanting to parse child nodes, implementations should not call Parse::parse() directly. Instead - call Parser::parse<T>(). Other convenience methods such as Parser::parse_if_peek<T>() and Parser::try_parse<T>() exist.

Any node implementing Parse::parse() gets Parse::try_parse() for free. It’s unlikely that nodes can come up with a more efficient algorithm than the provided one, so it is not worth re-implementing Parse::try_parse().

If a Node can construct itself from a single Cursor it should instead implement Peek and Build, which will provide Parse for free.

Required Methods§

Source

fn parse(p: &mut Parser<'a>) -> Result<Self>

Provided Methods§

Source

fn try_parse(p: &mut Parser<'a>) -> Result<Self>

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.

Implementations on Foreign Types§

Source§

impl<'a, A, B> Parse<'a> for (A, B)
where A: Parse<'a>, B: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C> Parse<'a> for (A, B, C)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D> Parse<'a> for (A, B, C, D)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E> Parse<'a> for (A, B, C, D, E)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F> Parse<'a> for (A, B, C, D, E, F)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F, G> Parse<'a> for (A, B, C, D, E, F, G)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>, G: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F, G, H> Parse<'a> for (A, B, C, D, E, F, G, H)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>, G: Parse<'a>, H: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F, G, H, I> Parse<'a> for (A, B, C, D, E, F, G, H, I)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>, G: Parse<'a>, H: Parse<'a>, I: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F, G, H, I, J> Parse<'a> for (A, B, C, D, E, F, G, H, I, J)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>, G: Parse<'a>, H: Parse<'a>, I: Parse<'a>, J: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F, G, H, I, J, K> Parse<'a> for (A, B, C, D, E, F, G, H, I, J, K)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>, G: Parse<'a>, H: Parse<'a>, I: Parse<'a>, J: Parse<'a>, K: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, A, B, C, D, E, F, G, H, I, J, K, L> Parse<'a> for (A, B, C, D, E, F, G, H, I, J, K, L)
where A: Parse<'a>, B: Parse<'a>, C: Parse<'a>, D: Parse<'a>, E: Parse<'a>, F: Parse<'a>, G: Parse<'a>, H: Parse<'a>, I: Parse<'a>, J: Parse<'a>, K: Parse<'a>, L: Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, T> Parse<'a> for Option<T>
where T: Peek<'a> + Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Source§

impl<'a, T> Parse<'a> for Vec<'a, T>
where T: Peek<'a> + Parse<'a>,

Source§

fn parse(p: &mut Parser<'a>) -> Result<Self>

Implementors§

Source§

impl<'a> Parse<'a> for Comparison

Source§

impl<'a> Parse<'a> for ComponentValue<'a>

Source§

impl<'a> Parse<'a> for BadDeclaration<'a>

Source§

impl<'a> Parse<'a> for BangImportant

Source§

impl<'a> Parse<'a> for ComponentValues<'a>

Source§

impl<'a> Parse<'a> for FunctionBlock<'a>

Source§

impl<'a> Parse<'a> for NoBlockAllowed

Source§

impl<'a> Parse<'a> for NoPreludeAllowed

Source§

impl<'a> Parse<'a> for SimpleBlock<'a>

Source§

impl<'a> Parse<'a> for CaretEqual

Source§

impl<'a> Parse<'a> for ColonColon

Source§

impl<'a> Parse<'a> for DollarEqual

Source§

impl<'a> Parse<'a> for EqualEqual

Source§

impl<'a> Parse<'a> for GreaterThanEqual

Source§

impl<'a> Parse<'a> for LessThanEqual

Source§

impl<'a> Parse<'a> for PipeEqual

Source§

impl<'a> Parse<'a> for PipePipe

Source§

impl<'a> Parse<'a> for StarEqual

Source§

impl<'a> Parse<'a> for StarPipe

Source§

impl<'a> Parse<'a> for TildeEqual

Source§

impl<'a> Parse<'a> for Whitespace

Source§

impl<'a, A, B> Parse<'a> for Optionals2<A, B>
where A: Parse<'a> + Peek<'a>, B: Parse<'a> + Peek<'a>,

Source§

impl<'a, A, B, C> Parse<'a> for Optionals3<A, B, C>
where A: Parse<'a> + Peek<'a>, B: Parse<'a> + Peek<'a>, C: Parse<'a> + Peek<'a>,

Source§

impl<'a, A, B, C, D> Parse<'a> for Optionals4<A, B, C, D>
where A: Parse<'a> + Peek<'a>, B: Parse<'a> + Peek<'a>, C: Parse<'a> + Peek<'a>, D: Parse<'a> + Peek<'a>,

Source§

impl<'a, A, B, C, D, E> Parse<'a> for Optionals5<A, B, C, D, E>
where A: Parse<'a> + Peek<'a>, B: Parse<'a> + Peek<'a>, C: Parse<'a> + Peek<'a>, D: Parse<'a> + Peek<'a>, E: Parse<'a> + Peek<'a>,

Source§

impl<'a, AT, P, B> Parse<'a> for AtRule<AT, P, B>
where AT: Parse<'a> + Into<AtKeyword>, P: Parse<'a>, B: Parse<'a>,

Source§

impl<'a, D, R> Parse<'a> for Block<'a, D, R>
where D: DeclarationValue<'a>, R: Parse<'a>,

Source§

impl<'a, D, R> Parse<'a> for DeclarationRuleList<'a, D, R>
where D: DeclarationValue<'a>, R: Parse<'a>, Declaration<'a, D>: Parse<'a>,

Source§

impl<'a, FT, T> Parse<'a> for Function<FT, T>
where FT: Parse<'a> + Into<Function>, T: Parse<'a>,

Source§

impl<'a, P, D, R> Parse<'a> for QualifiedRule<'a, P, D, R>
where D: DeclarationValue<'a>, P: Parse<'a>, R: Parse<'a>,

A QualifiedRule represents a block with a prelude which may contain other rules. Examples of QualifiedRules are StyleRule, KeyframeRule (no s!).

Source§

impl<'a, R: Parse<'a>> Parse<'a> for RuleList<'a, R>

Source§

impl<'a, T> Parse<'a> for T
where T: Peek<'a> + Build<'a>,

Source§

impl<'a, T: Parse<'a> + Peek<'a>, const MIN: usize> Parse<'a> for CommaSeparated<'a, T, MIN>

Source§

impl<'a, V: DeclarationValue<'a>> Parse<'a> for Declaration<'a, V>

Source§

impl<'a, V: DeclarationValue<'a>> Parse<'a> for DeclarationList<'a, V>