From 6935cf8dfefff3d6cf234f077a7d61661fd5ca57 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 25 May 2022 11:46:51 +0200 Subject: Virtual machine --- src/source.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/source.rs') diff --git a/src/source.rs b/src/source.rs index cd5a453a..77a020cb 100644 --- a/src/source.rs +++ b/src/source.rs @@ -175,9 +175,12 @@ impl SourceFile { 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)); + /// Create a source file with the same synthetic span for all nodes. + pub fn synthesized(src: impl Into, span: Span) -> Self { + let mut file = Self::detached(src); + Arc::make_mut(&mut file.root).synthesize(Arc::new(span)); + file.id = span.source; + file } /// The root node of the file's untyped green tree. -- cgit v1.2.3