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: ArgLayoutHow the block-structure pass lays out
the argument’s content; inline by default. See ArgDef::layout.
opaque_wrapper: boolWhether 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: StringDocumentation 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
impl ArgDef
Sourcepub fn new(kind: impl IntoFlmArgumentParser) -> ArgDef
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.
Sourcepub fn code(&self) -> Option<&str>
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 (
{andmchoose 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(seeArgStdKind); 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);Sourcepub fn arg_code(&self) -> Option<&ArgCode>
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.
Sourcepub fn named(
name: impl Into<String>,
kind: impl IntoFlmArgumentParser,
) -> ArgDef
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.
Sourcepub fn mandatory(name: impl Into<String>) -> ArgDef
pub fn mandatory(name: impl Into<String>) -> ArgDef
Creates the declaration of a mandatory {…} argument named name;
shorthand for ArgDef::named(name, ArgStdKind::Mandatory).
Sourcepub fn optional(name: impl Into<String>) -> ArgDef
pub fn optional(name: impl Into<String>) -> ArgDef
Creates the declaration of an optional […] argument named name;
shorthand for ArgDef::named(name, ArgStdKind::Optional).
Sourcepub fn mode(self, mode: Mode) -> ArgDef
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).
Sourcepub fn layout(self, layout: ArgLayout) -> ArgDef
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);Sourcepub fn blocks(self) -> ArgDef
pub fn blocks(self) -> ArgDef
Builder: the argument’s content is a region of blocks; shorthand for
.layout(ArgLayout::Blocks).
Sourcepub fn with_opaque_wrapper(self) -> ArgDef
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.
Sourcepub fn scoped(self, package: impl Into<Name>) -> ArgDef
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"]);Sourcepub fn event(self, event: FlmEvent) -> ArgDef
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]);Sourcepub fn docs(self, docs: impl Into<String>) -> ArgDef
pub fn docs(self, docs: impl Into<String>) -> ArgDef
Builder: sets the argument’s documentation.
Sourcepub fn role(self, name: impl Into<Name>) -> ArgDef
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<'de> Deserialize<'de> for ArgDef
impl<'de> Deserialize<'de> for ArgDef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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.
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
fn from(arg: &ArgDef) -> ArgDataFields
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.
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§impl JsonSchema for ArgDef
impl JsonSchema for ArgDef
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ArgDef
impl !UnwindSafe for ArgDef
impl Forget for ArgDef
impl Freeze for ArgDefwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<dyn FlmArgumentParser> is !null: Freeze,
PhantomData<ArcInner<dyn FlmArgumentParser>>: Freeze,
PhantomData<Name>: Freeze,
PhantomData<FlmEvent>: Freeze,
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
PhantomData<char>: Freeze,
PhantomData<TackOnField>: Freeze,
impl Move for ArgDef
impl Send for ArgDef
impl Sync for ArgDef
impl Unpin for ArgDef
impl UnsafeUnpin for ArgDefwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<dyn FlmArgumentParser> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn FlmArgumentParser>>: UnsafeUnpin,
PhantomData<Name>: UnsafeUnpin,
PhantomData<FlmEvent>: UnsafeUnpin,
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
PhantomData<char>: UnsafeUnpin,
PhantomData<TackOnField>: 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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