Rename RoleMap to LangItems

This commit is contained in:
Laurenz 2022-10-31 09:11:56 +01:00
parent 237feda063
commit 636bdb9e43
7 changed files with 23 additions and 23 deletions

View File

@ -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<EcoString>, bool) -> Content,

View File

@ -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| {

View File

@ -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};

View File

@ -242,7 +242,7 @@ impl Eval for ast::Strong {
type Output = Content;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
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<Self::Output> {
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<Self::Output> {
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<Self::Output> {
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<Self::Output> {
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<Self::Output> {
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<Self::Output> {
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<Self::Output> {
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))
}
}

View File

@ -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),
}
}
}

View File

@ -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
}
}

View File

@ -184,7 +184,7 @@ fn config() -> Config {
Config {
root: PathBuf::new(),
roles: typst::library::roles(),
items: typst::library::items(),
std,
styles,
}