mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Rename RoleMap
to LangItems
This commit is contained in:
parent
237feda063
commit
636bdb9e43
@ -108,8 +108,8 @@ pub struct Config {
|
|||||||
pub std: Scope,
|
pub std: Scope,
|
||||||
/// Defines which standard library items fulfill which syntactical roles.
|
/// Defines which standard library items fulfill which syntactical roles.
|
||||||
///
|
///
|
||||||
/// Default: Typst's standard library's role map.
|
/// Default: Typst's standard library's language map.
|
||||||
pub roles: RoleMap,
|
pub items: LangItems,
|
||||||
/// The default properties for page size, font selection and so on.
|
/// The default properties for page size, font selection and so on.
|
||||||
///
|
///
|
||||||
/// Default: Empty style map.
|
/// Default: Empty style map.
|
||||||
@ -121,15 +121,15 @@ impl Default for Config {
|
|||||||
Self {
|
Self {
|
||||||
root: PathBuf::new(),
|
root: PathBuf::new(),
|
||||||
std: library::scope(),
|
std: library::scope(),
|
||||||
|
items: library::items(),
|
||||||
styles: StyleMap::new(),
|
styles: StyleMap::new(),
|
||||||
roles: library::roles(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Definition of certain standard library items the language is aware of.
|
/// Definition of certain standard library items the language is aware of.
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
pub struct RoleMap {
|
pub struct LangItems {
|
||||||
pub strong: fn(Content) -> Content,
|
pub strong: fn(Content) -> Content,
|
||||||
pub emph: fn(Content) -> Content,
|
pub emph: fn(Content) -> Content,
|
||||||
pub raw: fn(EcoString, Option<EcoString>, bool) -> Content,
|
pub raw: fn(EcoString, Option<EcoString>, bool) -> Content,
|
||||||
|
@ -143,9 +143,9 @@ pub fn scope() -> Scope {
|
|||||||
std
|
std
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct the standard role map.
|
/// Construct the language map.
|
||||||
pub fn roles() -> RoleMap {
|
pub fn items() -> LangItems {
|
||||||
RoleMap {
|
LangItems {
|
||||||
strong: |body| Content::show(text::StrongNode(body)),
|
strong: |body| Content::show(text::StrongNode(body)),
|
||||||
emph: |body| Content::show(text::EmphNode(body)),
|
emph: |body| Content::show(text::EmphNode(body)),
|
||||||
raw: |text, lang, block| {
|
raw: |text, lang, block| {
|
||||||
|
@ -22,4 +22,4 @@ pub use crate::model::{
|
|||||||
};
|
};
|
||||||
pub use crate::syntax::{Span, Spanned};
|
pub use crate::syntax::{Span, Spanned};
|
||||||
pub use crate::util::EcoString;
|
pub use crate::util::EcoString;
|
||||||
pub use crate::{RoleMap, World};
|
pub use crate::{LangItems, World};
|
||||||
|
@ -242,7 +242,7 @@ impl Eval for ast::Strong {
|
|||||||
type Output = Content;
|
type Output = Content;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
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;
|
type Output = Content;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
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 text = self.text().clone();
|
||||||
let lang = self.lang().cloned();
|
let lang = self.lang().cloned();
|
||||||
let block = self.block();
|
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;
|
type Output = Content;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
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;
|
type Output = Content;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
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> {
|
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||||
let level = self.level();
|
let level = self.level();
|
||||||
let body = self.body().eval(vm)?;
|
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;
|
type Output = Content;
|
||||||
|
|
||||||
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
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> {
|
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||||
let number = self.number();
|
let number = self.number();
|
||||||
let body = self.body().eval(vm)?;
|
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> {
|
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
|
||||||
let term = self.term().eval(vm)?;
|
let term = self.term().eval(vm)?;
|
||||||
let body = self.body().eval(vm)?;
|
let body = self.body().eval(vm)?;
|
||||||
Ok((vm.roles().desc_item)(term, body))
|
Ok((vm.items().desc_item)(term, body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ impl Value {
|
|||||||
|
|
||||||
// For values which can't be shown "naturally", we return the raw
|
// For values which can't be shown "naturally", we return the raw
|
||||||
// representation with typst code syntax highlighting.
|
// 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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use super::{Route, Scopes, Value};
|
|||||||
use crate::diag::{SourceError, StrResult};
|
use crate::diag::{SourceError, StrResult};
|
||||||
use crate::syntax::{SourceId, Span};
|
use crate::syntax::{SourceId, Span};
|
||||||
use crate::util::PathExt;
|
use crate::util::PathExt;
|
||||||
use crate::{RoleMap, World};
|
use crate::{LangItems, World};
|
||||||
|
|
||||||
/// A virtual machine.
|
/// A virtual machine.
|
||||||
pub struct Vm<'a> {
|
pub struct Vm<'a> {
|
||||||
@ -55,9 +55,9 @@ impl<'a> Vm<'a> {
|
|||||||
return Err("cannot access file system from here".into());
|
return Err("cannot access file system from here".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The role map.
|
/// The language items.
|
||||||
pub fn roles(&self) -> &RoleMap {
|
pub fn items(&self) -> &LangItems {
|
||||||
&self.world.config().roles
|
&self.world.config().items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ fn config() -> Config {
|
|||||||
|
|
||||||
Config {
|
Config {
|
||||||
root: PathBuf::new(),
|
root: PathBuf::new(),
|
||||||
roles: typst::library::roles(),
|
items: typst::library::items(),
|
||||||
std,
|
std,
|
||||||
styles,
|
styles,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user