mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Documentation fixes ✔
This commit is contained in:
parent
34f839c717
commit
5157c1e276
@ -83,8 +83,8 @@ impl Display for Level {
|
|||||||
/// # use typst::error;
|
/// # use typst::error;
|
||||||
/// # use typst::syntax::Span;
|
/// # use typst::syntax::Span;
|
||||||
/// # let span = Span::ZERO;
|
/// # let span = Span::ZERO;
|
||||||
/// # let name = "";
|
/// # let thing = "";
|
||||||
/// let error = error!(span, "there is an error with {}", name);
|
/// let error = error!(span, "there is an error with {}", thing);
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
@ -99,8 +99,7 @@ macro_rules! error {
|
|||||||
|
|
||||||
/// Construct a diagnostic with [`Warning`](Level::Warning) level.
|
/// Construct a diagnostic with [`Warning`](Level::Warning) level.
|
||||||
///
|
///
|
||||||
/// This works exactly like `error!`. See its documentation for more
|
/// This works exactly like [`error!`].
|
||||||
/// information.
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! warning {
|
macro_rules! warning {
|
||||||
($span:expr, $($tts:tt)*) => {
|
($span:expr, $($tts:tt)*) => {
|
||||||
|
@ -32,7 +32,7 @@ impl<'ast> Visit<'ast> for CapturesVisitor<'_> {
|
|||||||
match node {
|
match node {
|
||||||
Expr::Ident(ident) => {
|
Expr::Ident(ident) => {
|
||||||
// Find out whether the identifier is not locally defined, but
|
// Find out whether the identifier is not locally defined, but
|
||||||
// captured, and if so, replace it with its value.
|
// captured, and if so, capture its value.
|
||||||
if self.internal.get(ident).is_none() {
|
if self.internal.get(ident).is_none() {
|
||||||
if let Some(slot) = self.external.get(ident) {
|
if let Some(slot) = self.external.get(ident) {
|
||||||
self.captures.def_slot(ident.as_str(), Rc::clone(slot));
|
self.captures.def_slot(ident.as_str(), Rc::clone(slot));
|
||||||
|
@ -32,9 +32,9 @@ pub fn eval(env: &mut Env, tree: &Tree, scope: &Scope) -> Pass<ExprMap> {
|
|||||||
|
|
||||||
/// A map from expressions to the values they evaluated to.
|
/// A map from expressions to the values they evaluated to.
|
||||||
///
|
///
|
||||||
/// The raw pointers point into the expressions contained in some [tree](Tree).
|
/// The raw pointers point into the expressions contained in some [`Tree`].
|
||||||
/// Since the lifetime is erased, the tree could go out of scope while the hash
|
/// Since the lifetime is erased, the tree could go out of scope while the hash
|
||||||
/// map still lives. Though this could lead to lookup panics, it is not unsafe
|
/// map still lives. Although this could lead to lookup panics, it is not unsafe
|
||||||
/// since the pointers are never dereferenced.
|
/// since the pointers are never dereferenced.
|
||||||
pub type ExprMap = HashMap<*const Expr, Value>;
|
pub type ExprMap = HashMap<*const Expr, Value>;
|
||||||
|
|
||||||
@ -84,8 +84,8 @@ impl Eval for Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'ast> Visit<'ast> for ExprVisitor<'_, '_> {
|
impl<'ast> Visit<'ast> for ExprVisitor<'_, '_> {
|
||||||
fn visit_expr(&mut self, item: &'ast Expr) {
|
fn visit_expr(&mut self, node: &'ast Expr) {
|
||||||
self.map.insert(item as *const _, item.eval(self.ctx));
|
self.map.insert(node as *const _, node.eval(self.ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,8 +443,8 @@ impl Eval for ExprIf {
|
|||||||
if let Value::Bool(condition) = condition {
|
if let Value::Bool(condition) = condition {
|
||||||
if condition {
|
if condition {
|
||||||
self.if_body.eval(ctx)
|
self.if_body.eval(ctx)
|
||||||
} else if let Some(expr) = &self.else_body {
|
} else if let Some(else_body) = &self.else_body {
|
||||||
expr.eval(ctx)
|
else_body.eval(ctx)
|
||||||
} else {
|
} else {
|
||||||
Value::None
|
Value::None
|
||||||
}
|
}
|
||||||
|
@ -52,16 +52,21 @@ impl<'a> Scopes<'a> {
|
|||||||
self.top = self.scopes.pop().expect("no pushed scope");
|
self.top = self.scopes.pop().expect("no pushed scope");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define a constant variable in the active scope.
|
/// Define a constant variable with a value in the active scope.
|
||||||
pub fn def_const(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
pub fn def_const(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
||||||
self.top.def_const(var, value);
|
self.top.def_const(var, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define a mutable variable in the active scope.
|
/// Define a mutable variable with a value in the active scope.
|
||||||
pub fn def_mut(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
pub fn def_mut(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
||||||
self.top.def_mut(var, value);
|
self.top.def_mut(var, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Define a variable with a slot in the active scope.
|
||||||
|
pub fn def_slot(&mut self, var: impl Into<String>, slot: Slot) {
|
||||||
|
self.top.def_slot(var, slot);
|
||||||
|
}
|
||||||
|
|
||||||
/// Look up the slot of a variable.
|
/// Look up the slot of a variable.
|
||||||
pub fn get(&self, var: &str) -> Option<&Slot> {
|
pub fn get(&self, var: &str) -> Option<&Slot> {
|
||||||
iter::once(&self.top)
|
iter::once(&self.top)
|
||||||
@ -84,7 +89,7 @@ impl Scope {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define a constant variable.
|
/// Define a constant variable with a value.
|
||||||
pub fn def_const(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
pub fn def_const(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
||||||
let cell = RefCell::new(value.into());
|
let cell = RefCell::new(value.into());
|
||||||
|
|
||||||
@ -95,7 +100,7 @@ impl Scope {
|
|||||||
self.values.insert(var.into(), Rc::new(cell));
|
self.values.insert(var.into(), Rc::new(cell));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define a mutable variable.
|
/// Define a mutable variable with a value.
|
||||||
pub fn def_mut(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
pub fn def_mut(&mut self, var: impl Into<String>, value: impl Into<Value>) {
|
||||||
self.values.insert(var.into(), Rc::new(RefCell::new(value.into())));
|
self.values.insert(var.into(), Rc::new(RefCell::new(value.into())));
|
||||||
}
|
}
|
||||||
|
@ -178,8 +178,8 @@ impl<'a> ExecContext<'a> {
|
|||||||
|
|
||||||
/// Start a layouting group.
|
/// Start a layouting group.
|
||||||
///
|
///
|
||||||
/// All further calls to [`push`](Self::push) will collect nodes for this group.
|
/// All further calls to [`push`](Self::push) will collect nodes for this
|
||||||
/// The given metadata will be returned alongside the collected nodes
|
/// group. The given metadata will be returned alongside the collected nodes
|
||||||
/// in a matching call to [`end_group`](Self::end_group).
|
/// in a matching call to [`end_group`](Self::end_group).
|
||||||
fn start_group<T: 'static>(&mut self, meta: T) {
|
fn start_group<T: 'static>(&mut self, meta: T) {
|
||||||
self.groups.push((Box::new(meta), std::mem::take(&mut self.inner)));
|
self.groups.push((Box::new(meta), std::mem::take(&mut self.inner)));
|
||||||
|
@ -133,7 +133,7 @@ impl FontState {
|
|||||||
impl Default for FontState {
|
impl Default for FontState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
/// The default tree of font fallbacks.
|
// The default tree of font fallbacks.
|
||||||
families: Rc::new(fallback! {
|
families: Rc::new(fallback! {
|
||||||
list: [],
|
list: [],
|
||||||
classes: { "monospace" => ["inconsolata"] },
|
classes: { "monospace" => ["inconsolata"] },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user