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 in the order in which the language stacks
the features’ definitions (see elements), so
that, in a parsing mode, 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
impl Declarations
Sourcepub fn elements(&self) -> &[ElementDef]
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 declarations come in the order in which the language stacks the
features’ definitions, so that, in a parsing mode, the last
declaration of a command is the one in force. The weak declarations
(ElementDef::weak) of every feature come first, then the ordinary
ones. In each of these two parts, the features come in the order of
each feature’s first element declaration, a later feature’s definition
of a command replacing an earlier one’s: 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 of one part are in the
order it made them, its finalizers’ last.
Sourcepub fn scoped_packages(&self) -> &[ScopedPackageDef]
pub fn scoped_packages(&self) -> &[ScopedPackageDef]
Every scoped package, with the element declarations it holds, in registration order.
Sourcepub fn fallbacks(&self) -> &[FallbackDef]
pub fn fallbacks(&self) -> &[FallbackDef]
Every fallback, in registration order.
Sourcepub fn overrides(&self) -> &[OverrideDef]
pub fn overrides(&self) -> &[OverrideDef]
Every override, in registration order.
Sourcepub fn elements_of<'a>(
&'a self,
feature: &'a str,
) -> impl Iterator<Item = &'a ElementDef> + 'a
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 of elements: its
weak declarations first, then its ordinary ones, each in the order it
made them. The declarations of its scoped
packages are not among them: see
scoped_packages_of.
Sourcepub fn scoped_packages_of<'a>(
&'a self,
feature: &'a str,
) -> impl Iterator<Item = &'a ScopedPackageDef> + 'a
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.
Sourcepub fn named(&self, kind: CallableKind, name: &str) -> Vec<&ElementDef>
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 ordinary definition of the feature whose definitions the language
stacks last, or the weak one of that feature when no feature defines
the command ordinarily in that mode). Only the declarations
that features made directly are searched; a scoped package’s command
is found through scoped_package.
Sourcepub fn scoped_package(&self, name: &str) -> Option<&ScopedPackageDef>
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.
Sourcepub fn scoped_package_uses(&self, name: &str) -> Vec<ScopedPackageUse<'_>>
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.
Sourcepub fn arguments(&self) -> Vec<ArgumentRef<'_>>
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.
Trait Implementations§
Source§impl Clone for Declarations
impl Clone for Declarations
Auto Trait Implementations§
impl !RefUnwindSafe for Declarations
impl !UnwindSafe for Declarations
impl Forget for Declarations
impl Freeze for Declarationswhere
*const u8 is !null: Freeze,
PhantomData<ElementDef>: Freeze,
PhantomData<ScopedPackageDef>: Freeze,
PhantomData<FallbackDef>: Freeze,
PhantomData<OverrideDef>: Freeze,
impl Move for Declarations
impl Send for Declarationswhere
RawVecInner: Send,
Arc<str>: Send,
Arc<dyn FlmArgumentParser>: Send,
Arc<dyn FlmBodyParser>: Send,
Arc<ElementSpec>: Send,
impl Sync for Declarationswhere
RawVecInner: Sync,
Arc<str>: Sync,
Arc<dyn FlmArgumentParser>: Sync,
Arc<dyn FlmBodyParser>: Sync,
Arc<ElementSpec>: Sync,
impl Unpin for Declarationswhere
*const u8 is !null: Unpin,
Arc<str>: Unpin,
Arc<dyn FlmArgumentParser>: Unpin,
Arc<dyn FlmBodyParser>: Unpin,
Arc<ElementSpec>: Unpin,
impl UnsafeUnpin for Declarationswhere
*const u8 is !null: UnsafeUnpin,
PhantomData<ElementDef>: UnsafeUnpin,
PhantomData<ScopedPackageDef>: UnsafeUnpin,
PhantomData<FallbackDef>: UnsafeUnpin,
PhantomData<OverrideDef>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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