Struct scopegraphs::resolve::Query
source · pub struct Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> { /* private fields */ }Expand description
A query over a scope graph. Read more here
Implementations§
source§impl<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>
impl<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>
sourcepub fn with_path_wellformedness<NPWF>(
self,
new_path_wellformedness: NPWF
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, NPWF, DWF, LO, DEq>where
NPWF: for<'a> RegexMatcher<&'a LABEL> + 'rslv,
pub fn with_path_wellformedness<NPWF>(
self,
new_path_wellformedness: NPWF
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, NPWF, DWF, LO, DEq>where
NPWF: for<'a> RegexMatcher<&'a LABEL> + 'rslv,
Add a path well-formedness to this query.
A path well-formedness can be specified using a regular expression.
Often you want to use query_regex! here.
#[derive(Label)]
pub enum Lbl {
Lexical,
Definition
}
use Lbl::*;
scopegraph.query()
.with_path_wellformedness(query_regex!(Lbl: Lexical* Definition));
sourcepub fn with_data_wellformedness<NDWF>(
self,
new_data_wellformedness: NDWF
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, NDWF, LO, DEq>where
NDWF: DataWellformedness<DATA> + 'rslv,
pub fn with_data_wellformedness<NDWF>(
self,
new_data_wellformedness: NDWF
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, NDWF, LO, DEq>where
NDWF: DataWellformedness<DATA> + 'rslv,
Add a data well-formedness to this query.
A data well-formedness must implement DataWellformedness.
Defaults to DefaultDataWellformedness, considering all data to be well-formed.
With a data well-formedness you can specify what data a scope must have to be a valid target for this query.
use scopegraphs::resolve::DataWellformedness;
struct MyData {
is_good: bool
}
struct MyDataWellformedness;
impl DataWellformedness<MyData> for MyDataWellformedness {
fn data_wf(&self, data: &MyData) -> bool {
data.is_good
}
}
scopegraph.query()
.with_data_wellformedness(MyDataWellformedness);
A data-wellformedness can be a lambda that takes a reference to DATA and returns a boolean.
use scopegraphs::resolve::DataWellformedness;
struct MyData {
is_good: bool
}
scopegraph.query()
.with_data_wellformedness(|data: &MyData| data.is_good);
sourcepub fn with_label_order<NLO>(
self,
new_label_order: NLO
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, NLO, DEq>where
NLO: LabelOrder<LABEL> + 'rslv,
pub fn with_label_order<NLO>(
self,
new_label_order: NLO
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, NLO, DEq>where
NLO: LabelOrder<LABEL> + 'rslv,
Add a label order to this query.
A label order must implement LabelOrder.
Defaults to DefaultLabelOrder, considering all labels of equal importance.
With a label order, you can specify which labels are “more important” in a query.
Specify label orders using the label_order! macro.
TODO: lower is better? from Lace.
use scopegraphs_macros::label_order;
#[derive(Label, Copy, Clone)]
pub enum Lbl {
Lexical,
Definition
}
use Lbl::*;
scopegraph.query()
.with_label_order(label_order!(Lbl: Lexical < Definition));sourcepub fn with_data_equivalence<NDEq>(
self,
new_data_equivalence: NDEq
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, NDEq>where
NDEq: DataEquivalence<DATA> + 'rslv,
pub fn with_data_equivalence<NDEq>(
self,
new_data_equivalence: NDEq
) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, NDEq>where
NDEq: DataEquivalence<DATA> + 'rslv,
Add a data equivalence to this query.
A data equivalence must implement DataEquivalence.
TODO: example (@aron?)
Trait Implementations§
source§impl<'sg: 'rslv, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Resolve<'sg, 'rslv> for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>where
LABEL: Label + Copy + Debug + Hash + Eq,
DATA: Debug,
CMPL: Completeness<LABEL, DATA>,
CMPL::GetEdgesResult<'rslv>: ScopeContainer<LABEL>,
<CMPL::GetEdgesResult<'rslv> as ScopeContainer<LABEL>>::PathContainer: PathContainer<'sg, 'rslv, LABEL, DATA>,
<<CMPL::GetEdgesResult<'rslv> as ScopeContainer<LABEL>>::PathContainer as PathContainer<'sg, 'rslv, LABEL, DATA>>::EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA> + Debug,
PWF: for<'a> RegexMatcher<&'a LABEL> + 'rslv,
DWF: DataWellformedness<DATA> + 'rslv,
LO: LabelOrder<LABEL> + 'rslv,
DEq: DataEquivalence<DATA> + 'rslv,
ResolvedPath<'sg, LABEL, DATA>: Hash + Eq,
Path<LABEL>: Clone,
'storage: 'sg,
impl<'sg: 'rslv, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Resolve<'sg, 'rslv> for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>where
LABEL: Label + Copy + Debug + Hash + Eq,
DATA: Debug,
CMPL: Completeness<LABEL, DATA>,
CMPL::GetEdgesResult<'rslv>: ScopeContainer<LABEL>,
<CMPL::GetEdgesResult<'rslv> as ScopeContainer<LABEL>>::PathContainer: PathContainer<'sg, 'rslv, LABEL, DATA>,
<<CMPL::GetEdgesResult<'rslv> as ScopeContainer<LABEL>>::PathContainer as PathContainer<'sg, 'rslv, LABEL, DATA>>::EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA> + Debug,
PWF: for<'a> RegexMatcher<&'a LABEL> + 'rslv,
DWF: DataWellformedness<DATA> + 'rslv,
LO: LabelOrder<LABEL> + 'rslv,
DEq: DataEquivalence<DATA> + 'rslv,
ResolvedPath<'sg, LABEL, DATA>: Hash + Eq,
Path<LABEL>: Clone,
'storage: 'sg,
source§fn resolve(&'rslv self, scope: Scope) -> Self::EnvContainer
fn resolve(&'rslv self, scope: Scope) -> Self::EnvContainer
Entry point of lookup-based query resolution. Performs a traversal of the scope graph that results in an environment containing all declarations matching a reference.
Type parameters:
LABEL: labels in the scope graph.DATA: Data in the scope graph.CMPL: the completeness approach (determined by the scope graph). Should be an instance ofCompleteness. This guarantees that the query resolution result will remain valid, even in the presence of future additions to the scope graph.ENVC: TheEnvContainer(determined byCMPL) used to process environments throughout the resolution process..PWF: regular expression matcher that indicates which paths are valid. The labels of all paths in the environment will match the regular expression that this matcher is derived from.DWF: Unary predicate over data that selects valid declarations.LO: Label order: the order on labels that indicates which declarations are preferred over others.DEq: Equivalence relation on data that determines which declarations can shadow each other.
Parameters:
scope: the scope graph in which to start name resolution