Skip to main content

Declarations

Struct Declarations 

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

The element declarations, scoped packages, fallbacks and overrides that the features of a registry declared, as declared.

The element declarations are grouped by feature, in the order in which the language stacks the features’ definitions (see elements), so that the last declaration of a command is the one in force. Everything else is in registration order.

Get it from FlmRegistry::declarations. The list accessors (elements, scoped_packages, fallbacks, overrides) return everything; the other accessors answer the usual questions of a program that describes the language: the commands of one feature (elements_of), the declarations of one command (named), a scoped package and the places that make it available (scoped_package, scoped_package_uses), and the arguments that hold a given kind of thing (arguments, role_uses).

§Examples

use std::sync::Arc;
use flm_core::core::registry::{BuildError, FeatureBuilder, FeatureInfo, FlmFeature, build_registry};
use flm_core::lang::mint::{ArgDef, CallableKind, ElementDef, SyntaxDef};
use flm_core::model::element::ElementSpec;

struct Shout;
impl FlmFeature for Shout {
    fn info(&self) -> FeatureInfo { FeatureInfo::new("shout", "Shouting") }
    fn register(&self, b: &mut FeatureBuilder<'_>) -> Result<(), BuildError> {
        let element = Arc::new(ElementSpec::new("shout.shout"));
        let syntax = SyntaxDef::Macro { args: vec![ArgDef::mandatory("text")] };
        b.element(ElementDef::new("shout", ["shout"], syntax, element).docs("Shouted text."))
    }
}

let registry = build_registry([Arc::new(Shout) as Arc<dyn FlmFeature>])?;
let found = registry.declarations().named(CallableKind::Macro, "shout");
assert_eq!(found.len(), 1);
assert_eq!(found[0].docs, "Shouted text.");
assert_eq!(found[0].syntax.args()[0].name.as_deref(), Some("text"));

Implementations§

Source§

impl Declarations

Source

pub fn elements(&self) -> &[ElementDef]

Every element declaration a feature made directly (FeatureBuilder::element), grouped by feature. The declarations held by scoped packages are not among them: see scoped_packages.

The features come in the order in which the language stacks their definitions, a later feature’s definition of a command replacing an earlier one’s: the order of each feature’s first element declaration, which is the final order of the features (FlmRegistry::features) among those that declare elements when they register. A feature whose only element declarations come from a Finalizer comes after them. Each feature’s declarations are in the order it made them, its finalizers’ last.

Source

pub fn scoped_packages(&self) -> &[ScopedPackageDef]

Every scoped package, with the element declarations it holds, in registration order.

Source

pub fn fallbacks(&self) -> &[FallbackDef]

Every fallback, in registration order.

Source

pub fn overrides(&self) -> &[OverrideDef]

Every override, in registration order.

Source

pub fn elements_of<'a>( &'a self, feature: &'a str, ) -> impl Iterator<Item = &'a ElementDef> + 'a

The element declarations that the feature called feature made directly, in the order it made them. The declarations of its scoped packages are not among them: see scoped_packages_of.

Source

pub fn scoped_packages_of<'a>( &'a self, feature: &'a str, ) -> impl Iterator<Item = &'a ScopedPackageDef> + 'a

The scoped packages that the feature called feature declared, in the order it declared them.

Source

pub fn named(&self, kind: CallableKind, name: &str) -> Vec<&ElementDef>

The element declarations, across features, that define the command name of the callable kind kind, in the order of elements. name is written without the escape character (section, itemize); for a special character sequence it is the trigger (~). A file-inclusion macro is a macro.

Several declarations define one command when their parsing modes differ (ElementDef::modes), or when one feature’s definition replaces another’s. In a given parsing mode, the definition in force is the last one in this list that is available in that mode (a feature declares a command at most once per parsing mode, so this is the definition of the feature whose definitions the language stacks last). Only the declarations that features made directly are searched; a scoped package’s command is found through scoped_package.

Source

pub fn scoped_package(&self, name: &str) -> Option<&ScopedPackageDef>

The scoped package called name, or None when no feature declares one. A registry holds at most one scoped package of a name.

Source

pub fn scoped_package_uses(&self, name: &str) -> Vec<ScopedPackageUse<'_>>

Every place where an element declaration makes the scoped package called name available: each environment body and each argument whose declaration lists the package (BodyDef::scoped, ArgDef::scoped). The declarations that features made directly come first, in the order of elements, then those held by scoped packages, in registration order. A use by a feature that declared the package as a peer is listed whether or not some feature declares the package.

Source

pub fn arguments(&self) -> Vec<ArgumentRef<'_>>

Every argument of every element declaration, including the arguments of the tack-on fields: the declarations that features made directly first, in the order of elements, then those held by scoped packages, in registration order; each declaration’s arguments come in the order written.

Source

pub fn role_uses(&self, role: &str) -> Vec<ArgumentRef<'_>>

Every argument whose role is role, in the order of arguments.

Trait Implementations§

Source§

impl Clone for Declarations

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Declarations

Source§

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

Formats the value using the given formatter. 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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.