pub trait Parse<'a>: Sized {
// Required method
fn parse<I>(p: &mut Parser<'a, I>) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone;
// Provided method
fn try_parse<I>(p: &mut Parser<'a, I>) -> Result<Self>
where I: Iterator<Item = Cursor> + Clone { ... }
}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 implement Peek and Parse, where Parse::parse() calls Parser::next() and constructs from the cursor.
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
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)
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)
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)
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)
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)
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)
Source§impl<'a, A, B, C, D, E, F, G, H, I> Parse<'a> for (A, B, C, D, E, F, G, H, I)
impl<'a, A, B, C, D, E, F, G, H, I> Parse<'a> for (A, B, C, D, E, F, G, H, I)
Source§impl<'a, A, B, C, D, E, F, G, H> Parse<'a> for (A, B, C, D, E, F, G, H)
impl<'a, A, B, C, D, E, F, G, H> Parse<'a> for (A, B, C, D, E, F, G, H)
Source§impl<'a, A, B, C, D, E, F, G> Parse<'a> for (A, B, C, D, E, F, G)
impl<'a, A, B, C, D, E, F, G> Parse<'a> for (A, B, C, D, E, F, G)
Source§impl<'a, A, B, C, D, E, F> Parse<'a> for (A, B, C, D, E, F)
impl<'a, A, B, C, D, E, F> Parse<'a> for (A, B, C, D, E, F)
Source§impl<'a, A, B, C, D, E> Parse<'a> for (A, B, C, D, E)
impl<'a, A, B, C, D, E> Parse<'a> for (A, B, C, D, E)
Source§impl<'a, A, B, C, D> Parse<'a> for (A, B, C, D)
impl<'a, A, B, C, D> Parse<'a> for (A, B, C, D)
Implementors§
impl<'a, A, B, C, D, E> Parse<'a> for Optionals5<A, B, C, D, E>
impl<'a, A, B, C, D> Parse<'a> for Optionals4<A, B, C, D>
impl<'a, A, B, C> Parse<'a> for Optionals3<A, B, C>
impl<'a, A, B> Parse<'a> for Optionals2<A, B>
impl<'a, D, M> Parse<'a> for NoBlockAllowed<D, M>
impl<'a, D, M> Parse<'a> for UnknownRuleBlock<'a, D, M>
impl<'a, D, R, M> Parse<'a> for Block<'a, D, R, M>where
D: DeclarationValue<'a, M>,
R: Parse<'a> + NodeWithMetadata<M> + RuleVariants<'a, DeclarationValue = D, Metadata = M>,
M: NodeMetadata,
impl<'a, D, R, M> Parse<'a> for DeclarationRuleList<'a, D, R, M>where
D: DeclarationValue<'a, M>,
R: NodeWithMetadata<M> + Parse<'a>,
M: NodeMetadata,
Declaration<'a, D, M>: Parse<'a>,
impl<'a, Left: Parse<'a> + Peek<'a>, Right: Parse<'a>> Parse<'a> for Either<Left, Right>
impl<'a, P, D, R, M> Parse<'a> for QualifiedRule<'a, P, D, R, M>where
D: DeclarationValue<'a, M>,
P: Parse<'a>,
R: Parse<'a> + NodeWithMetadata<M> + RuleVariants<'a, DeclarationValue = D, Metadata = M>,
M: NodeMetadata,
A QualifiedRule represents a block with a prelude which may contain other rules. Examples of QualifiedRules are StyleRule, KeyframeRule (no s!).