Enum macros_core::Pattern

source ·
pub enum Pattern<T>where
    T: ToOwned<Owned = T> + ParserOutput,{
    Optional(Vec<Pattern<T>, Global>),
    Parameter(Vec<Pattern<T>, Global>, String),
    ZeroOrMore(Vec<Pattern<T>, Global>, bool),
    OneOrMore(Vec<Pattern<T>, Global>, bool),
    Choice(Vec<Vec<Pattern<T>, Global>, Global>),
    Token(Token),
    Group(Delimiter, Vec<Pattern<T>, Global>),
    Any,
    Validator(Option<MacroStream>, Option<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>, Global>)

§

Parameter(Vec<Pattern<T>, Global>, String)

§

ZeroOrMore(Vec<Pattern<T>, Global>, bool)

§

OneOrMore(Vec<Pattern<T>, Global>, bool)

§

Choice(Vec<Vec<Pattern<T>, Global>, Global>)

§

Token(Token)

§

Group(Delimiter, Vec<Pattern<T>, Global>)

§

Any

§

Validator(Option<MacroStream>, Option<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), Global>

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>( output: Cow<'a, T>, patterns: &'b [Pattern<T>], stream: &mut MacroStream ) -> (Result<Match, MacrosError>, Cow<'a, T>)where 'a: 'b,

Trait Implementations§

source§

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

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> 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.