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,
}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.
Implementations§
Source§impl Format
impl Format
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 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.