macroonz_compiler/token/generation/types.rs
1//! The generation home's declarations.
2//!
3//! Declarations only.
4//! Every road that reaches a private field lives in `type_guard.rs`, this file's own child.
5
6use crate::bounded::Bounded;
7
8#[path = "type_guard.rs"]
9mod guard;
10
11/// Tokens one generated tree may carry at any one nesting level.
12pub const GENERATED_TOKEN_LIMIT: usize = 4096;
13
14/// Whether one generated punctuation mark joins the token after it.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16pub enum GeneratedSpacing {
17 /// It joins what follows: `::`, `->`, `'static`.
18 Joint,
19 /// It stands alone.
20 Alone,
21}
22
23/// The delimiter one generated group is written with.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
25pub enum GeneratedDelimiter {
26 /// `( … )`.
27 Parenthesis,
28 /// `{ … }`.
29 Brace,
30 /// `[ … ]`.
31 Bracket,
32}
33
34/// One token a renderer writes.
35///
36/// A renderer states a literal's value and never its spelling, and the quoting, the escaping, and the absence of a suffix are the tree's business.
37///
38/// # Ordering
39///
40/// The roster grows at its end and nowhere else: each arm's slot is a byte of [`GeneratedTree::canonical_bytes`], which is what a rendered unit's identity is derived over.
41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub enum GeneratedToken {
43 /// An ordinary identifier-shaped word.
44 Word(String),
45 /// One punctuation character and whether it joins what follows.
46 Punct {
47 /// The character.
48 mark: char,
49 /// Whether it joins what follows.
50 spacing: GeneratedSpacing,
51 },
52 /// A text literal, stated as its text; the quoting is the tree's business.
53 Text(String),
54 /// A delimited group.
55 Group {
56 /// The delimiter.
57 delimiter: GeneratedDelimiter,
58 /// The tokens inside.
59 tokens: Bounded<GeneratedToken, GENERATED_TOKEN_LIMIT>,
60 },
61 /// A byte-string literal's material, written `b"…"`.
62 ByteText(Vec<u8>),
63 /// An unsuffixed integer literal.
64 Number(u64),
65 /// A raw identifier's name without its `r#` spelling marker.
66 RawIdentifier(String),
67}
68
69/// One generated token tree: the artifact a renderer produces.
70#[derive(Debug, Clone, PartialEq, Eq, Hash)]
71pub struct GeneratedTree {
72 tokens: Bounded<GeneratedToken, GENERATED_TOKEN_LIMIT>,
73}