Skip to main content

Pattern

Enum Pattern 

Source
pub enum Pattern<'s> {
Show 14 variants Grouping(TokenRef<'s>, Box<Pattern<'s>>, TokenRef<'s>), Literal(Option<TokenRef<'s>>, TokenRef<'s>), Constant(TokenRef<'s>), Relation(TokenRef<'s>, Box<Pattern<'s>>), Range(Box<Pattern<'s>>, TokenRef<'s>, Box<Pattern<'s>>), Discard(TokenRef<'s>), Bind(Option<TokenRef<'s>>, TokenRef<'s>), Record(TokenRef<'s>, Vec<RecordPattern<'s>>, TokenRef<'s>), Array(TokenRef<'s>, Vec<ArrayPattern<'s>>, TokenRef<'s>), SpreadDiscard(usize), And(Box<Pattern<'s>>, TokenRef<'s>, Box<Pattern<'s>>), Or(Box<Pattern<'s>>, TokenRef<'s>, Box<Pattern<'s>>), Not(TokenRef<'s>, Box<Pattern<'s>>), Unknown { recovered: Option<Box<Pattern<'s>>>, tokens: Vec<TokenRef<'s>>, errors: Vec<SourceDiagnostic>, },
}

Variants§

§

Grouping(TokenRef<'s>, Box<Pattern<'s>>, TokenRef<'s>)

( pattern )

Grouping pattern.

§

Literal(Option<TokenRef<'s>>, TokenRef<'s>)

( + | - )? literal

Matches against a literal value.

§

Constant(TokenRef<'s>)

constant

Matches against a constant value.

§

Relation(TokenRef<'s>, Box<Pattern<'s>>)

( > | >= | <= | < | == | != | =~ | !~ ) (pattern_constant | pattern_literal)

Matches against a relation with constant values.

§

Range(Box<Pattern<'s>>, TokenRef<'s>, Box<Pattern<'s>>)

(pattern_constant | pattern_literal) ( .. | ..< ) (pattern_constant | pattern_literal)

Matches against a range of constant values.

§

Discard(TokenRef<'s>)

_

Matches and discards a value.

§

Bind(Option<TokenRef<'s>>, TokenRef<'s>)

mut? identifier

Matches and binds a value to a variable.

§

Record(TokenRef<'s>, Vec<RecordPattern<'s>>, TokenRef<'s>)

pattern_record
    : '(' sub_pattern* ')'
    ;
sub_pattern
    : name colon pattern ','?
    | colon pattern_bind ','?
    | pattern ','?
    | '..' pattern ','?
    ;
colon
    : ':'
    | '?:'
    ;

Matches a record pattern.

§

Array(TokenRef<'s>, Vec<ArrayPattern<'s>>, TokenRef<'s>)

pattern_array
    : '[' sub_pattern* ']'
    ;
sub_pattern
    : pattern ','?
    | '..' pattern? ','?
    ;
§

SpreadDiscard(usize)

prefix<..>

Contains no token. Used in ArrayPattern::Spread and RecordPattern::Spread as a placeholder since _ must be omitted in these cases.

The value is the position of the spread discard in the pattern. Used in the [AstWalker::range] method

§

And(Box<Pattern<'s>>, TokenRef<'s>, Box<Pattern<'s>>)

pattern and pattern

Matches all of the patterns.

§

Or(Box<Pattern<'s>>, TokenRef<'s>, Box<Pattern<'s>>)

pattern or pattern

Matches any of the patterns.

§

Not(TokenRef<'s>, Box<Pattern<'s>>)

not pattern

Matches if the pattern does not match.

§

Unknown

Unknown pattern.

Fields

§recovered: Option<Box<Pattern<'s>>>
§tokens: Vec<TokenRef<'s>>

Implementations§

Source§

impl<'s> Pattern<'s>

Source

pub const fn is_grouping(&self) -> bool

Returns true if the enum is Pattern::Grouping otherwise false

Source

pub const fn is_literal(&self) -> bool

Returns true if the enum is Pattern::Literal otherwise false

Source

pub const fn is_constant(&self) -> bool

Returns true if the enum is Pattern::Constant otherwise false

Source

pub const fn is_relation(&self) -> bool

Returns true if the enum is Pattern::Relation otherwise false

Source

pub const fn is_range(&self) -> bool

Returns true if the enum is Pattern::Range otherwise false

Source

pub const fn is_discard(&self) -> bool

Returns true if the enum is Pattern::Discard otherwise false

Source

pub const fn is_bind(&self) -> bool

Returns true if the enum is Pattern::Bind otherwise false

Source

pub const fn is_record(&self) -> bool

Returns true if the enum is Pattern::Record otherwise false

Source

pub const fn is_array(&self) -> bool

Returns true if the enum is Pattern::Array otherwise false

Source

pub const fn is_spread_discard(&self) -> bool

Returns true if the enum is Pattern::SpreadDiscard otherwise false

Source

pub const fn is_and(&self) -> bool

Returns true if the enum is Pattern::And otherwise false

Source

pub const fn is_or(&self) -> bool

Returns true if the enum is Pattern::Or otherwise false

Source

pub const fn is_not(&self) -> bool

Returns true if the enum is Pattern::Not otherwise false

Source

pub const fn is_unknown(&self) -> bool

Returns true if the enum is Pattern::Unknown otherwise false

Trait Implementations§

Source§

impl<'s> Clone for Pattern<'s>

Source§

fn clone(&self) -> Pattern<'s>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'s> Debug for Pattern<'s>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s> PartialEq for Pattern<'s>

Source§

fn eq(&self, other: &Pattern<'s>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'s> StructuralPartialEq for Pattern<'s>

Auto Trait Implementations§

§

impl<'s> Freeze for Pattern<'s>

§

impl<'s> RefUnwindSafe for Pattern<'s>

§

impl<'s> Send for Pattern<'s>

§

impl<'s> Sync for Pattern<'s>

§

impl<'s> Unpin for Pattern<'s>

§

impl<'s> UnsafeUnpin for Pattern<'s>

§

impl<'s> UnwindSafe for Pattern<'s>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.