Skip to main content

asciidoc_parser/parser/
attribute_value.rs

1use crate::document::InterpretedValue;
2
3/// Document attributes are used either to configure behavior in the processor
4/// or to relay information about the document and its environment.
5///
6/// Attribute values can be established via the API using the
7/// [`Parser::with_intrinsic_attribute()`] or
8/// [`Parser::with_intrinsic_attribute_bool()`] functions.
9///
10/// [`Parser::with_intrinsic_attribute()`]: crate::Parser::with_intrinsic_attribute
11/// [`Parser::with_intrinsic_attribute_bool()`]: crate::Parser::with_intrinsic_attribute_bool
12#[derive(Clone, Debug, Eq, PartialEq)]
13pub(crate) struct AttributeValue {
14    /// Allowable values for the attribute.
15    pub(crate) allowable_value: AllowableValue,
16
17    /// Allowable contexts for modifying the attribute value.
18    pub(crate) modification_context: ModificationContext,
19
20    /// Whether a rejected write (a document header or body assignment that
21    /// [`modification_context`](Self::modification_context) does not permit) is
22    /// silently ignored instead of recording an
23    /// [`AttributeValueIsLocked`](crate::warnings::WarningType::AttributeValueIsLocked)
24    /// warning.
25    ///
26    /// This is orthogonal to the scope axis: it does not change *where* the
27    /// attribute may be set, only whether a rejected write warns. It exists so
28    /// a caller can reproduce Asciidoctor's *silent* safe-mode attribute
29    /// restrictions — under `SERVER`/`SECURE`, a document assignment of a
30    /// restricted conversion attribute (`backend`, `doctype`, `docinfo`,
31    /// `source-highlighter`) is simply dropped, with no diagnostic.
32    pub(crate) silent_when_locked: bool,
33
34    /// Current value of the attribute.
35    pub(crate) value: InterpretedValue,
36}
37
38/// Allowable values for the attribute.
39#[derive(Clone, Debug, Eq, PartialEq)]
40pub enum AllowableValue {
41    /// Any value is accepted.
42    Any,
43
44    /// Indicates the attribute doesn't require an explicit value. The
45    /// attribute is simply turned on by being set.
46    Empty,
47
48    /// In some cases, an empty value is interpreted by the processor as one of
49    /// the allowable non-empty values. This effective value is prefixed with an
50    /// equals sign and enclosed in square brackets (e.g., `[=auto]`). An
51    /// attribute reference will resolve to an empty value rather than the
52    /// effective value.
53    Effective(InterpretedValue),
54
55    /// Built-in attributes that are not set may have an implied value. The
56    /// implied value is enclosed in parentheses (e.g., (attributes)). An
57    /// implied value can't be resolved using an attribute reference.
58    Implied(&'static str),
59}
60
61/// Allowable context(s) for modification of this attribute value.
62#[derive(Clone, Debug, Eq, PartialEq)]
63pub enum ModificationContext {
64    /// Value can only be configured via API.
65    ApiOnly,
66
67    /// The attribute must be set or unset by the end of the document header
68    /// (i.e., set by the API or in the document header).
69    ApiOrHeader,
70
71    /// The attribute was set by API. It can not be overridden in the document
72    /// header, but can be set in the document body. Changing the attribute's
73    /// value only affects behavior for content that follows the assignment (in
74    /// document order).
75    ApiOrDocumentBody,
76
77    /// The attribute can be set anywhere in the document. However, changing an
78    /// attribute only affects behavior for content that follows the assignment
79    /// (in document order).
80    Anywhere,
81}