summaryrefslogtreecommitdiff
path: root/crates/typst-syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-11-25 16:10:28 +0100
committerLaurenz <laurmaedje@gmail.com>2023-11-26 19:03:21 +0100
commit85b1d1d4dd4628d1fb8901c3280cde84da450bbe (patch)
treeb69a629be9295268e071667b1587a5701f2bc7ef /crates/typst-syntax
parent2f795b5c07171affa0709195a9dae3ed5c0afbeb (diff)
Rework `Vt` into `Engine`
- Moves as much data out of the `Vm` - Removes duplication with call_vm and call_vt flavours - Uses tracked chain instead of fixed int for determining max nesting depth - This means that nesting checks now generalizes to layout and realization, to detect crashing show rules and overly nested layouts
Diffstat (limited to 'crates/typst-syntax')
-rw-r--r--crates/typst-syntax/src/span.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/typst-syntax/src/span.rs b/crates/typst-syntax/src/span.rs
index 14e5e216..8138a316 100644
--- a/crates/typst-syntax/src/span.rs
+++ b/crates/typst-syntax/src/span.rs
@@ -2,6 +2,8 @@ use std::fmt::{self, Debug, Formatter};
use std::num::NonZeroU64;
use std::ops::Range;
+use ecow::EcoString;
+
use crate::FileId;
/// A unique identifier for a syntax node.
@@ -80,6 +82,14 @@ impl Span {
pub const fn number(self) -> u64 {
self.0.get() & ((1 << Self::BITS) - 1)
}
+
+ /// Resolve a file location relative to this span's source.
+ pub fn resolve_path(self, path: &str) -> Result<FileId, EcoString> {
+ let Some(file) = self.id() else {
+ return Err("cannot access file system from here".into());
+ };
+ Ok(file.join(path))
+ }
}
/// A value with a span locating it in the source code.