pub trait Backend {
type Language;
type Query;
type Tree;
// Required methods
fn compile(
&mut self,
language: &Self::Language,
source: &str,
) -> Result<Query<Self::Query>, Error>;
fn parse(
&mut self,
language: &Self::Language,
source: &str,
ranges: &[Range<usize>],
) -> Result<Self::Tree, Error>;
fn matches(
&mut self,
query: &Query<Self::Query>,
tree: &Self::Tree,
source: &str,
) -> Result<Vec<Match>, Error>;
// Provided methods
fn parse_incremental(
&mut self,
language: &Self::Language,
source: &str,
ranges: &[Range<usize>],
_previous: Option<Self::Tree>,
_edit: Option<&Edit>,
) -> Result<Self::Tree, Error> { ... }
fn prepare_source(&mut self, _source: &str) -> Result<(), Error> { ... }
fn parse_prepared(
&mut self,
language: &Self::Language,
source: &str,
ranges: &[Range<usize>],
previous: Option<Self::Tree>,
edit: Option<&Edit>,
) -> Result<Self::Tree, Error> { ... }
}Expand description
A parser adapter that reports UTF-8 byte ranges and keeps query matches intact.
Required Associated Types§
Required Methods§
Sourcefn compile(
&mut self,
language: &Self::Language,
source: &str,
) -> Result<Query<Self::Query>, Error>
fn compile( &mut self, language: &Self::Language, source: &str, ) -> Result<Query<Self::Query>, Error>
Compile a query and convert its pattern metadata to the shared format.
§Errors
Return an error for invalid query syntax or unsupported predicates or properties.
Sourcefn parse(
&mut self,
language: &Self::Language,
source: &str,
ranges: &[Range<usize>],
) -> Result<Self::Tree, Error>
fn parse( &mut self, language: &Self::Language, source: &str, ranges: &[Range<usize>], ) -> Result<Self::Tree, Error>
Parse the source using the given included UTF-8 byte ranges.
Included ranges preserve source coordinates rather than concatenating text.
§Errors
Return an error when the runtime rejects the language, ranges, or parse.
Sourcefn matches(
&mut self,
query: &Query<Self::Query>,
tree: &Self::Tree,
source: &str,
) -> Result<Vec<Match>, Error>
fn matches( &mut self, query: &Query<Self::Query>, tree: &Self::Tree, source: &str, ) -> Result<Vec<Match>, Error>
Collect complete query matches in runtime order, using UTF-8 byte ranges.
Pattern and capture indices must refer to the supplied query. Built-in text
predicates are evaluated by the runtime. Custom predicates are evaluated by
Query::filtered.
§Errors
Return an error for runtime failures, invalid coordinates, or match limits.
Provided Methods§
Sourcefn parse_incremental(
&mut self,
language: &Self::Language,
source: &str,
ranges: &[Range<usize>],
_previous: Option<Self::Tree>,
_edit: Option<&Edit>,
) -> Result<Self::Tree, Error>
fn parse_incremental( &mut self, language: &Self::Language, source: &str, ranges: &[Range<usize>], _previous: Option<Self::Tree>, _edit: Option<&Edit>, ) -> Result<Self::Tree, Error>
Parse using an edited previous tree when supported by this backend. The default implementation performs a full parse and drops the old tree.
Sourcefn prepare_source(&mut self, _source: &str) -> Result<(), Error>
fn prepare_source(&mut self, _source: &str) -> Result<(), Error>
Prepare source coordinates for reuse across parses of the same source version.
Call again whenever the source changes, including same-length edits. Backends that need no preparation can use the default implementation.
§Errors
Returns an error if the source cannot be represented by the runtime.
Sourcefn parse_prepared(
&mut self,
language: &Self::Language,
source: &str,
ranges: &[Range<usize>],
previous: Option<Self::Tree>,
edit: Option<&Edit>,
) -> Result<Self::Tree, Error>
fn parse_prepared( &mut self, language: &Self::Language, source: &str, ranges: &[Range<usize>], previous: Option<Self::Tree>, edit: Option<&Edit>, ) -> Result<Self::Tree, Error>
Parse a layer after calling Self::prepare_source for the same source version.
The default implementation delegates to Self::parse_incremental.
§Errors
Returns an error when the runtime rejects the source, language, or ranges.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".