summaryrefslogtreecommitdiff
path: root/src/source.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-16 19:13:39 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-16 20:22:48 +0200
commit242b01549a472d4eeca1404b8f63427e23224253 (patch)
tree7d44ef801ce857469912a75233a1e7a1603e405e /src/source.rs
parenta741bd6b83d1e374c8218b5439e26522499cc4ae (diff)
Safe `eval` function
Diffstat (limited to 'src/source.rs')
-rw-r--r--src/source.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/source.rs b/src/source.rs
index 780e12a8..deeaef4b 100644
--- a/src/source.rs
+++ b/src/source.rs
@@ -12,7 +12,7 @@ use crate::diag::TypResult;
use crate::loading::{FileHash, Loader};
use crate::parse::{is_newline, parse, reparse};
use crate::syntax::ast::Markup;
-use crate::syntax::{self, Category, GreenNode, RedNode};
+use crate::syntax::{self, Category, GreenNode, RedNode, Span};
use crate::util::{PathExt, StrExt};
#[cfg(feature = "codespan-reporting")]
@@ -23,6 +23,11 @@ use codespan_reporting::files::{self, Files};
pub struct SourceId(u32);
impl SourceId {
+ /// Create a new source id for a file that is not part of a store.
+ pub const fn detached() -> Self {
+ Self(u32::MAX)
+ }
+
/// Create a source id from the raw underlying value.
///
/// This should only be called with values returned by
@@ -165,7 +170,12 @@ impl SourceFile {
/// Create a source file without a real id and path, usually for testing.
pub fn detached(src: impl Into<String>) -> Self {
- Self::new(SourceId(0), Path::new(""), src.into())
+ Self::new(SourceId::detached(), Path::new(""), src.into())
+ }
+
+ /// Set a synthetic span for all nodes in this file.
+ pub fn synthesize(&mut self, span: Span) {
+ Arc::make_mut(&mut self.root).synthesize(Arc::new(span));
}
/// The root node of the file's untyped green tree.