summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-syntax/src')
-rw-r--r--crates/typst-syntax/src/file.rs8
-rw-r--r--crates/typst-syntax/src/highlight.rs3
-rw-r--r--crates/typst-syntax/src/parser.rs3
-rw-r--r--crates/typst-syntax/src/source.rs2
-rw-r--r--crates/typst-syntax/src/span.rs14
5 files changed, 27 insertions, 3 deletions
diff --git a/crates/typst-syntax/src/file.rs b/crates/typst-syntax/src/file.rs
index 89aaa55e..bc7dd314 100644
--- a/crates/typst-syntax/src/file.rs
+++ b/crates/typst-syntax/src/file.rs
@@ -97,12 +97,16 @@ impl FileId {
}
/// Construct from a raw number.
- pub(crate) const fn from_raw(v: u16) -> Self {
+ ///
+ /// Should only be used with numbers retrieved via
+ /// [`into_raw`](Self::into_raw). Misuse may results in panics, but no
+ /// unsafety.
+ pub const fn from_raw(v: u16) -> Self {
Self(v)
}
/// Extract the raw underlying number.
- pub(crate) const fn into_raw(self) -> u16 {
+ pub const fn into_raw(self) -> u16 {
self.0
}
diff --git a/crates/typst-syntax/src/highlight.rs b/crates/typst-syntax/src/highlight.rs
index ddd29326..de8ed65c 100644
--- a/crates/typst-syntax/src/highlight.rs
+++ b/crates/typst-syntax/src/highlight.rs
@@ -411,9 +411,10 @@ fn highlight_html_impl(html: &mut String, node: &LinkedNode) {
#[cfg(test)]
mod tests {
- use super::*;
use std::ops::Range;
+ use super::*;
+
#[test]
fn test_highlighting() {
use Tag::*;
diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs
index dba6d69d..8c783ffe 100644
--- a/crates/typst-syntax/src/parser.rs
+++ b/crates/typst-syntax/src/parser.rs
@@ -12,6 +12,7 @@ use crate::{
/// Parses a source file.
pub fn parse(text: &str) -> SyntaxNode {
+ let _scope = typst_timing::TimingScope::new("parse");
let mut p = Parser::new(text, 0, LexMode::Markup);
markup(&mut p, true, 0, |_| false);
p.finish().into_iter().next().unwrap()
@@ -19,6 +20,7 @@ pub fn parse(text: &str) -> SyntaxNode {
/// Parses top-level code.
pub fn parse_code(text: &str) -> SyntaxNode {
+ let _scope = typst_timing::TimingScope::new("parse code");
let mut p = Parser::new(text, 0, LexMode::Code);
let m = p.marker();
p.skip();
@@ -29,6 +31,7 @@ pub fn parse_code(text: &str) -> SyntaxNode {
/// Parses top-level math.
pub fn parse_math(text: &str) -> SyntaxNode {
+ let _scope = typst_timing::TimingScope::new("parse math");
let mut p = Parser::new(text, 0, LexMode::Math);
math(&mut p, |_| false);
p.finish().into_iter().next().unwrap()
diff --git a/crates/typst-syntax/src/source.rs b/crates/typst-syntax/src/source.rs
index a2ccb5bb..3454a265 100644
--- a/crates/typst-syntax/src/source.rs
+++ b/crates/typst-syntax/src/source.rs
@@ -32,6 +32,7 @@ struct Repr {
impl Source {
/// Create a new source file.
pub fn new(id: FileId, text: String) -> Self {
+ let _scope = typst_timing::TimingScope::new("create source");
let mut root = parse(&text);
root.numberize(id, Span::FULL).unwrap();
Self(Arc::new(Repr {
@@ -75,6 +76,7 @@ impl Source {
///
/// Returns the range in the new source that was ultimately reparsed.
pub fn replace(&mut self, new: &str) -> Range<usize> {
+ let _scope = typst_timing::TimingScope::new("replace source");
let old = self.text();
let mut prefix =
diff --git a/crates/typst-syntax/src/span.rs b/crates/typst-syntax/src/span.rs
index 85745f60..0847ceea 100644
--- a/crates/typst-syntax/src/span.rs
+++ b/crates/typst-syntax/src/span.rs
@@ -83,6 +83,20 @@ impl Span {
self.0.get() & ((1 << Self::BITS) - 1)
}
+ /// Construct from a raw number.
+ ///
+ /// Should only be used with numbers retrieved via
+ /// [`into_raw`](Self::into_raw). Misuse may results in panics, but no
+ /// unsafety.
+ pub const fn from_raw(v: NonZeroU64) -> Self {
+ Self(v)
+ }
+
+ /// Extract the raw underlying number.
+ pub const fn into_raw(self) -> NonZeroU64 {
+ self.0
+ }
+
/// Return `other` if `self` is detached and `self` otherwise.
pub fn or(self, other: Self) -> Self {
if self.is_detached() {