1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright Two Neutron Stars Incorporated and contributors
// SPDX-License-Identifier: BlueOak-1.0.0
/// Declares a set of known identifiers as compile-time constants.
///
/// This macro generates `pub const` declarations for [`Ident`] values and a
/// `try_resolve` function to look up the original string from an ident hash.
///
/// # Usage
///
/// Create a dedicated `{language}-known-idents` crate for your language's
/// known identifiers. This keeps them centralized and allows both the compiler
/// and LSP to share the same definitions.
///
/// ```ignore
/// // In your {language}-known-idents/src/lib.rs
/// use laburnum::known_idents;
///
/// known_idents! {
/// // Simple identifiers: input becomes the string value,
/// // UPPER_CASE version becomes the const name
/// theme, // pub const THEME: Ident = Ident::new("theme");
/// palette, // pub const PALETTE: Ident = Ident::new("palette");
/// my_field, // pub const MY_FIELD: Ident = Ident::new("my_field");
///
/// // Explicit overrides for strings that aren't valid Rust identifiers
/// // or need different const names (e.g., PascalCase, kebab-case)
/// {
/// COLOR_HEX = "ColorHex",
/// TEMPLATES_PER_VARIANT = "templates-per-variant",
/// }
/// }
/// ```
///
/// # Generated Code
///
/// The macro generates:
/// - `pub const NAME: Ident` for each identifier
/// - `pub fn try_resolve(ident: Ident) -> Option<&'static str>` to look up strings
///
/// # Crate Structure
///
/// Recommended structure for a language called "mylang":
///
/// ```text
/// crates/
/// mylang-known-idents/
/// Cargo.toml
/// src/lib.rs # known_idents! { ... }
/// ```
///
/// Your `Cargo.toml` must include both `laburnum` and `paste`:
///
/// ```toml
/// [dependencies]
/// laburnum = { workspace = true }
/// paste = { workspace = true }
/// ```
///
/// Then depend on `mylang-known-idents` from your compiler and LSP crates.
}
}
};
}