flm_core/stdlib/features/quote/diagnostics.rs
1//! This module defines the diagnostic conditions that the [`quote`](super)
2//! feature reports (see
3//! [diagnostics](crate::guide::concepts_overview#diagnostics)). All three
4//! conditions are errors in the source of a quotation.
5//!
6//! The lowering rules of the feature report these errors on every backend.
7//! The `check` workflow ([`CHECK_WORKFLOW`](crate::stdlib::CHECK_WORKFLOW))
8//! lowers nothing, and therefore does not report them.
9
10use techy::error::DiagnosticInfo;
11
12/// The error that is reported when a quote environment such as `quote`
13/// contains content outside its quotation-section commands (id
14/// `flm.quote.bare-content`).
15///
16/// The configuration of a quote environment
17/// ([`QuoteEnvironment`](super::QuoteEnvironment)) declares the
18/// quotation-section commands (`\text`, `\lines`, `\attributed` and `\block`)
19/// that its body accepts. It can also declare a kind of quotation section for
20/// the content written outside these commands
21/// ([`bare`](super::QuoteEnvironment::bare)). If it declares none, as for the
22/// default environment `quote`, all content must be written inside the
23/// accepted commands, as in
24/// `\begin{quote}\text{Veni, vidi, vici.}\attributed{Caesar}\end{quote}`.
25/// Whitespace and comments outside the commands are allowed.
26///
27/// Reported by the lowering rule of the quote environment
28/// ([`QuoteRule`](super::QuoteRule), or
29/// [`QuoteLatexRule`](super::latex::QuoteLatexRule) on the `latex-recomposed`
30/// backend) when it is invoked. The error is reported once for each run of
31/// content outside the commands: all the content between two
32/// quotation-section commands, or before the first, or after the last. This
33/// content is otherwise written as usual, at its place in the quotation and
34/// outside any quotation section.
35#[derive(Debug, Clone, PartialEq, Eq, DiagnosticInfo)]
36#[diagnostic(
37 id = "flm.quote.bare-content",
38 message = "Content of the ‘{environment}’ environment must be written inside {sections}"
39)]
40pub struct BareContent {
41 /// The environment's name.
42 pub environment: String,
43 /// The quotation-section commands that the environment accepts, quoted
44 /// and listed as in an English sentence, e.g.
45 /// `‘\text’, ‘\lines’ or ‘\block’`.
46 pub sections: String,
47}
48
49/// Error raised when a quotation-section command is not written directly in
50/// the body of a quote environment (`flm.quote.nested-section`).
51///
52/// A quotation-section command (`\text`, `\lines`, `\attributed` or `\block`)
53/// starts a quotation section. It must be written directly in the body of a
54/// quote environment, as in
55/// `\begin{quote}\text{Veni, vidi, vici.}\attributed{Caesar}\end{quote}`.
56///
57/// Reported by the lowering rule of the quotation-section commands
58/// ([`SectionRule`](super::SectionRule)) when it is invoked. The command
59/// expands to the content of its argument. For a `\lines` command, the `\\`
60/// and `\indent` commands in the argument are left out.
61#[derive(Debug, Clone, PartialEq, Eq, DiagnosticInfo)]
62#[diagnostic(
63 id = "flm.quote.nested-section",
64 message = "‘\\{section}’ must be written directly in the body of the quotation environment"
65)]
66pub struct NestedSection {
67 /// The quotation-section command's name, without the backslash: `text`.
68 pub section: String,
69}
70
71/// Error raised when an `\indent` command is not written at the start of a
72/// line (`flm.quote.indent-mid-line`).
73///
74/// A lines section of a quotation is the argument of a `\lines` command, or
75/// the body of a quote environment whose content is read as lines, such as
76/// `address`. In a lines section, each `\indent` command at the start of a
77/// line indents the line by one tab, as in
78/// `\lines{First line\\ \indent Second line}`. The `\indent` commands of a
79/// line must come before all other content of the line.
80///
81/// Reported by the lowering rule of the quote environment
82/// ([`QuoteRule`](super::QuoteRule), or
83/// [`QuoteLatexRule`](super::latex::QuoteLatexRule) on the `latex-recomposed`
84/// backend) when it is invoked. The `\indent` command is left out. The line
85/// is otherwise written as usual, indented by the `\indent` commands at its
86/// start.
87#[derive(Debug, Clone, PartialEq, Eq, DiagnosticInfo)]
88#[diagnostic(
89 id = "flm.quote.indent-mid-line",
90 message = "‘\\indent’ must be written at the start of a line"
91)]
92pub struct IndentMidLine;