typst_syntax::ast

Enum Expr

source
pub enum Expr<'a> {
Show 58 variants Text(Text<'a>), Space(Space<'a>), Linebreak(Linebreak<'a>), Parbreak(Parbreak<'a>), Escape(Escape<'a>), Shorthand(Shorthand<'a>), SmartQuote(SmartQuote<'a>), Strong(Strong<'a>), Emph(Emph<'a>), Raw(Raw<'a>), Link(Link<'a>), Label(Label<'a>), Ref(Ref<'a>), Heading(Heading<'a>), List(ListItem<'a>), Enum(EnumItem<'a>), Term(TermItem<'a>), Equation(Equation<'a>), Math(Math<'a>), MathIdent(MathIdent<'a>), MathShorthand(MathShorthand<'a>), MathAlignPoint(MathAlignPoint<'a>), MathDelimited(MathDelimited<'a>), MathAttach(MathAttach<'a>), MathPrimes(MathPrimes<'a>), MathFrac(MathFrac<'a>), MathRoot(MathRoot<'a>), Ident(Ident<'a>), None(None<'a>), Auto(Auto<'a>), Bool(Bool<'a>), Int(Int<'a>), Float(Float<'a>), Numeric(Numeric<'a>), Str(Str<'a>), Code(CodeBlock<'a>), Content(ContentBlock<'a>), Parenthesized(Parenthesized<'a>), Array(Array<'a>), Dict(Dict<'a>), Unary(Unary<'a>), Binary(Binary<'a>), FieldAccess(FieldAccess<'a>), FuncCall(FuncCall<'a>), Closure(Closure<'a>), Let(LetBinding<'a>), DestructAssign(DestructAssignment<'a>), Set(SetRule<'a>), Show(ShowRule<'a>), Contextual(Contextual<'a>), Conditional(Conditional<'a>), While(WhileLoop<'a>), For(ForLoop<'a>), Import(ModuleImport<'a>), Include(ModuleInclude<'a>), Break(LoopBreak<'a>), Continue(LoopContinue<'a>), Return(FuncReturn<'a>),
}
Expand description

An expression in markup, math or code.

Variants§

§

Text(Text<'a>)

Plain text without markup.

§

Space(Space<'a>)

Whitespace in markup or math. Has at most one newline in markup, as more indicate a paragraph break.

§

Linebreak(Linebreak<'a>)

A forced line break: \.

§

Parbreak(Parbreak<'a>)

A paragraph break, indicated by one or multiple blank lines.

§

Escape(Escape<'a>)

An escape sequence: \#, \u{1F5FA}.

§

Shorthand(Shorthand<'a>)

A shorthand for a unicode codepoint. For example, ~ for non-breaking space or -? for a soft hyphen.

§

SmartQuote(SmartQuote<'a>)

A smart quote: ' or ".

§

Strong(Strong<'a>)

Strong content: *Strong*.

§

Emph(Emph<'a>)

Emphasized content: _Emphasized_.

§

Raw(Raw<'a>)

Raw text with optional syntax highlighting: `...`.

A hyperlink: https://typst.org.

§

Label(Label<'a>)

A label: <intro>.

§

Ref(Ref<'a>)

A reference: @target, @target[..].

§

Heading(Heading<'a>)

A section heading: = Introduction.

§

List(ListItem<'a>)

An item in a bullet list: - ....

§

Enum(EnumItem<'a>)

An item in an enumeration (numbered list): + ... or 1. ....

§

Term(TermItem<'a>)

An item in a term list: / Term: Details.

§

Equation(Equation<'a>)

A mathematical equation: $x$, $ x^2 $.

§

Math(Math<'a>)

The contents of a mathematical equation: x^2 + 1.

§

MathIdent(MathIdent<'a>)

An identifier in math: pi.

§

MathShorthand(MathShorthand<'a>)

A shorthand for a unicode codepoint in math: a <= b.

§

MathAlignPoint(MathAlignPoint<'a>)

An alignment point in math: &.

§

MathDelimited(MathDelimited<'a>)

Matched delimiters in math: [x + y].

§

MathAttach(MathAttach<'a>)

A base with optional attachments in math: a_1^2.

§

MathPrimes(MathPrimes<'a>)

Grouped math primes

§

MathFrac(MathFrac<'a>)

A fraction in math: x/2.

§

MathRoot(MathRoot<'a>)

A root in math: √x, ∛x or ∜x.

§

Ident(Ident<'a>)

An identifier: left.

§

None(None<'a>)

The none literal.

§

Auto(Auto<'a>)

The auto literal.

§

Bool(Bool<'a>)

A boolean: true, false.

§

Int(Int<'a>)

An integer: 120.

§

Float(Float<'a>)

A floating-point number: 1.2, 10e-4.

§

Numeric(Numeric<'a>)

A numeric value with a unit: 12pt, 3cm, 2em, 90deg, 50%.

§

Str(Str<'a>)

A quoted string: "...".

§

Code(CodeBlock<'a>)

A code block: { let x = 1; x + 2 }.

§

Content(ContentBlock<'a>)

A content block: [*Hi* there!].

§

Parenthesized(Parenthesized<'a>)

A grouped expression: (1 + 2).

§

Array(Array<'a>)

An array: (1, "hi", 12cm).

§

Dict(Dict<'a>)

A dictionary: (thickness: 3pt, pattern: dashed).

§

Unary(Unary<'a>)

A unary operation: -x.

§

Binary(Binary<'a>)

A binary operation: a + b.

§

FieldAccess(FieldAccess<'a>)

A field access: properties.age.

§

FuncCall(FuncCall<'a>)

An invocation of a function or method: f(x, y).

§

Closure(Closure<'a>)

A closure: (x, y) => z.

§

Let(LetBinding<'a>)

A let binding: let x = 1.

§

DestructAssign(DestructAssignment<'a>)

A destructuring assignment: (x, y) = (1, 2).

§

Set(SetRule<'a>)

A set rule: set text(...).

§

Show(ShowRule<'a>)

A show rule: show heading: it => emph(it.body).

§

Contextual(Contextual<'a>)

A contextual expression: context text.lang.

§

Conditional(Conditional<'a>)

An if-else conditional: if x { y } else { z }.

§

While(WhileLoop<'a>)

A while loop: while x { y }.

§

For(ForLoop<'a>)

A for loop: for x in y { z }.

§

Import(ModuleImport<'a>)

A module import: import "utils.typ": a, b, c.

§

Include(ModuleInclude<'a>)

A module include: include "chapter1.typ".

§

Break(LoopBreak<'a>)

A break from a loop: break.

§

Continue(LoopContinue<'a>)

A continue in a loop: continue.

§

Return(FuncReturn<'a>)

A return from a function: return, return x + 1.

Implementations§

source§

impl Expr<'_>

source

pub fn hash(self) -> bool

Can this expression be embedded into markup with a hash?

source

pub fn is_literal(self) -> bool

Is this a literal?

Trait Implementations§

source§

impl<'a> AstNode<'a> for Expr<'a>

source§

fn from_untyped(node: &'a SyntaxNode) -> Option<Self>

Convert a node into its typed variant.
source§

fn to_untyped(self) -> &'a SyntaxNode

A reference to the underlying syntax node.
source§

fn span(self) -> Span

The source code location.
source§

impl<'a> Clone for Expr<'a>

source§

fn clone(&self) -> Expr<'a>

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<'a> Debug for Expr<'a>

source§

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

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

impl Default for Expr<'_>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> Hash for Expr<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> Copy for Expr<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Expr<'a>

§

impl<'a> RefUnwindSafe for Expr<'a>

§

impl<'a> Send for Expr<'a>

§

impl<'a> Sync for Expr<'a>

§

impl<'a> Unpin for Expr<'a>

§

impl<'a> UnwindSafe for Expr<'a>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.