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.
Implementations§
Source§impl<'s> Pattern<'s>
impl<'s> Pattern<'s>
Sourcepub const fn is_grouping(&self) -> bool
pub const fn is_grouping(&self) -> bool
Returns true if the enum is Pattern::Grouping otherwise false
Sourcepub const fn is_literal(&self) -> bool
pub const fn is_literal(&self) -> bool
Returns true if the enum is Pattern::Literal otherwise false
Sourcepub const fn is_constant(&self) -> bool
pub const fn is_constant(&self) -> bool
Returns true if the enum is Pattern::Constant otherwise false
Sourcepub const fn is_relation(&self) -> bool
pub const fn is_relation(&self) -> bool
Returns true if the enum is Pattern::Relation otherwise false
Sourcepub const fn is_range(&self) -> bool
pub const fn is_range(&self) -> bool
Returns true if the enum is Pattern::Range otherwise false
Sourcepub const fn is_discard(&self) -> bool
pub const fn is_discard(&self) -> bool
Returns true if the enum is Pattern::Discard otherwise false
Sourcepub const fn is_record(&self) -> bool
pub const fn is_record(&self) -> bool
Returns true if the enum is Pattern::Record otherwise false
Sourcepub const fn is_array(&self) -> bool
pub const fn is_array(&self) -> bool
Returns true if the enum is Pattern::Array otherwise false
Sourcepub const fn is_spread_discard(&self) -> bool
pub const fn is_spread_discard(&self) -> bool
Returns true if the enum is Pattern::SpreadDiscard otherwise false
Sourcepub const fn is_unknown(&self) -> bool
pub const fn is_unknown(&self) -> bool
Returns true if the enum is Pattern::Unknown otherwise false