Enum Pattern

Source
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 ~~

Variants§

§

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

Implementations§

Source§

impl<T> Pattern<T>
where T: ToOwned<Owned = T> + ParserOutput,

Source

pub fn params(&self) -> Vec<(String, bool)>

Source

pub fn match_pattern<'a>( &self, output: Cow<'a, T>, next: Option<&Pattern<T>>, next2: Option<&Pattern<T>>, stream: &mut MacroStream, ) -> (Result<Match, MacrosError>, Cow<'a, T>)

Source

pub fn match_patterns<'b, 'a: 'b>( output: Cow<'a, T>, patterns: &'b [Pattern<T>], stream: &mut MacroStream, ) -> (Result<Match, MacrosError>, Cow<'a, T>)

Trait Implementations§

Source§

impl<T> Parse for Pattern<T>
where T: ToOwned<Owned = T> + ParserOutput,

Source§

fn parse(input: &mut MacroStream) -> Result<Self, MacrosError>

Source§

impl<T> Repr for Pattern<T>
where T: ToOwned<Owned = T> + ParserOutput,

Source§

fn repr(&self, name: &str) -> MacroStream

Source§

impl<T> Sync for Pattern<T>
where T: ToOwned<Owned = T> + ParserOutput,

Auto Trait Implementations§

§

impl<T> Freeze for Pattern<T>

§

impl<T> RefUnwindSafe for Pattern<T>

§

impl<T> !Send for Pattern<T>

§

impl<T> Unpin for Pattern<T>

§

impl<T> UnwindSafe for Pattern<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.