Skip to main content

Builder

Trait Builder 

Source
pub trait Builder<L: Language> {
    // Required method
    fn build<'a, S: Source + ?Sized>(
        &self,
        text: &S,
        edits: &[TextEdit],
        cache: &'a mut impl BuilderCache<L>,
    ) -> BuildOutput<L>;
}
Expand description

Trait for building higher-level structures (like ASTs) from a green tree.

While the [Parser] produces a generic GreenNode tree, the Builder is responsible for “lowering” or “binding” this tree into a more ergonomic, language-specific structure (e.g., an AST with typed nodes).

§Usage Scenario

The Builder is typically used after parsing to:

  1. Traverse the produced GreenNode tree.
  2. Construct typed AST nodes.
  3. Cache these typed nodes for incremental updates.

Required Methods§

Source

fn build<'a, S: Source + ?Sized>( &self, text: &S, edits: &[TextEdit], cache: &'a mut impl BuilderCache<L>, ) -> BuildOutput<L>

Builds the higher-level structure (typically an AST) from the source text.

This method is the primary entry point for converting a raw source or a syntax tree into a typed AST. It handles incremental rebuilding if edits and a cache are provided.

§Arguments
  • text - The source text to build from.
  • edits - A slice of TextEdits representing changes since the last build. Empty if building from scratch.
  • cache - A BuilderCache for incremental reuse and resource management.
§Returns

A BuildOutput containing the typed root node and any diagnostics.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§