Skip to main content

aozora_syntax/
extension.rs

1//! Paired-container classifier tags.
2//!
3//! [`ContainerKind`] is the tag the lexer's classify phase emits on
4//! every paired open / close marker (e.g. `[#ここから2字下げ] … [#ここで字下げ終わり]`).
5//! The renderer reads it when wrapping the enclosed sibling nodes
6//! into an `AozoraNode::Container`.
7
8/// The kinds of Aozora container blocks the lexer classifies.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11#[non_exhaustive]
12pub enum ContainerKind {
13    /// `[#ここから N字下げ]`
14    Indent { amount: u8 },
15    /// `[#割り注] ... [#割り注終わり]` (when spanning multiple lines)
16    Warichu,
17    /// `[#罫囲み] ... [#罫囲み終わり]`
18    Keigakomi,
19    /// `[#ここから地付き]` / `[#ここから地から N 字上げ]`
20    AlignEnd { offset: u8 },
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn container_kind_is_copy_and_fits_in_a_word() {
29        fn assert_copy<T: Copy>() {}
30        assert_copy::<ContainerKind>();
31        // u8 + discriminant, must fit in a few bytes so downstream
32        // vector entries stay tight.
33        assert!(size_of::<ContainerKind>() <= 4);
34    }
35}