pub struct Format {
pub shape: Option<Shape>,
pub variants: Vec<(String, FormatVariant)>,
pub key: Option<String>,
pub prohibited: Vec<Prohibition>,
pub example: Option<String>,
pub raw: Spanned,
pub patched: bool,
}Expand description
A line format (grammar format), its shapes compiled against the types
its layer sees.
Fields§
§shape: Option<Shape>The shape of a format without variants.
variants: Vec<(String, FormatVariant)>The named shapes of a variant format, in the order a line tries them.
key: Option<String>The name of the hole or group that captures the line’s key.
prohibited: Vec<Prohibition>prohibited-patterns: what no bound line may match.
example: Option<String>One conforming line of a format without variants.
raw: SpannedThe entry as written, for a printed registry and a layer on top.
patched: boolWhether its layer wrote the entry as a patch, which raw holds
merged onto the farther entry.
Implementations§
Source§impl Format
impl Format
Sourcepub fn read_with(&self, read: &dyn Fn(&str) -> String) -> Format
pub fn read_with(&self, read: &dyn Fn(&str) -> String) -> Format
The format as a format grammar reads it: each shape read through
read, as Shape::read_with reads it, and the rest as it is.
Sourcepub fn examples(&self) -> Vec<&str>
pub fn examples(&self) -> Vec<&str>
Every example the format carries: its own, or each variant’s.
Sourcepub fn reach(&self, text: &str) -> usize
pub fn reach(&self, text: &str) -> usize
How far text follows the format before it fails: the furthest
that any of its shapes reaches.
Sourcepub fn first_example(&self) -> &str
pub fn first_example(&self) -> &str
The first example, which stands for the format where one is needed.
Sourcepub fn check(&self, text: &str) -> FormatMatch
pub fn check(&self, text: &str) -> FormatMatch
Match text, squashed, against the format. A failure is built from
what the format holds, never from a sentence written to explain it:
where the shape fails and its example, or what a ban matched and the
example of the shape the line took.
Sourcepub fn check_as(&self, text: &str, noun: &str) -> FormatMatch
pub fn check_as(&self, text: &str, noun: &str) -> FormatMatch
As check, for a unit that a failure calls noun, such as item.
Sourcepub fn check_masked(&self, text: &str, masked: &str, noun: &str) -> FormatMatch
pub fn check_masked(&self, text: &str, masked: &str, noun: &str) -> FormatMatch
As check_as, where the bans read masked: text with what they
leave out, such as a code span, overwritten byte for byte, so that
every offset of text stays where it was. A failure quotes the
span as text holds it.
Sourcepub fn check_quoting(
&self,
text: &str,
masked: &str,
noun: &str,
quote: &Quote<'_>,
) -> FormatMatch
pub fn check_quoting( &self, text: &str, masked: &str, noun: &str, quote: &Quote<'_>, ) -> FormatMatch
As check_masked, for a text that a format grammar read in another
spelling: a failure quotes quote, the text as written.
Sourcepub fn shape_for(&self, text: &str) -> Option<(&Shape, &str)>
pub fn shape_for(&self, text: &str) -> Option<(&Shape, &str)>
The shape text has and its example, where it has one: the check
alone, with no failure built.
Sourcepub fn conforms(&self, text: &str) -> bool
pub fn conforms(&self, text: &str) -> bool
Whether text has the format’s shape and passes its bans, silently.
Sourcepub fn conforms_masked(&self, text: &str, masked: &str) -> bool
pub fn conforms_masked(&self, text: &str, masked: &str) -> bool
As conforms, where the bans read masked, as for check_masked.
Sourcepub fn matching(&self, text: &str) -> Result<(&Shape, &str), String>
pub fn matching(&self, text: &str) -> Result<(&Shape, &str), String>
The shape text has and its example, or why it has none. A variant
format tries its variants in order; where none matches, the one the
line follows furthest is the one it meant (TL_42).