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>

source

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));
     
source

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);
source

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));
source

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,

source§

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 of Completeness. This guarantees that the query resolution result will remain valid, even in the presence of future additions to the scope graph.
  • ENVC: The EnvContainer (determined by CMPL) 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
§

type EnvContainer = <<<CMPL as Completeness<LABEL, DATA>>::GetEdgesResult<'rslv> as ScopeContainer<LABEL>>::PathContainer as PathContainer<'sg, 'rslv, LABEL, DATA>>::EnvContainer where Self: 'rslv, 'sg: 'rslv

The type of result that this query gives. This depends on the completeness strategy used. Read more

Auto Trait Implementations§

§

impl<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Freeze for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>
where PWF: Freeze, DWF: Freeze, LO: Freeze, DEq: Freeze,

§

impl<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> !RefUnwindSafe for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>

§

impl<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> !Send for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>

§

impl<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> !Sync for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>

§

impl<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> Unpin for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>
where PWF: Unpin, DWF: Unpin, LO: Unpin, DEq: Unpin,

§

impl<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq> !UnwindSafe for Query<'storage, 'sg, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.