pub struct BodyDef {
pub layout: BodyLayout,
pub parser: Option<Arc<dyn FlmBodyParser>>,
pub mode: Option<Mode>,
pub opaque_wrapper: bool,
pub scoped: Vec<Name>,
pub events: Vec<FlmEvent>,
}Expand description
The declaration of an environment’s body: how it is laid out, which parser reads it, which parsing mode it is read in, whether its content is kept as written under an opaque wrapper, which scoped packages are available inside it, and which state events it is read under.
BodyDef::new (the same as BodyDef::default()) declares a body laid
out by the element’s block role, read the ordinary way, read in the mode
the environment is written in, with no opaque wrapper, with no scoped
package and with no event; each builder method changes one of these.
The body parser is one field among the others (BodyDef::parser): a body
that is not read the ordinary way (raw text, or content a feature checks as
it reads it) holds the object that reads it, and minting applies the
layout, mode, opaque wrapper, scoped packages and events declared here
around that object.
Fields§
§layout: BodyLayoutHow the block-structure pass lays out the body.
parser: Option<Arc<dyn FlmBodyParser>>The parser that reads the body, when the body is not read the ordinary
way (content up to and including \end{name}). See
BodyDef::parser.
mode: Option<Mode>The parsing mode the body is read in: Some(Mode::Math) for an
equation-like environment, Some(Mode::Text) to restore the
non-mathematics context that encloses the mathematics, None to read
the body in the mode the environment is written in.
opaque_wrapper: boolWhether minting places the body’s content under an opaque wrapper, as
ArgDef::opaque_wrapper does for an argument: a group of the class
FlmGroupType::OpaqueWrapper,
whose content the block-structure pass
carries over as written. The wrapper is placed around whatever reads
the body, the declared parser or the ordinary reading, and the content
designated as the body’s stays the same nodes. false by default; set
it with BodyDef::with_opaque_wrapper.
A body declared with an opaque wrapper may not declare a layout other
than BodyLayout::FromRole; minting reports one as
MintError::LayoutOnOpaqueWrappedBody.
A scoped package declared on it is attached as on any body
(BodyDef::scoped).
scoped: Vec<Name>The names of the scoped packages whose
declarations are available inside this body, such as the package that
defines \item inside a list environment. See BodyDef::scoped.
events: Vec<FlmEvent>The state events the body is read under (FlmEvent), in the order
they are declared; empty by default. See BodyDef::event.
Implementations§
Source§impl BodyDef
impl BodyDef
Sourcepub fn new() -> BodyDef
pub fn new() -> BodyDef
Creates the declaration of a body read the ordinary way, laid out by
the element’s block role (BodyLayout::FromRole), read in the mode
the environment is written in, with no opaque wrapper, no scoped
package and no event. The same as BodyDef::default().
Sourcepub fn layout(self, layout: BodyLayout) -> BodyDef
pub fn layout(self, layout: BodyLayout) -> BodyDef
Builder: sets how the body is laid out.
Sourcepub fn blocks(self) -> BodyDef
pub fn blocks(self) -> BodyDef
Builder: the body is a region of blocks; shorthand for
.layout(BodyLayout::Blocks).
Sourcepub fn verbatim(self) -> BodyDef
pub fn verbatim(self) -> BodyDef
Builder: the body is raw text, read by FLM’s verbatim reader
(crate::lang::verbatim), which places the content under a group of
the verbatim class; shorthand for
.parser(FlmVerbatimBehavior::new()).
Sourcepub fn parser(self, parser: impl IntoFlmBodyParser) -> BodyDef
pub fn parser(self, parser: impl IntoFlmBodyParser) -> BodyDef
Builder: sets the parser that reads the body (FlmBodyParser), for
a body not read the ordinary way: FLM’s verbatim reader
(BodyDef::verbatim), or a feature’s own parser, such as one that
reads the ordinary content and then checks it.
Only the parser’s reading of the body is used: the environment’s
arguments are those of the declaration, the body is read under the
mode, the scoped packages and the events declared here, and what the
parser read is placed under an opaque wrapper when the declaration asks for one
(BodyDef::with_opaque_wrapper).
parser is a parser passed by value, or one already shared as
Arc<dyn FlmBodyParser> by several declarations; IntoFlmBodyParser
converts both.
Sourcepub fn mode(self, mode: Mode) -> BodyDef
pub fn mode(self, mode: Mode) -> BodyDef
Builder: sets the parsing mode the body is read in. Mode::Math and
Mode::Text mean what they mean for an argument (ArgDef::mode).
Sourcepub fn with_opaque_wrapper(self) -> BodyDef
pub fn with_opaque_wrapper(self) -> BodyDef
Builder: places the body’s content under an opaque wrapper
(BodyDef::opaque_wrapper, which states what the wrapper does and
what the declaration then admits).
Sourcepub fn scoped(self, package: impl Into<Name>) -> BodyDef
pub fn scoped(self, package: impl Into<Name>) -> BodyDef
Builder: makes the declarations of one more scoped package, given by
name, available inside the body. Some feature must declare a
ScopedPackageDef of that name; the rules are those of
ArgDef::scoped.
Sourcepub fn event(self, event: FlmEvent) -> BodyDef
pub fn event(self, event: FlmEvent) -> BodyDef
Builder: adds one more state event (FlmEvent) that the body is
read under, after those declared before; the rules are those of
ArgDef::event.
An environment whose body declares FlmEvent::StandardState holds
ordinary document content wherever it is written, even in a document
parsed from a restricted state:
use flm_core::lang::FlmEvent;
use flm_core::lang::mint::BodyDef;
let body = BodyDef::new().blocks().event(FlmEvent::StandardState);
assert_eq!(body.events, [FlmEvent::StandardState]);Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for BodyDef
impl !UnwindSafe for BodyDef
impl Forget for BodyDef
impl Freeze for BodyDefwhere
*const ArcInner<dyn FlmBodyParser> is !null: Freeze,
PhantomData<ArcInner<dyn FlmBodyParser>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Name>: Freeze,
PhantomData<FlmEvent>: Freeze,
impl Move for BodyDef
impl Send for BodyDef
impl Sync for BodyDef
impl Unpin for BodyDef
impl UnsafeUnpin for BodyDefwhere
*const ArcInner<dyn FlmBodyParser> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn FlmBodyParser>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Name>: UnsafeUnpin,
PhantomData<FlmEvent>: 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