Skip to main content

ArgDef

Struct ArgDef 

Source
pub struct ArgDef {
    pub name: Option<String>,
    pub kind: Arc<dyn FlmArgumentParser>,
    pub mode: Option<Mode>,
    pub layout: ArgLayout,
    pub opaque_wrapper: bool,
    pub scoped: Vec<Name>,
    pub events: Vec<FlmEvent>,
    pub docs: String,
    pub role: Option<Name>,
    /* private fields */
}
Expand description

The declaration of one argument of a macro, an environment or a special character sequence: the parser that reads it, the name it can be read by, the parsing mode it is read in, how its content is laid out, whether its content is kept as written under an opaque wrapper, the scoped packages available inside it, the state events it is read under, documentation, and what it holds (its role).

The parser is one field among the others (ArgDef::kind): one of the standard argument kinds (ArgStdKind) for the forms FLM provides, or a parser of a feature’s own (FlmArgumentParser) for a syntax they cannot express. Either way, minting applies the name, mode, layout, opaque wrapper, scoped packages and events declared here around the parser.

Give an argument a name whenever anything reads it: reading by name keeps working when the argument list changes later, reading by position does not.

An argument may also state its role: what the text written for it holds (a label, a citation key, the path of a file), as a dotted name that a feature registers in the registry’s namespace of argument roles. The role describes the argument for a reader of the registry; parsing and processing do not read it. See ArgDef::role.

ArgDef::new, ArgDef::named, ArgDef::mandatory and ArgDef::optional create a declaration; the builder methods mode, layout, blocks, with_opaque_wrapper, scoped, event, docs and role each change one thing. Settings given as data write an argument as its argument code, or as a map of its syntax (a structured syntax, the standard kind written as data, or a code) with the argument’s name, parsing mode, layout, opaque wrapper, scoped packages, state events, documentation and role (ArgData, which converts into an ArgDef through TryFrom; see super::codes).

Two declarations are equal (PartialEq) when every field is equal, the code they were read from included (ArgDef::code). Their parsers are compared by the bytes that identify them (FlmArgumentParser::identity), which differ for any two parsers that read differently.

Fields§

§name: Option<String>

The name the argument can be read by, when it has one.

§kind: Arc<dyn FlmArgumentParser>

The parser that reads the argument and tells FLM what it needs to know about the argument beyond reading it (FlmArgumentParser). It is a shared object, so cloning a declaration shares its parser. ArgDef::new and ArgDef::named build it from a standard kind or from a parser of one’s own.

§mode: Option<Mode>

The parsing mode the argument is read in; None reads it in the mode the command itself is written in. See ArgDef::mode.

§layout: ArgLayout

How the block-structure pass lays out the argument’s content; inline by default. See ArgDef::layout.

§opaque_wrapper: bool

Whether minting places the argument’s content under an opaque wrapper: a group of the class FlmGroupType::OpaqueWrapper, with no delimiters of its own, staged over what the argument’s reader read. The block-structure pass carries the content of such a group over as written, with no whitespace collapsed and no typographic substitution made, so the element that declared the argument reads it as typed; it reads it through the same content nodes as without the wrapper. false by default; set it with ArgDef::with_opaque_wrapper.

The wrapper is placed around whatever the argument’s reader read, for every kind and for a parser of one’s own. The reader of a characters-only group (ArgStdKind::CharsGroup) places one by construction, whatever this field says. A verbatim argument places its content under a verbatim group, which the block-structure pass carries over in the same way.

An argument declared with an opaque wrapper may not take a layout other than ArgLayout::Inline; minting reports one as MintError::LayoutOnOpaqueWrappedArgument. A scoped package declared on it is attached as on any argument (ArgDef::scoped).

§scoped: Vec<Name>

The names of the scoped packages whose declarations are available inside this argument. See ArgDef::scoped.

§events: Vec<FlmEvent>

The state events the argument is read under (FlmEvent), in the order they are declared; empty by default. See ArgDef::event.

§docs: String

Documentation of the argument. The library does not act on it; the registry keeps it with the declaration (FlmRegistry::declarations) for a program that describes what an author may write.

§role: Option<Name>

The argument role: what the argument holds, beyond how it is written, as a registered dotted name such as flm.refs.target (the label a reference points to). None, the default, says nothing about what the argument holds. See ArgDef::role.

Implementations§

Source§

impl ArgDef

Source

pub fn new(kind: impl IntoFlmArgumentParser) -> ArgDef

Creates the declaration of an argument read by kind, with no name, so that it can be read only by position. Its content is inline (ArgLayout::Inline) and not placed under an opaque wrapper by the declaration, it is read in the mode the command is written in, no scoped package is available inside it, and it declares no event.

kind is a standard kind (ArgDef::new(ArgStdKind::Star)), a parser of one’s own passed by value, or a parser already shared as Arc<dyn FlmArgumentParser>; IntoFlmArgumentParser converts all three.

Source

pub fn code(&self) -> Option<&str>

The argument code this declaration was read from: "[", "r()". A declaration has one when it was made from a code, by arg_def_from_code (every reader of settings given as data reads its codes through it) or from a code read already (ArgCode, through From). None for a declaration built from a standard kind or a parser (ArgDef::new and the constructors built on it), and for one read from a structured syntax, whose standard kind the parser returns (FlmArgumentParser::std_kind).

A program that writes a declaration back as data writes it in the form it was read from, so that it reads back the same:

  • a declaration read from a code writes this code: the parser object alone does not say which code chose it ({ and m choose the same parser);
  • any other declaration whose parser is a standard kind writes the structured syntax, the kind written as data under the key syntax (see ArgStdKind); this covers a declaration read from a structured syntax and one built in Rust from a standard kind;
  • a declaration whose parser is a feature’s own writes neither, and does not read back.

ArgDataFields’ conversion from an ArgDef follows this rule. The builder methods leave the code as it is; a caller that replaces kind after reading a code makes the code describe a parser the declaration no longer holds.

use flm_core::lang::mint::{arg_def_from_code, ArgDef, ArgStdKind};

assert_eq!(arg_def_from_code("m").unwrap().code(), Some("m"));
assert_eq!(ArgDef::new(ArgStdKind::Mandatory).code(), None);
Source

pub fn arg_code(&self) -> Option<&ArgCode>

The argument code this declaration was read from, with the standard kind it stands for (ArgCode); None where ArgDef::code is None. A program that holds declarations in a form of its own takes the code from here, already read, and makes the declaration again from it through From, without reading the code again.

Source

pub fn named( name: impl Into<String>, kind: impl IntoFlmArgumentParser, ) -> ArgDef

Creates the declaration of an argument read by kind, which can be read by name. Everything else is as for ArgDef::new.

Source

pub fn mandatory(name: impl Into<String>) -> ArgDef

Creates the declaration of a mandatory {…} argument named name; shorthand for ArgDef::named(name, ArgStdKind::Mandatory).

Source

pub fn optional(name: impl Into<String>) -> ArgDef

Creates the declaration of an optional […] argument named name; shorthand for ArgDef::named(name, ArgStdKind::Optional).

Source

pub fn mode(self, mode: Mode) -> ArgDef

Builder: sets the parsing mode the argument is read in. Without it, the argument is read in the mode the command is written in.

Mode::Math reads the argument as mathematics wherever the command is written. Mode::Text restores the innermost non-mathematics context that encloses the command, with its mode and its token rules; this is how \text{…} inside mathematics holds ordinary document content. Outside mathematics, Mode::Text changes nothing. The two values mean the same on an environment’s body (BodyDef::mode).

Source

pub fn layout(self, layout: ArgLayout) -> ArgDef

Builder: sets how the block-structure pass lays out the argument’s content: inline content (the default), a region of blocks, or whichever of the two the content calls for. See ArgLayout.

An argument declared with an opaque wrapper (ArgDef::with_opaque_wrapper) may not take a layout other than ArgLayout::Inline, and an argument read in mathematics mode may not take ArgLayout::Blocks. Minting reports a declaration that breaks either rule (MintError::LayoutOnOpaqueWrappedArgument, MintError::BlocksOnMathArgument) and lays the argument out inline.

use flm_core::lang::mint::{ArgDef, ArgLayout};

// A note whose text may be one line of running text or several
// paragraphs, as the author writes it.
let text = ArgDef::mandatory("text").layout(ArgLayout::InlineOrBlocks);
assert_eq!(text.layout, ArgLayout::InlineOrBlocks);
Source

pub fn blocks(self) -> ArgDef

Builder: the argument’s content is a region of blocks; shorthand for .layout(ArgLayout::Blocks).

Source

pub fn with_opaque_wrapper(self) -> ArgDef

Builder: places the argument’s content under an opaque wrapper (ArgDef::opaque_wrapper, which states what the wrapper does and what the declaration then admits), for an argument whose text the element reads as typed, such as a citation key or the target of a link.

Source

pub fn scoped(self, package: impl Into<Name>) -> ArgDef

Builder: makes the declarations of one more scoped package, given by name, available inside this argument, as BodyDef::scoped does for an environment’s body.

This is how a command gives one of its arguments commands of its own: a note whose optional argument accepts \label{…}, while \label is not defined in the running text. While the argument is parsed, the scoped package is the innermost techy package of the parsing state’s scope stack, so its declarations shadow any other definition of the same names inside the argument.

Some feature must declare a scoped package of that name; the order in which the features register does not matter. A name that no feature declares is reported as MintError::UnknownScopedPackage, unless the feature that refers to it declared the name as a peer (FeatureBuilder::peer_scoped_package). A package that another feature owns may be absent from a registry; the argument then makes no command available through it, and a command the package would define is an unknown command there. Scoped packages that refer to each other in a cycle are reported as MintError::ScopedPackageCycle.

The package is attached to the parsing state of the argument whatever its reader. Inside a reading that recognizes no command, such as a characters-only group or a verbatim argument, its declarations are not reachable, and nothing is reported.

use flm_core::lang::mint::ArgDef;

let labels = ArgDef::optional("labels").scoped("my.labels");
assert_eq!(labels.scoped, ["my.labels"]);
Source

pub fn event(self, event: FlmEvent) -> ArgDef

Builder: adds one more state event (FlmEvent) that the argument is read under, after those declared before.

An event asks the parse for a state computed where the command is written: FlmEvent::StandardState reads the argument under the standard state of the parse, whatever state the command is written in, and FlmEvent::StandardScope under the standard scope with the token rules of the place of the command. The three fields that declare a change of state are applied as one change: what the events resolve to first, in the order listed, then the mode and the scoped packages. So an argument can be read under the standard state, in mathematics, with a scoped package of its own.

FlmEvent::ExitMathContext asks for what .mode(Mode::Text) asks for; the mode is the documented way to leave mathematics, and declaring both changes nothing more.

use flm_core::lang::FlmEvent;
use flm_core::lang::mint::ArgDef;

// A caption that holds ordinary document content wherever the
// command is written.
let caption = ArgDef::mandatory("caption").event(FlmEvent::StandardState);
assert_eq!(caption.events, [FlmEvent::StandardState]);
Source

pub fn docs(self, docs: impl Into<String>) -> ArgDef

Builder: sets the argument’s documentation.

Source

pub fn role(self, name: impl Into<Name>) -> ArgDef

Builder: sets the argument’s role, the registered name of what the argument holds, replacing any role set before.

The syntax of an argument says how it is written (a group of characters, raw text up to a closing brace); its role says what the written text is: a label, a citation key, the path of an image file. A program that describes the language reads the role, for example to show that the argument of \ref and the argument of \eqref hold the same kind of thing. Parsing and processing do not read it, and the role is not an input of the registry digest.

A role is an entity of the registry, in a namespace of its own, the argument roles. A feature declares a role with FeatureBuilder::argument_role, giving its name and a description. A feature may set a role that another feature declares; when that feature may be absent from a registry, the feature using the role declares it as a peer (FeatureBuilder::peer_argument_role). When the registry is built, a role that no feature declares, and that the feature setting it did not declare as a peer, is refused as a BuildError::UndeclaredArgumentRole.

use flm_core::lang::mint::{ArgDef, ArgStdKind};

let target = ArgDef::named("target", ArgStdKind::CharsGroup).role("flm.refs.target");
assert_eq!(target.role.as_ref().map(|name| name.as_str()), Some("flm.refs.target"));
assert!(ArgDef::mandatory("text").role.is_none());

Trait Implementations§

Source§

impl Clone for ArgDef

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 ArgDef

Source§

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

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

impl<'de> Deserialize<'de> for ArgDef

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ArgDef

Source§

impl From<&ArgDef> for ArgDataFields

Writes a declaration as an argument’s map, as ArgDef::code states a declaration is written back: with the code it was read from, when it has one; otherwise with the structured syntax of its parser’s standard kind (FlmArgumentParser::std_kind); otherwise with neither, for a parser of a feature’s own. A map written with neither does not read back. The declaration’s other fields are copied.

Source§

fn from(arg: &ArgDef) -> ArgDataFields

Converts to this type from the input type.
Source§

impl From<ArgCode> for ArgDef

The declaration of an argument read by the standard kind code stands for, with no name, inline layout and no scoped package, which keeps the code (ArgDef::code, ArgDef::arg_code). The code is not read again.

Source§

fn from(code: ArgCode) -> ArgDef

Converts to this type from the input type.
Source§

impl JsonSchema for ArgDef

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for ArgDef

Source§

fn eq(&self, other: &ArgDef) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl TryFrom<ArgData> for ArgDef

Source§

type Error = ArgDataError

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

fn try_from(data: ArgData) -> Result<ArgDef, ArgDataError>

Performs the conversion.

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

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

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> 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> SettingsData for T

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.