pub enum Pattern<T>where
T: ToOwned<Owned = T> + ParserOutput,{
Optional(Vec<Pattern<T>>),
Parameter(Vec<Pattern<T>>, String),
ZeroOrMore(Vec<Pattern<T>>, bool),
OneOrMore(Vec<Pattern<T>>, bool),
Choice(Vec<Vec<Pattern<T>>>),
Token(Token),
Group(Delimiter, Vec<Pattern<T>>),
Any,
Validator(Option<MacroStream>, Option<for<'a> fn(Cow<'a, T>, &Match) -> (Result<(), String>, Cow<'a, T>)>),
}
Expand description
A pattern to match against a MacroStream
in a parser from the parser!
macro.
The following are the various patterns that can be used:
{…}? indicates that the pattern is optional
{… :name}@ indicates that the match should be bound to the parameter name
{…}* indicates zero or more (non-greedy), meaning it will consume the stream until the next pattern matches
{…}** indicates zero or more (greedy), meaning it will consume the remainder of the stream
{…}+ indicates one or more (non-greedy), meaning it will consume the stream until the next pattern matches
{…}++ indicates one or more (greedy), meaning it will consume the remainder of the stream
{… | … | …}& indicates a choice
… indicates a token to match exactly
{}$ indicates an arbitrary token, if used in a zero or more or one or more then it will consume the stream until the next pattern matches
{…}= indicates a validation function, should be anything of type type for<'a> fn(Cow<'a, T>, &Match) -> (Result<(), String>, Cow<'a, T>)
as it will be interpolated directly into the code expecting that type
{{…}} escapes the {} grouping
To escape any of the special endings, use ~whatever before the ending, to escape the tilde use ~~