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 /// Current value of the attribute.
21 pub(crate) value: InterpretedValue,
22}
23
24/// Allowable values for the attribute.
25#[derive(Clone, Debug, Eq, PartialEq)]
26pub enum AllowableValue {
27 /// Any value is accepted.
28 Any,
29
30 /// Indicates the attribute doesn't require an explicit value. The
31 /// attribute is simply turned on by being set.
32 Empty,
33
34 /// In some cases, an empty value is interpreted by the processor as one of
35 /// the allowable non-empty values. This effective value is prefixed with an
36 /// equals sign and enclosed in square brackets (e.g., `[=auto]`). An
37 /// attribute reference will resolve to an empty value rather than the
38 /// effective value.
39 Effective(InterpretedValue),
40
41 /// Built-in attributes that are not set may have an implied value. The
42 /// implied value is enclosed in parentheses (e.g., (attributes)). An
43 /// implied value can't be resolved using an attribute reference.
44 Implied(&'static str),
45}
46
47/// Allowable context(s) for modification of this attribute value.
48#[derive(Clone, Debug, Eq, PartialEq)]
49pub enum ModificationContext {
50 /// Value can only be configured via API.
51 ApiOnly,
52
53 /// The attribute must be set or unset by the end of the document header
54 /// (i.e., set by the API or in the document header).
55 ApiOrHeader,
56
57 /// The attribute was set by API. It can not be overridden in the document
58 /// header, but can be set in the document body. Changing the attribute's
59 /// value only affects behavior for content that follows the assignment (in
60 /// document order).
61 ApiOrDocumentBody,
62
63 /// The attribute can be set anywhere in the document. However, changing an
64 /// attribute only affects behavior for content that follows the assignment
65 /// (in document order).
66 Anywhere,
67}