mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Reorder and fix docs ✔
This commit is contained in:
parent
84ba547c7c
commit
0de4f3ed7b
@ -175,11 +175,11 @@ impl Eval for Spanned<&Expr> {
|
|||||||
Expr::Array(v) => Value::Array(v.with_span(self.span).eval(ctx)),
|
Expr::Array(v) => Value::Array(v.with_span(self.span).eval(ctx)),
|
||||||
Expr::Dict(v) => Value::Dict(v.with_span(self.span).eval(ctx)),
|
Expr::Dict(v) => Value::Dict(v.with_span(self.span).eval(ctx)),
|
||||||
Expr::Template(v) => Value::Template(v.clone()),
|
Expr::Template(v) => Value::Template(v.clone()),
|
||||||
|
Expr::Group(v) => v.as_ref().eval(ctx),
|
||||||
|
Expr::Block(v) => v.as_ref().eval(ctx),
|
||||||
Expr::Call(v) => v.with_span(self.span).eval(ctx),
|
Expr::Call(v) => v.with_span(self.span).eval(ctx),
|
||||||
Expr::Unary(v) => v.with_span(self.span).eval(ctx),
|
Expr::Unary(v) => v.with_span(self.span).eval(ctx),
|
||||||
Expr::Binary(v) => v.with_span(self.span).eval(ctx),
|
Expr::Binary(v) => v.with_span(self.span).eval(ctx),
|
||||||
Expr::Group(v) => v.as_ref().eval(ctx),
|
|
||||||
Expr::Block(v) => v.as_ref().eval(ctx),
|
|
||||||
Expr::Let(v) => v.with_span(self.span).eval(ctx),
|
Expr::Let(v) => v.with_span(self.span).eval(ctx),
|
||||||
Expr::If(v) => v.with_span(self.span).eval(ctx),
|
Expr::If(v) => v.with_span(self.span).eval(ctx),
|
||||||
}
|
}
|
||||||
|
@ -34,16 +34,16 @@ pub enum Expr {
|
|||||||
Dict(ExprDict),
|
Dict(ExprDict),
|
||||||
/// A template expression: `[*Hi* there!]`.
|
/// A template expression: `[*Hi* there!]`.
|
||||||
Template(ExprTemplate),
|
Template(ExprTemplate),
|
||||||
|
/// A grouped expression: `(1 + 2)`.
|
||||||
|
Group(ExprGroup),
|
||||||
|
/// A block expression: `{1 + 2}`.
|
||||||
|
Block(ExprBlock),
|
||||||
/// A unary operation: `-x`.
|
/// A unary operation: `-x`.
|
||||||
Unary(ExprUnary),
|
Unary(ExprUnary),
|
||||||
/// A binary operation: `a + b`, `a / b`.
|
/// A binary operation: `a + b`, `a / b`.
|
||||||
Binary(ExprBinary),
|
Binary(ExprBinary),
|
||||||
/// An invocation of a function: `[foo ...]`, `foo(...)`.
|
/// An invocation of a function: `[foo ...]`, `foo(...)`.
|
||||||
Call(ExprCall),
|
Call(ExprCall),
|
||||||
/// A grouped expression: `(1 + 2)`.
|
|
||||||
Group(ExprGroup),
|
|
||||||
/// A block expression: `{1 + 2}`.
|
|
||||||
Block(ExprBlock),
|
|
||||||
/// A let expression: `let x = 1`.
|
/// A let expression: `let x = 1`.
|
||||||
Let(ExprLet),
|
Let(ExprLet),
|
||||||
/// An if expression: `if x { y } else { z }`.
|
/// An if expression: `if x { y } else { z }`.
|
||||||
@ -70,9 +70,6 @@ impl Pretty for Expr {
|
|||||||
v.pretty(p);
|
v.pretty(p);
|
||||||
p.push_str("]");
|
p.push_str("]");
|
||||||
}
|
}
|
||||||
Self::Unary(v) => v.pretty(p),
|
|
||||||
Self::Binary(v) => v.pretty(p),
|
|
||||||
Self::Call(v) => v.pretty(p),
|
|
||||||
Self::Group(v) => {
|
Self::Group(v) => {
|
||||||
p.push_str("(");
|
p.push_str("(");
|
||||||
v.v.pretty(p);
|
v.v.pretty(p);
|
||||||
@ -83,6 +80,9 @@ impl Pretty for Expr {
|
|||||||
v.v.pretty(p);
|
v.v.pretty(p);
|
||||||
p.push_str("}");
|
p.push_str("}");
|
||||||
}
|
}
|
||||||
|
Self::Unary(v) => v.pretty(p),
|
||||||
|
Self::Binary(v) => v.pretty(p),
|
||||||
|
Self::Call(v) => v.pretty(p),
|
||||||
Self::Let(v) => v.pretty(p),
|
Self::Let(v) => v.pretty(p),
|
||||||
Self::If(v) => v.pretty(p),
|
Self::If(v) => v.pretty(p),
|
||||||
}
|
}
|
||||||
@ -121,6 +121,12 @@ impl Pretty for ExprDict {
|
|||||||
/// A template expression: `[*Hi* there!]`.
|
/// A template expression: `[*Hi* there!]`.
|
||||||
pub type ExprTemplate = Tree;
|
pub type ExprTemplate = Tree;
|
||||||
|
|
||||||
|
/// A grouped expression: `(1 + 2)`.
|
||||||
|
pub type ExprGroup = Box<Spanned<Expr>>;
|
||||||
|
|
||||||
|
/// A block expression: `{1 + 2}`.
|
||||||
|
pub type ExprBlock = Box<Spanned<Expr>>;
|
||||||
|
|
||||||
/// An invocation of a function: `[foo ...]`, `foo(...)`.
|
/// An invocation of a function: `[foo ...]`, `foo(...)`.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ExprCall {
|
pub struct ExprCall {
|
||||||
@ -306,12 +312,6 @@ impl Pretty for BinOp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A grouped expression: `(1 + 2)`.
|
|
||||||
pub type ExprGroup = Box<Spanned<Expr>>;
|
|
||||||
|
|
||||||
/// A block expression: `{1 + 2}`.
|
|
||||||
pub type ExprBlock = Box<Spanned<Expr>>;
|
|
||||||
|
|
||||||
/// A let expression: `let x = 1`.
|
/// A let expression: `let x = 1`.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ExprLet {
|
pub struct ExprLet {
|
||||||
@ -335,7 +335,7 @@ impl Pretty for ExprLet {
|
|||||||
/// An if expression: `if x { y } else { z }`.
|
/// An if expression: `if x { y } else { z }`.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct ExprIf {
|
pub struct ExprIf {
|
||||||
/// The pattern to assign to.
|
/// The condition which selects the body to evaluate.
|
||||||
pub condition: Box<Spanned<Expr>>,
|
pub condition: Box<Spanned<Expr>>,
|
||||||
/// The expression to evaluate if the condition is true.
|
/// The expression to evaluate if the condition is true.
|
||||||
pub if_body: Box<Spanned<Expr>>,
|
pub if_body: Box<Spanned<Expr>>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user