Enum ArgPattern

Source
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 string tt. Here, {,b}t matches and yields the string t (which corresponds to {2}).

  • Example 2. For \sqrt[1]{2}{2}, parser requires the pattern to match with an encoded string btt. Here, {,b}t matches and yields the string bt (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)

Fields

§len: u8

The length of the arguments should be matched

§

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

§min: u8

The minimum length of the arguments should be matched

§max: u8

The maximum length of the arguments should be matched

§

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}

Fields

§pattern: GlobStr

The glob pattern to match the arguments

Trait Implementations§

Source§

impl Archive for ArgPattern

Source§

type Archived = ArchivedArgPattern

The archived representation of this type. Read more
Source§

type Resolver = ArgPatternResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

unsafe fn resolve( &self, pos: usize, resolver: <ArgPattern as Archive>::Resolver, out: *mut <ArgPattern as Archive>::Archived, )

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

impl Clone for ArgPattern

Source§

fn clone(&self) -> ArgPattern

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ArgPattern

Source§

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

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

impl<'de> Deserialize<'de> for ArgPattern

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ArgPattern, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<__D> Deserialize<ArgPattern, __D> for <ArgPattern as Archive>::Archived

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<ArgPattern, <__D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<__S> Serialize<__S> for ArgPattern
where __S: Fallible + ?Sized, u8: Serialize<__S>, GlobStr: Serialize<__S>,

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<ArgPattern as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

impl Serialize for ArgPattern

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

type MetadataResolver = ()

The resolver for the metadata of this type. Read more
Source§

unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata, )

Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
Source§

unsafe fn resolve_unsized( &self, from: usize, to: usize, resolver: Self::MetadataResolver, out: *mut RelPtr<Self::Archived, <isize as Archive>::Archived>, )

Resolves a relative pointer to this value with the given from and to and writes it to the given output. 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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Serializer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
Source§

fn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>

Serializes the metadata for the given type.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,