pub enum ArgPattern {
None,
FixedLenTerm {
len: u8,
},
RangeLenTerm {
min: u8,
max: u8,
},
Greedy,
Glob {
pattern: GlobStr,
},
}
Expand description
An efficient pattern used for argument matching.
There are four kinds of pattern. The most powerful one is
ArgPattern::Glob
, which matches an sequence of input as arguments. Among
these four kinds, ArgPattern::Glob
can already match all possible inputs
in our use cases. But one should specify a fixed length pattern
(ArgPattern::FixedLenTerm
), a range length pattern
(ArgPattern::RangeLenTerm
), or a greedy pattern
(ArgPattern::Greedy
) to achieve better performance.
Let us look at usage of a glob pattern by \sqrt, which is {,b}t
.
-
Example 1. For
\sqrt{2}{3}
, parser requires the pattern to match with an encoded stringtt
. Here,{,b}t
matches and yields the stringt
(which corresponds to{2}
). -
Example 2. For
\sqrt[1]{2}{2}
, parser requires the pattern to match with an encoded stringbtt
. Here,{,b}t
matches and yields the stringbt
(which corresponds to[1]{2}
).
Kinds of item to match:
- Bracket/b: []
- Parenthesis/p: ()
- Term/t: any remaining terms, typically {} or a single char
Note: any prefix of the argument pattern are matched during the parse stage, so you need to check whether it is complete in later stages.
Variants§
None
No arguments are passed, i.e. this is processed as a variable in Typst.
E.g. \alpha
=> $alpha$
, where \alpha
has an argument pattern of
None
FixedLenTerm
Fixed length pattern, equivalent to repeat {,t}
for x
times
E.g. \hat x y
=> $hat(x) y$
, where \hat
has an argument pattern of
FixedLenTerm(1)
E.g. 1 \sum\limits
=> $1 limits(sum)$
, where \limits
has an
argument pattern of FixedLenTerm(1)
RangeLenTerm
Range length pattern (matches as much as possible), equivalent to
repeat t
for x
times, then repeat {,t}
for y
times.
No example
Fields
Greedy
Receives any items as much as possible, equivalent to *
.
E.g. \over, \displaystyle
Glob
The most powerful pattern, but slightly slow. Note that the glob must accept the whole prefix of the input.
E.g. \sqrt has a glob argument pattern of {,b}t
Description of the glob pattern:
- {,b}: first, it matches a bracket option, e.g.
\sqrt[3]
- t: it then matches a single term, e.g.
\sqrt[3]{a}
or\sqrt{a}
Trait Implementations§
Source§impl Archive for ArgPattern
impl Archive for ArgPattern
Source§type Archived = ArchivedArgPattern
type Archived = ArchivedArgPattern
Source§type Resolver = ArgPatternResolver
type Resolver = ArgPatternResolver
Source§impl Clone for ArgPattern
impl Clone for ArgPattern
Source§fn clone(&self) -> ArgPattern
fn clone(&self) -> ArgPattern
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ArgPattern
impl Debug for ArgPattern
Source§impl<'de> Deserialize<'de> for ArgPattern
impl<'de> Deserialize<'de> for ArgPattern
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ArgPattern, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ArgPattern, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<__D> Deserialize<ArgPattern, __D> for <ArgPattern as Archive>::Archived
impl<__D> Deserialize<ArgPattern, __D> for <ArgPattern as Archive>::Archived
Source§fn deserialize(
&self,
deserializer: &mut __D,
) -> Result<ArgPattern, <__D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut __D, ) -> Result<ArgPattern, <__D as Fallible>::Error>
Source§impl<__S> Serialize<__S> for ArgPattern
impl<__S> Serialize<__S> for ArgPattern
Source§impl Serialize for ArgPattern
impl Serialize for ArgPattern
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for ArgPattern
impl RefUnwindSafe for ArgPattern
impl Send for ArgPattern
impl Sync for ArgPattern
impl Unpin for ArgPattern
impl UnwindSafe for ArgPattern
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be unsized. Read more