summaryrefslogtreecommitdiff
path: root/library/src/compute
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
commit25b5bd117529cd04bb789e1988eb3a3db8025a0e (patch)
tree2fbb4650903123da047a1f1f11a0abda95286e12 /library/src/compute
parent6ab7760822ccd24b4ef126d4737d41f1be15fe19 (diff)
Fully untyped model
Diffstat (limited to 'library/src/compute')
-rw-r--r--library/src/compute/calc.rs120
-rw-r--r--library/src/compute/construct.rs62
-rw-r--r--library/src/compute/data.rs22
-rw-r--r--library/src/compute/foundations.rs25
-rw-r--r--library/src/compute/mod.rs3
5 files changed, 96 insertions, 136 deletions
diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs
index 9ebce84c..d4a4bcf6 100644
--- a/library/src/compute/calc.rs
+++ b/library/src/compute/calc.rs
@@ -1,3 +1,5 @@
+//! Calculations and processing of numeric values.
+
use std::cmp::Ordering;
use std::ops::Rem;
@@ -6,7 +8,7 @@ use typst::eval::{Module, Scope};
use crate::prelude::*;
/// A module with computational functions.
-pub fn calc() -> Module {
+pub fn module() -> Module {
let mut scope = Scope::new();
scope.def_func::<AbsFunc>("abs");
scope.def_func::<PowFunc>("pow");
@@ -37,7 +39,6 @@ pub fn calc() -> Module {
Module::new("calc").with_scope(scope)
}
-/// # Absolute
/// Calculate the absolute value of a numeric value.
///
/// ## Example
@@ -51,8 +52,8 @@ pub fn calc() -> Module {
/// - value: `ToAbs` (positional, required)
/// The value whose absolute value to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Absolute
+/// Category: calculate
#[func]
pub fn abs(args: &mut Args) -> SourceResult<Value> {
Ok(args.expect::<ToAbs>("value")?.0)
@@ -61,7 +62,7 @@ pub fn abs(args: &mut Args) -> SourceResult<Value> {
/// A value of which the absolute value can be taken.
struct ToAbs(Value);
-castable! {
+cast_from_value! {
ToAbs,
v: i64 => Self(Value::Int(v.abs())),
v: f64 => Self(Value::Float(v.abs())),
@@ -72,7 +73,6 @@ castable! {
v: Fr => Self(Value::Fraction(v.abs())),
}
-/// # Power
/// Raise a value to some exponent.
///
/// ## Example
@@ -86,8 +86,8 @@ castable! {
/// - exponent: `Num` (positional, required)
/// The exponent of the power. Must be non-negative.
///
-/// ## Category
-/// calculate
+/// Display: Power
+/// Category: calculate
#[func]
pub fn pow(args: &mut Args) -> SourceResult<Value> {
let base = args.expect::<Num>("base")?;
@@ -103,7 +103,6 @@ pub fn pow(args: &mut Args) -> SourceResult<Value> {
Ok(base.apply2(exponent, |a, b| a.pow(b as u32), f64::powf))
}
-/// # Square Root
/// Calculate the square root of a number.
///
/// ## Example
@@ -116,8 +115,8 @@ pub fn pow(args: &mut Args) -> SourceResult<Value> {
/// - value: `Num` (positional, required)
/// The number whose square root to calculate. Must be non-negative.
///
-/// ## Category
-/// calculate
+/// Display: Square Root
+/// Category: calculate
#[func]
pub fn sqrt(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<Spanned<Num>>("value")?;
@@ -127,7 +126,6 @@ pub fn sqrt(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Float(value.v.float().sqrt()))
}
-/// # Sine
/// Calculate the sine of an angle.
///
/// When called with an integer or a float, they will be interpreted as
@@ -144,8 +142,8 @@ pub fn sqrt(args: &mut Args) -> SourceResult<Value> {
/// - angle: `AngleLike` (positional, required)
/// The angle whose sine to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Sine
+/// Category: calculate
#[func]
pub fn sin(args: &mut Args) -> SourceResult<Value> {
let arg = args.expect::<AngleLike>("angle")?;
@@ -156,7 +154,6 @@ pub fn sin(args: &mut Args) -> SourceResult<Value> {
}))
}
-/// # Cosine
/// Calculate the cosine of an angle.
///
/// When called with an integer or a float, they will be interpreted as
@@ -173,8 +170,8 @@ pub fn sin(args: &mut Args) -> SourceResult<Value> {
/// - angle: `AngleLike` (positional, required)
/// The angle whose cosine to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Cosine
+/// Category: calculate
#[func]
pub fn cos(args: &mut Args) -> SourceResult<Value> {
let arg = args.expect::<AngleLike>("angle")?;
@@ -185,7 +182,6 @@ pub fn cos(args: &mut Args) -> SourceResult<Value> {
}))
}
-/// # Tangent
/// Calculate the tangent of an angle.
///
/// When called with an integer or a float, they will be interpreted as
@@ -201,8 +197,8 @@ pub fn cos(args: &mut Args) -> SourceResult<Value> {
/// - angle: `AngleLike` (positional, required)
/// The angle whose tangent to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Tangent
+/// Category: calculate
#[func]
pub fn tan(args: &mut Args) -> SourceResult<Value> {
let arg = args.expect::<AngleLike>("angle")?;
@@ -213,7 +209,6 @@ pub fn tan(args: &mut Args) -> SourceResult<Value> {
}))
}
-/// # Arcsine
/// Calculate the arcsine of a number.
///
/// ## Example
@@ -226,8 +221,8 @@ pub fn tan(args: &mut Args) -> SourceResult<Value> {
/// - value: `Num` (positional, required)
/// The number whose arcsine to calculate. Must be between -1 and 1.
///
-/// ## Category
-/// calculate
+/// Display: Arcsine
+/// Category: calculate
#[func]
pub fn asin(args: &mut Args) -> SourceResult<Value> {
let Spanned { v, span } = args.expect::<Spanned<Num>>("value")?;
@@ -238,7 +233,6 @@ pub fn asin(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Angle(Angle::rad(val.asin())))
}
-/// # Arccosine
/// Calculate the arccosine of a number.
///
/// ## Example
@@ -251,8 +245,8 @@ pub fn asin(args: &mut Args) -> SourceResult<Value> {
/// - value: `Num` (positional, required)
/// The number whose arccosine to calculate. Must be between -1 and 1.
///
-/// ## Category
-/// calculate
+/// Display: Arccosine
+/// Category: calculate
#[func]
pub fn acos(args: &mut Args) -> SourceResult<Value> {
let Spanned { v, span } = args.expect::<Spanned<Num>>("value")?;
@@ -263,7 +257,6 @@ pub fn acos(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Angle(Angle::rad(val.acos())))
}
-/// # Arctangent
/// Calculate the arctangent of a number.
///
/// ## Example
@@ -276,15 +269,14 @@ pub fn acos(args: &mut Args) -> SourceResult<Value> {
/// - value: `Num` (positional, required)
/// The number whose arctangent to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Arctangent
+/// Category: calculate
#[func]
pub fn atan(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<Num>("value")?;
Ok(Value::Angle(Angle::rad(value.float().atan())))
}
-/// # Hyperbolic sine
/// Calculate the hyperbolic sine of an angle.
///
/// When called with an integer or a float, they will be interpreted as radians.
@@ -299,8 +291,8 @@ pub fn atan(args: &mut Args) -> SourceResult<Value> {
/// - angle: `AngleLike` (positional, required)
/// The angle whose hyperbolic sine to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Hyperbolic sine
+/// Category: calculate
#[func]
pub fn sinh(args: &mut Args) -> SourceResult<Value> {
let arg = args.expect::<AngleLike>("angle")?;
@@ -311,7 +303,6 @@ pub fn sinh(args: &mut Args) -> SourceResult<Value> {
}))
}
-/// # Hyperbolic cosine
/// Calculate the hyperbolic cosine of an angle.
///
/// When called with an integer or a float, they will be interpreted as radians.
@@ -326,8 +317,8 @@ pub fn sinh(args: &mut Args) -> SourceResult<Value> {
/// - angle: `AngleLike` (positional, required)
/// The angle whose hyperbolic cosine to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Hyperbolic cosine
+/// Category: calculate
#[func]
pub fn cosh(args: &mut Args) -> SourceResult<Value> {
let arg = args.expect::<AngleLike>("angle")?;
@@ -338,7 +329,6 @@ pub fn cosh(args: &mut Args) -> SourceResult<Value> {
}))
}
-/// # Hyperbolic tangent
/// Calculate the hyperbolic tangent of an angle.
///
/// When called with an integer or a float, they will be interpreted as radians.
@@ -353,8 +343,8 @@ pub fn cosh(args: &mut Args) -> SourceResult<Value> {
/// - angle: `AngleLike` (positional, required)
/// The angle whose hyperbolic tangent to calculate.
///
-/// ## Category
-/// calculate
+/// Display: Hyperbolic tangent
+/// Category: calculate
#[func]
pub fn tanh(args: &mut Args) -> SourceResult<Value> {
let arg = args.expect::<AngleLike>("angle")?;
@@ -365,7 +355,6 @@ pub fn tanh(args: &mut Args) -> SourceResult<Value> {
}))
}
-/// # Logarithm
/// Calculate the logarithm of a number.
///
/// If the base is not specified, the logarithm is calculated in base 10.
@@ -381,8 +370,8 @@ pub fn tanh(args: &mut Args) -> SourceResult<Value> {
/// - base: `Num` (named)
/// The base of the logarithm.
///
-/// ## Category
-/// calculate
+/// Display: Logarithm
+/// Category: calculate
#[func]
pub fn log(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<f64>("value")?;
@@ -390,7 +379,6 @@ pub fn log(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Float(value.log(base)))
}
-/// # Round down
/// Round a number down to the nearest integer.
///
/// If the number is already an integer, it is returned unchanged.
@@ -406,8 +394,8 @@ pub fn log(args: &mut Args) -> SourceResult<Value> {
/// - value: `Num` (positional, required)
/// The number to round down.
///
-/// ## Category
-/// calculate
+/// Display: Round down
+/// Category: calculate
#[func]
pub fn floor(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<Num>("value")?;
@@ -417,7 +405,6 @@ pub fn floor(args: &mut Args) -> SourceResult<Value> {
})
}
-/// # Round up
/// Round a number up to the nearest integer.
///
/// If the number is already an integer, it is returned unchanged.
@@ -433,8 +420,8 @@ pub fn floor(args: &mut Args) -> SourceResult<Value> {
/// - value: `Num` (positional, required)
/// The number to round up.
///
-/// ## Category
-/// calculate
+/// Display: Round up
+/// Category: calculate
#[func]
pub fn ceil(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<Num>("value")?;
@@ -444,7 +431,6 @@ pub fn ceil(args: &mut Args) -> SourceResult<Value> {
})
}
-/// # Round
/// Round a number to the nearest integer.
///
/// Optionally, a number of decimal places can be specified.
@@ -461,8 +447,8 @@ pub fn ceil(args: &mut Args) -> SourceResult<Value> {
/// The number to round.
/// - digits: `i64` (named)
///
-/// ## Category
-/// calculate
+/// Display: Round
+/// Category: calculate
#[func]
pub fn round(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<Num>("value")?;
@@ -477,7 +463,6 @@ pub fn round(args: &mut Args) -> SourceResult<Value> {
})
}
-/// # Clamp
/// Clamp a number between a minimum and maximum value.
///
/// ## Example
@@ -495,8 +480,8 @@ pub fn round(args: &mut Args) -> SourceResult<Value> {
/// - max: `Num` (positional, required)
/// The inclusive maximum value.
///
-/// ## Category
-/// calculate
+/// Display: Clamp
+/// Category: calculate
#[func]
pub fn clamp(args: &mut Args) -> SourceResult<Value> {
let value = args.expect::<Num>("value")?;
@@ -508,7 +493,6 @@ pub fn clamp(args: &mut Args) -> SourceResult<Value> {
Ok(value.apply3(min, max.v, i64::clamp, f64::clamp))
}
-/// # Minimum
/// Determine the minimum of a sequence of values.
///
/// ## Example
@@ -524,14 +508,13 @@ pub fn clamp(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: any
///
-/// ## Category
-/// calculate
+/// Display: Minimum
+/// Category: calculate
#[func]
pub fn min(args: &mut Args) -> SourceResult<Value> {
minmax(args, Ordering::Less)
}
-/// # Maximum
/// Determine the maximum of a sequence of values.
///
/// ## Example
@@ -547,8 +530,8 @@ pub fn min(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: any
///
-/// ## Category
-/// calculate
+/// Display: Maximum
+/// Category: calculate
#[func]
pub fn max(args: &mut Args) -> SourceResult<Value> {
minmax(args, Ordering::Greater)
@@ -575,7 +558,6 @@ fn minmax(args: &mut Args, goal: Ordering) -> SourceResult<Value> {
Ok(extremum)
}
-/// # Even
/// Determine whether an integer is even.
///
/// ## Example
@@ -591,14 +573,13 @@ fn minmax(args: &mut Args, goal: Ordering) -> SourceResult<Value> {
///
/// - returns: boolean
///
-/// ## Category
-/// calculate
+/// Display: Even
+/// Category: calculate
#[func]
pub fn even(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Bool(args.expect::<i64>("value")? % 2 == 0))
}
-/// # Odd
/// Determine whether an integer is odd.
///
/// ## Example
@@ -615,14 +596,13 @@ pub fn even(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: boolean
///
-/// ## Category
-/// calculate
+/// Display: Odd
+/// Category: calculate
#[func]
pub fn odd(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Bool(args.expect::<i64>("value")? % 2 != 0))
}
-/// # Modulus
/// Calculate the modulus of two numbers.
///
/// ## Example
@@ -640,8 +620,8 @@ pub fn odd(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: integer or float
///
-/// ## Category
-/// calculate
+/// Display: Modulus
+/// Category: calculate
#[func]
pub fn mod_(args: &mut Args) -> SourceResult<Value> {
let dividend = args.expect::<Num>("dividend")?;
@@ -693,7 +673,7 @@ impl Num {
}
}
-castable! {
+cast_from_value! {
Num,
v: i64 => Self::Int(v),
v: f64 => Self::Float(v),
@@ -706,7 +686,7 @@ enum AngleLike {
Angle(Angle),
}
-castable! {
+cast_from_value! {
AngleLike,
v: i64 => Self::Int(v),
v: f64 => Self::Float(v),
diff --git a/library/src/compute/construct.rs b/library/src/compute/construct.rs
index 8355e20f..db442327 100644
--- a/library/src/compute/construct.rs
+++ b/library/src/compute/construct.rs
@@ -5,7 +5,6 @@ use typst::eval::Regex;
use crate::prelude::*;
-/// # Integer
/// Convert a value to an integer.
///
/// - Booleans are converted to `0` or `1`.
@@ -26,8 +25,8 @@ use crate::prelude::*;
///
/// - returns: integer
///
-/// ## Category
-/// construct
+/// Display: Integer
+/// Category: construct
#[func]
pub fn int(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Int(args.expect::<ToInt>("value")?.0))
@@ -36,7 +35,7 @@ pub fn int(args: &mut Args) -> SourceResult<Value> {
/// A value that can be cast to an integer.
struct ToInt(i64);
-castable! {
+cast_from_value! {
ToInt,
v: bool => Self(v as i64),
v: i64 => Self(v),
@@ -44,7 +43,6 @@ castable! {
v: EcoString => Self(v.parse().map_err(|_| "not a valid integer")?),
}
-/// # Float
/// Convert a value to a float.
///
/// - Booleans are converted to `0.0` or `1.0`.
@@ -67,8 +65,8 @@ castable! {
///
/// - returns: float
///
-/// ## Category
-/// construct
+/// Display: Float
+/// Category: construct
#[func]
pub fn float(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Float(args.expect::<ToFloat>("value")?.0))
@@ -77,7 +75,7 @@ pub fn float(args: &mut Args) -> SourceResult<Value> {
/// A value that can be cast to a float.
struct ToFloat(f64);
-castable! {
+cast_from_value! {
ToFloat,
v: bool => Self(v as i64 as f64),
v: i64 => Self(v as f64),
@@ -85,7 +83,6 @@ castable! {
v: EcoString => Self(v.parse().map_err(|_| "not a valid float")?),
}
-/// # Luma
/// Create a grayscale color.
///
/// ## Example
@@ -101,15 +98,14 @@ castable! {
///
/// - returns: color
///
-/// ## Category
-/// construct
+/// Display: Luma
+/// Category: construct
#[func]
pub fn luma(args: &mut Args) -> SourceResult<Value> {
let Component(luma) = args.expect("gray component")?;
Ok(Value::Color(LumaColor::new(luma).into()))
}
-/// # RGBA
/// Create an RGB(A) color.
///
/// The color is specified in the sRGB color space.
@@ -154,8 +150,8 @@ pub fn luma(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: color
///
-/// ## Category
-/// construct
+/// Display: RGBA
+/// Category: construct
#[func]
pub fn rgb(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Color(if let Some(string) = args.find::<Spanned<EcoString>>()? {
@@ -175,7 +171,7 @@ pub fn rgb(args: &mut Args) -> SourceResult<Value> {
/// An integer or ratio component.
struct Component(u8);
-castable! {
+cast_from_value! {
Component,
v: i64 => match v {
0 ..= 255 => Self(v as u8),
@@ -188,7 +184,6 @@ castable! {
},
}
-/// # CMYK
/// Create a CMYK color.
///
/// This is useful if you want to target a specific printer. The conversion
@@ -217,8 +212,8 @@ castable! {
///
/// - returns: color
///
-/// ## Category
-/// construct
+/// Display: CMYK
+/// Category: construct
#[func]
pub fn cmyk(args: &mut Args) -> SourceResult<Value> {
let RatioComponent(c) = args.expect("cyan component")?;
@@ -231,7 +226,7 @@ pub fn cmyk(args: &mut Args) -> SourceResult<Value> {
/// A component that must be a ratio.
struct RatioComponent(u8);
-castable! {
+cast_from_value! {
RatioComponent,
v: Ratio => if (0.0 ..= 1.0).contains(&v.get()) {
Self((v.get() * 255.0).round() as u8)
@@ -240,7 +235,6 @@ castable! {
},
}
-/// # Symbol
/// Create a custom symbol with modifiers.
///
/// ## Example
@@ -272,8 +266,8 @@ castable! {
///
/// - returns: symbol
///
-/// ## Category
-/// construct
+/// Display: Symbol
+/// Category: construct
#[func]
pub fn symbol(args: &mut Args) -> SourceResult<Value> {
let mut list = EcoVec::new();
@@ -289,7 +283,7 @@ pub fn symbol(args: &mut Args) -> SourceResult<Value> {
/// A value that can be cast to a symbol.
struct Variant(EcoString, char);
-castable! {
+cast_from_value! {
Variant,
c: char => Self(EcoString::new(), c),
array: Array => {
@@ -301,7 +295,6 @@ castable! {
},
}
-/// # String
/// Convert a value to a string.
///
/// - Integers are formatted in base 10.
@@ -322,8 +315,8 @@ castable! {
///
/// - returns: string
///
-/// ## Category
-/// construct
+/// Display: String
+/// Category: construct
#[func]
pub fn str(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Str(args.expect::<ToStr>("value")?.0))
@@ -332,7 +325,7 @@ pub fn str(args: &mut Args) -> SourceResult<Value> {
/// A value that can be cast to a string.
struct ToStr(Str);
-castable! {
+cast_from_value! {
ToStr,
v: i64 => Self(format_str!("{}", v)),
v: f64 => Self(format_str!("{}", v)),
@@ -340,7 +333,6 @@ castable! {
v: Str => Self(v),
}
-/// # Label
/// Create a label from a string.
///
/// Inserting a label into content attaches it to the closest previous element
@@ -366,14 +358,13 @@ castable! {
///
/// - returns: label
///
-/// ## Category
-/// construct
+/// Display: Label
+/// Category: construct
#[func]
pub fn label(args: &mut Args) -> SourceResult<Value> {
Ok(Value::Label(Label(args.expect("string")?)))
}
-/// # Regex
/// Create a regular expression from a string.
///
/// The result can be used as a
@@ -406,15 +397,14 @@ pub fn label(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: regex
///
-/// ## Category
-/// construct
+/// Display: Regex
+/// Category: construct
#[func]
pub fn regex(args: &mut Args) -> SourceResult<Value> {
let Spanned { v, span } = args.expect::<Spanned<EcoString>>("regular expression")?;
Ok(Regex::new(&v).at(span)?.into())
}
-/// # Range
/// Create an array consisting of a sequence of numbers.
///
/// If you pass just one positional parameter, it is interpreted as the `end` of
@@ -442,8 +432,8 @@ pub fn regex(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: array
///
-/// ## Category
-/// construct
+/// Display: Range
+/// Category: construct
#[func]
pub fn range(args: &mut Args) -> SourceResult<Value> {
let first = args.expect::<i64>("end")?;
diff --git a/library/src/compute/data.rs b/library/src/compute/data.rs
index c604be11..90d72ade 100644
--- a/library/src/compute/data.rs
+++ b/library/src/compute/data.rs
@@ -4,7 +4,6 @@ use typst::diag::{format_xml_like_error, FileError};
use crate::prelude::*;
-/// # Plain text
/// Read plain text from a file.
///
/// The file will be read and returned as a string.
@@ -23,8 +22,8 @@ use crate::prelude::*;
///
/// - returns: string
///
-/// ## Category
-/// data-loading
+/// Display: Plain text
+/// Category: data-loading
#[func]
pub fn read(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: path, span } = args.expect::<Spanned<EcoString>>("path to file")?;
@@ -38,7 +37,6 @@ pub fn read(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
Ok(Value::Str(text.into()))
}
-/// # CSV
/// Read structured data from a CSV file.
///
/// The CSV file will be read and parsed into a 2-dimensional array of strings:
@@ -68,8 +66,8 @@ pub fn read(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
///
/// - returns: array
///
-/// ## Category
-/// data-loading
+/// Display: CSV
+/// Category: data-loading
#[func]
pub fn csv(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: path, span } =
@@ -100,7 +98,7 @@ pub fn csv(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
/// The delimiter to use when parsing CSV files.
struct Delimiter(u8);
-castable! {
+cast_from_value! {
Delimiter,
v: EcoString => {
let mut chars = v.chars();
@@ -134,7 +132,6 @@ fn format_csv_error(error: csv::Error) -> String {
}
}
-/// # JSON
/// Read structured data from a JSON file.
///
/// The file must contain a valid JSON object or array. JSON objects will be
@@ -179,8 +176,8 @@ fn format_csv_error(error: csv::Error) -> String {
///
/// - returns: dictionary or array
///
-/// ## Category
-/// data-loading
+/// Display: JSON
+/// Category: data-loading
#[func]
pub fn json(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: path, span } =
@@ -222,7 +219,6 @@ fn format_json_error(error: serde_json::Error) -> String {
format!("failed to parse json file: syntax error in line {}", error.line())
}
-/// # XML
/// Read structured data from an XML file.
///
/// The XML file is parsed into an array of dictionaries and strings. XML nodes
@@ -278,8 +274,8 @@ fn format_json_error(error: serde_json::Error) -> String {
///
/// - returns: array
///
-/// ## Category
-/// data-loading
+/// Display: XML
+/// Category: data-loading
#[func]
pub fn xml(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: path, span } =
diff --git a/library/src/compute/foundations.rs b/library/src/compute/foundations.rs
index 1619fb60..710ec68e 100644
--- a/library/src/compute/foundations.rs
+++ b/library/src/compute/foundations.rs
@@ -1,6 +1,5 @@
use crate::prelude::*;
-/// # Type
/// Determine a value's type.
///
/// Returns the name of the value's type.
@@ -21,14 +20,13 @@ use crate::prelude::*;
///
/// - returns: string
///
-/// ## Category
-/// foundations
+/// Display: Type
+/// Category: foundations
#[func]
pub fn type_(args: &mut Args) -> SourceResult<Value> {
Ok(args.expect::<Value>("value")?.type_name().into())
}
-/// # Representation
/// The string representation of a value.
///
/// When inserted into content, most values are displayed as this representation
@@ -49,14 +47,13 @@ pub fn type_(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: string
///
-/// ## Category
-/// foundations
+/// Display: Representation
+/// Category: foundations
#[func]
pub fn repr(args: &mut Args) -> SourceResult<Value> {
Ok(args.expect::<Value>("value")?.repr().into())
}
-/// # Panic
/// Fail with an error.
///
/// ## Example
@@ -69,8 +66,8 @@ pub fn repr(args: &mut Args) -> SourceResult<Value> {
/// - payload: `Value` (positional)
/// The value (or message) to panic with.
///
-/// ## Category
-/// foundations
+/// Display: Panic
+/// Category: foundations
#[func]
pub fn panic(args: &mut Args) -> SourceResult<Value> {
match args.eat::<Value>()? {
@@ -79,7 +76,6 @@ pub fn panic(args: &mut Args) -> SourceResult<Value> {
}
}
-/// # Assert
/// Ensure that a condition is fulfilled.
///
/// Fails with an error if the condition is not fulfilled. Does not
@@ -96,8 +92,8 @@ pub fn panic(args: &mut Args) -> SourceResult<Value> {
/// - message: `EcoString` (named)
/// The error message when the assertion fails.
///
-/// ## Category
-/// foundations
+/// Display: Assert
+/// Category: foundations
#[func]
pub fn assert(args: &mut Args) -> SourceResult<Value> {
let check = args.expect::<bool>("condition")?;
@@ -112,7 +108,6 @@ pub fn assert(args: &mut Args) -> SourceResult<Value> {
Ok(Value::None)
}
-/// # Evaluate
/// Evaluate a string as Typst code.
///
/// This function should only be used as a last resort.
@@ -132,8 +127,8 @@ pub fn assert(args: &mut Args) -> SourceResult<Value> {
///
/// - returns: any
///
-/// ## Category
-/// foundations
+/// Display: Evaluate
+/// Category: foundations
#[func]
pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let Spanned { v: text, span } = args.expect::<Spanned<String>>("source")?;
diff --git a/library/src/compute/mod.rs b/library/src/compute/mod.rs
index cf0486db..3f6a79fc 100644
--- a/library/src/compute/mod.rs
+++ b/library/src/compute/mod.rs
@@ -1,11 +1,10 @@
//! Computational functions.
-mod calc;
+pub mod calc;
mod construct;
mod data;
mod foundations;
-pub use self::calc::*;
pub use self::construct::*;
pub use self::data::*;
pub use self::foundations::*;