diff --git a/src/lib.rs b/src/lib.rs index 5acb8a907..c7e47ffac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,8 +108,8 @@ pub struct Config { pub std: Scope, /// Defines which standard library items fulfill which syntactical roles. /// - /// Default: Typst's standard library's role map. - pub roles: RoleMap, + /// Default: Typst's standard library's language map. + pub items: LangItems, /// The default properties for page size, font selection and so on. /// /// Default: Empty style map. @@ -121,15 +121,15 @@ impl Default for Config { Self { root: PathBuf::new(), std: library::scope(), + items: library::items(), styles: StyleMap::new(), - roles: library::roles(), } } } /// Definition of certain standard library items the language is aware of. #[derive(Debug, Clone, Hash)] -pub struct RoleMap { +pub struct LangItems { pub strong: fn(Content) -> Content, pub emph: fn(Content) -> Content, pub raw: fn(EcoString, Option, bool) -> Content, diff --git a/src/library/mod.rs b/src/library/mod.rs index b5a0e8ebc..17a7a681e 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -143,9 +143,9 @@ pub fn scope() -> Scope { std } -/// Construct the standard role map. -pub fn roles() -> RoleMap { - RoleMap { +/// Construct the language map. +pub fn items() -> LangItems { + LangItems { strong: |body| Content::show(text::StrongNode(body)), emph: |body| Content::show(text::EmphNode(body)), raw: |text, lang, block| { diff --git a/src/library/prelude.rs b/src/library/prelude.rs index c5a6bc8e0..dfc74ec84 100644 --- a/src/library/prelude.rs +++ b/src/library/prelude.rs @@ -22,4 +22,4 @@ pub use crate::model::{ }; pub use crate::syntax::{Span, Spanned}; pub use crate::util::EcoString; -pub use crate::{RoleMap, World}; +pub use crate::{LangItems, World}; diff --git a/src/model/eval.rs b/src/model/eval.rs index c16156cda..9051c9556 100644 --- a/src/model/eval.rs +++ b/src/model/eval.rs @@ -242,7 +242,7 @@ impl Eval for ast::Strong { type Output = Content; fn eval(&self, vm: &mut Vm) -> SourceResult { - Ok((vm.roles().strong)(self.body().eval(vm)?)) + Ok((vm.items().strong)(self.body().eval(vm)?)) } } @@ -250,7 +250,7 @@ impl Eval for ast::Emph { type Output = Content; fn eval(&self, vm: &mut Vm) -> SourceResult { - Ok((vm.roles().emph)(self.body().eval(vm)?)) + Ok((vm.items().emph)(self.body().eval(vm)?)) } } @@ -261,7 +261,7 @@ impl Eval for ast::Raw { let text = self.text().clone(); let lang = self.lang().cloned(); let block = self.block(); - Ok((vm.roles().raw)(text, lang, block)) + Ok((vm.items().raw)(text, lang, block)) } } @@ -269,7 +269,7 @@ impl Eval for ast::Link { type Output = Content; fn eval(&self, vm: &mut Vm) -> SourceResult { - Ok((vm.roles().link)(self.url().clone())) + Ok((vm.items().link)(self.url().clone())) } } @@ -285,7 +285,7 @@ impl Eval for ast::Ref { type Output = Content; fn eval(&self, vm: &mut Vm) -> SourceResult { - Ok((vm.roles().ref_)(self.get().clone())) + Ok((vm.items().ref_)(self.get().clone())) } } @@ -295,7 +295,7 @@ impl Eval for ast::Heading { fn eval(&self, vm: &mut Vm) -> SourceResult { let level = self.level(); let body = self.body().eval(vm)?; - Ok((vm.roles().heading)(level, body)) + Ok((vm.items().heading)(level, body)) } } @@ -303,7 +303,7 @@ impl Eval for ast::ListItem { type Output = Content; fn eval(&self, vm: &mut Vm) -> SourceResult { - Ok((vm.roles().list_item)(self.body().eval(vm)?)) + Ok((vm.items().list_item)(self.body().eval(vm)?)) } } @@ -313,7 +313,7 @@ impl Eval for ast::EnumItem { fn eval(&self, vm: &mut Vm) -> SourceResult { let number = self.number(); let body = self.body().eval(vm)?; - Ok((vm.roles().enum_item)(number, body)) + Ok((vm.items().enum_item)(number, body)) } } @@ -323,7 +323,7 @@ impl Eval for ast::DescItem { fn eval(&self, vm: &mut Vm) -> SourceResult { let term = self.term().eval(vm)?; let body = self.body().eval(vm)?; - Ok((vm.roles().desc_item)(term, body)) + Ok((vm.items().desc_item)(term, body)) } } diff --git a/src/model/value.rs b/src/model/value.rs index 7b594adf1..1782e4a63 100644 --- a/src/model/value.rs +++ b/src/model/value.rs @@ -124,7 +124,7 @@ impl Value { // For values which can't be shown "naturally", we return the raw // representation with typst code syntax highlighting. - v => (world.config().roles.raw)(v.repr().into(), Some("typc".into()), false), + v => (world.config().items.raw)(v.repr().into(), Some("typc".into()), false), } } } diff --git a/src/model/vm.rs b/src/model/vm.rs index 829693bcd..614e2a9f3 100644 --- a/src/model/vm.rs +++ b/src/model/vm.rs @@ -6,7 +6,7 @@ use super::{Route, Scopes, Value}; use crate::diag::{SourceError, StrResult}; use crate::syntax::{SourceId, Span}; use crate::util::PathExt; -use crate::{RoleMap, World}; +use crate::{LangItems, World}; /// A virtual machine. pub struct Vm<'a> { @@ -55,9 +55,9 @@ impl<'a> Vm<'a> { return Err("cannot access file system from here".into()); } - /// The role map. - pub fn roles(&self) -> &RoleMap { - &self.world.config().roles + /// The language items. + pub fn items(&self) -> &LangItems { + &self.world.config().items } } diff --git a/tests/typeset.rs b/tests/typeset.rs index b5c14cb3e..f3f5bfbeb 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -184,7 +184,7 @@ fn config() -> Config { Config { root: PathBuf::new(), - roles: typst::library::roles(), + items: typst::library::items(), std, styles, }