diff options
| author | cAttte <26514199+cAttte@users.noreply.github.com> | 2025-06-12 11:09:37 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-12 14:09:37 +0000 |
| commit | f9897479d2a8a865c4033bc44ec9a85fb5000795 (patch) | |
| tree | 498f159589cb1cf14c171a31750189023cad8327 /crates/typst-library | |
| parent | bd41fb9427f3965b91ac467fe12045bbb793b5e9 (diff) | |
Unify `EvalMode` and `LexMode` into `SyntaxMode` (#6432)
Diffstat (limited to 'crates/typst-library')
| -rw-r--r-- | crates/typst-library/src/foundations/cast.rs | 17 | ||||
| -rw-r--r-- | crates/typst-library/src/foundations/mod.rs | 6 | ||||
| -rw-r--r-- | crates/typst-library/src/model/bibliography.rs | 6 | ||||
| -rw-r--r-- | crates/typst-library/src/routines.rs | 15 |
4 files changed, 24 insertions, 20 deletions
diff --git a/crates/typst-library/src/foundations/cast.rs b/crates/typst-library/src/foundations/cast.rs index 73645491..5e0ba688 100644 --- a/crates/typst-library/src/foundations/cast.rs +++ b/crates/typst-library/src/foundations/cast.rs @@ -9,7 +9,7 @@ use std::ops::Add; use ecow::eco_format; use smallvec::SmallVec; -use typst_syntax::{Span, Spanned}; +use typst_syntax::{Span, Spanned, SyntaxMode}; use unicode_math_class::MathClass; use crate::diag::{At, HintedStrResult, HintedString, SourceResult, StrResult}; @@ -460,6 +460,21 @@ impl FromValue for Never { } cast! { + SyntaxMode, + self => IntoValue::into_value(match self { + SyntaxMode::Markup => "markup", + SyntaxMode::Math => "math", + SyntaxMode::Code => "code", + }), + /// Evaluate as markup, as in a Typst file. + "markup" => SyntaxMode::Markup, + /// Evaluate as math, as in an equation. + "math" => SyntaxMode::Math, + /// Evaluate as code, as after a hash. + "code" => SyntaxMode::Code, +} + +cast! { MathClass, self => IntoValue::into_value(match self { MathClass::Normal => "normal", diff --git a/crates/typst-library/src/foundations/mod.rs b/crates/typst-library/src/foundations/mod.rs index d42be15b..6840f855 100644 --- a/crates/typst-library/src/foundations/mod.rs +++ b/crates/typst-library/src/foundations/mod.rs @@ -69,6 +69,7 @@ pub use self::ty::*; pub use self::value::*; pub use self::version::*; pub use typst_macros::{scope, ty}; +use typst_syntax::SyntaxMode; #[rustfmt::skip] #[doc(hidden)] @@ -83,7 +84,6 @@ use typst_syntax::Spanned; use crate::diag::{bail, SourceResult, StrResult}; use crate::engine::Engine; -use crate::routines::EvalMode; use crate::{Feature, Features}; /// Hook up all `foundations` definitions. @@ -273,8 +273,8 @@ pub fn eval( /// #eval("1_2^3", mode: "math") /// ``` #[named] - #[default(EvalMode::Code)] - mode: EvalMode, + #[default(SyntaxMode::Code)] + mode: SyntaxMode, /// A scope of definitions that are made available. /// /// ```example diff --git a/crates/typst-library/src/model/bibliography.rs b/crates/typst-library/src/model/bibliography.rs index a85efc81..7bfacfc6 100644 --- a/crates/typst-library/src/model/bibliography.rs +++ b/crates/typst-library/src/model/bibliography.rs @@ -16,7 +16,7 @@ use hayagriva::{ }; use indexmap::IndexMap; use smallvec::{smallvec, SmallVec}; -use typst_syntax::{Span, Spanned}; +use typst_syntax::{Span, Spanned, SyntaxMode}; use typst_utils::{Get, ManuallyHash, NonZeroExt, PicoStr}; use crate::diag::{ @@ -39,7 +39,7 @@ use crate::model::{ CitationForm, CiteGroup, Destination, FootnoteElem, HeadingElem, LinkElem, ParElem, Url, }; -use crate::routines::{EvalMode, Routines}; +use crate::routines::Routines; use crate::text::{ FontStyle, Lang, LocalName, Region, Smallcaps, SubElem, SuperElem, TextElem, WeightDelta, @@ -1024,7 +1024,7 @@ impl ElemRenderer<'_> { Sink::new().track_mut(), math, self.span, - EvalMode::Math, + SyntaxMode::Math, Scope::new(), ) .map(Value::display) diff --git a/crates/typst-library/src/routines.rs b/crates/typst-library/src/routines.rs index 6f0cb32b..59ce8328 100644 --- a/crates/typst-library/src/routines.rs +++ b/crates/typst-library/src/routines.rs @@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher}; use std::num::NonZeroUsize; use comemo::{Tracked, TrackedMut}; -use typst_syntax::Span; +use typst_syntax::{Span, SyntaxMode}; use typst_utils::LazyHash; use crate::diag::SourceResult; @@ -58,7 +58,7 @@ routines! { sink: TrackedMut<Sink>, string: &str, span: Span, - mode: EvalMode, + mode: SyntaxMode, scope: Scope, ) -> SourceResult<Value> @@ -312,17 +312,6 @@ routines! { ) -> SourceResult<Fragment> } -/// In which mode to evaluate a string. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)] -pub enum EvalMode { - /// Evaluate as code, as after a hash. - Code, - /// Evaluate as markup, like in a Typst file. - Markup, - /// Evaluate as math, as in an equation. - Math, -} - /// Defines what kind of realization we are performing. pub enum RealizationKind<'a> { /// This the root realization for layout. Requires a mutable reference |
