oak_core/builder/
mod.rs

1use crate::{
2    Language,
3    errors::OakDiagnostics,
4    source::{Source, TextEdit},
5};
6
7/// Output of a builder operation.
8pub type BuildOutput<L: Language> = OakDiagnostics<L::TypedRoot>;
9
10/// Trait for building higher-level structures (like ASTs) from source text.
11pub trait Builder<L: Language> {
12    /// Builds the structure from the source text.
13    fn build<'a, S: Source + ?Sized>(&self, text: &S, edits: &[TextEdit], cache: &'a mut impl BuilderCache<L>) -> BuildOutput<L>;
14}
15
16/// Cache trait for builder operations used by lexers and parsers.
17///
18/// This trait defines the interface for building green tree nodes incrementally.
19/// It provides methods for adding tokens and nodes to the tree structure.
20pub trait BuilderCache<L: Language>: crate::parser::ParseCache<L> {}
21
22impl<'a, L: Language, C: BuilderCache<L> + ?Sized> BuilderCache<L> for &'a mut C {}
23
24impl<L: Language + Send + Sync + 'static> BuilderCache<L> for crate::parser::ParseSession<L> {}