Skip to main content

ModelBuilder

Struct ModelBuilder 

Source
pub struct ModelBuilder { /* private fields */ }
Expand description

Mutable model under construction. Entities are keyed: frontends that meet the same symbol (tree-sitter, then SCIP) share one entity. Relations are deduplicated on (from, kind, to, provenance); each occurrence site is kept.

Ids passed to the setters must come from this builder.

Implementations§

Source§

impl ModelBuilder

Source

pub fn new() -> Self

Source

pub fn from_model(model: &Model) -> Self

A builder holding everything model holds, entity ids unchanged: derived facts (analyses) can be added to a frozen model and the result frozen again.

Source

pub fn entity(&mut self, key: &str, kind: EntityKind, name: &str) -> EntityId

Entity with key, created with kind and name if absent. An existing entity keeps its kind and name.

Source

pub fn entity_of_kind( &mut self, key: &str, kind: KindId, name: &str, ) -> EntityId

Like Self::entity with a fine kind from Self::define_kind.

Source

pub fn get(&self, key: &str) -> Option<EntityId>

Source

pub fn ids(&self) -> impl ExactSizeIterator<Item = EntityId> + use<>

Ids of every entity, in creation order.

Source

pub fn rekey(&mut self, id: EntityId, key: &str) -> Result<(), EntityId>

Gives id the key key (e.g. its SCIP symbol, found after a syntactic frontend created it). Fails with the entity already holding key, if another one does.

Source

pub fn name(&self, id: EntityId) -> &str

Source

pub fn parent(&self, id: EntityId) -> Option<EntityId>

Source

pub fn file(&self, id: EntityId) -> Option<&str>

Source

pub fn range(&self, id: EntityId) -> Option<Range>

Source

pub fn name_range(&self, id: EntityId) -> Option<Range>

Source

pub fn external(&self, id: EntityId) -> bool

Source

pub fn key(&self, id: EntityId) -> &str

Source

pub fn kind(&self, id: EntityId) -> EntityKind

Archetype of the entity’s fine kind.

Source

pub fn kind_id(&self, id: EntityId) -> KindId

Source

pub fn set_kind(&mut self, id: EntityId, kind: EntityKind)

Sets the archetype’s default (unrefined) kind.

Source

pub fn set_kind_id(&mut self, id: EntityId, kind: KindId)

Source

pub fn define_kind( &mut self, name: &str, archetype: EntityKind, traits: TraitMask, fm3: Option<&str>, ) -> KindId

Kind named name (get-or-create); see Metamodel::define.

Source

pub fn set_kind_traits(&mut self, kind: KindId, traits: TraitMask)

Sets the traits of an existing kind, e.g. of an archetype’s default kind (KindId::of(EntityKind::Class)).

Source

pub fn set_kind_concept( &mut self, kind: KindId, graphql_type: Option<&str>, graphql_root: Option<&str>, ) -> bool

Declares the GraphQL concept and root field names of a defined kind; see Metamodel::set_concept.

Source

pub fn metamodel(&self) -> &Metamodel

Source

pub fn set_parent(&mut self, id: EntityId, parent: Option<EntityId>)

Source

pub fn set_language(&mut self, id: EntityId, language: &LanguageId)

Source

pub fn set_external(&mut self, id: EntityId, external: bool)

Source

pub fn set_source( &mut self, id: EntityId, file: &str, range: Range, name_range: Option<Range>, )

Where the entity is written; file relative to the analysed root.

Source

pub fn set_prop(&mut self, id: EntityId, key: &str, value: impl Into<Value>)

Source

pub fn props_mut(&mut self, id: EntityId) -> &mut Props

Source

pub fn relate( &mut self, kind: &RelationKind, from: EntityId, to: EntityId, provenance: Provenance, )

Asserts a relation without a site (inheritance read from metadata…).

Source

pub fn occurrence( &mut self, kind: &RelationKind, from: EntityId, to: EntityId, provenance: Provenance, site: Range, )

Asserts a relation at site, a range in from’s file: sites are attributed to their innermost enclosing entity, so they share its file.

Source

pub fn occurrence_flagged( &mut self, kind: &RelationKind, from: EntityId, to: EntityId, provenance: Provenance, site: Range, flags: SiteFlags, )

Like Self::occurrence with per-site flags (read/write, receiver). The same site asserted twice keeps the union of its flags.

Source

pub fn entity_count(&self) -> usize

Source

pub fn build(self) -> Model

Trait Implementations§

Source§

impl Debug for ModelBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModelBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.