yog_script_analyze/system.rs
1//! The System library's declarations (`system/*.ys`), read once and seen
2//! by every source as its own types are, namespace `System`.
3
4use yog_sync::LazyLock;
5
6use crate::ast::Decl;
7
8/// Every namespace of the library and of what a source reaches starts
9/// here: `System`, `System.Yog` (Yog's objects), `System.Game` (the game's
10/// classes, a `.yns`'s).
11pub const ROOT: &str = "System";
12
13/// The enum whose cases a source calls without its name (`Ok(v)`,
14/// `Err(e)`), as Rust's prelude brings them.
15pub const RESULT: &str = "Result";
16
17/// The attribute that runs derive macros on a type: `[Derive(Clone)]`.
18pub const DERIVE: &str = "Derive";
19
20/// What a derive macro is given and its fields (`System.Meta`).
21pub const ITEM: &str = "Item";
22pub const FIELD: &str = "Field";
23
24/// The attributes marking macros' methods (`System.Meta`).
25pub const PROC_MACRO: &str = "ProcMacro";
26pub const DERIVE_MACRO: &str = "DeriveMacro";
27
28/// The attribute marking an attribute class as an attribute macro (`System`).
29pub const MACRO: &str = "Macro";
30
31/// The bus's attributes (`System.Yog.Native`): a call, an event, a method provided.
32pub const SERVICE: &str = "Service";
33pub const EVENT: &str = "Event";
34pub const PROVIDE: &str = "Provide";
35
36/// The System library's sources, by file name.
37const SOURCES: &[(&str, &str)] = &[
38 ("System.ys", include_str!("system/System.ys")),
39 ("System.Meta.ys", include_str!("system/System.Meta.ys")),
40 (
41 "System.Yog.Native.ys",
42 include_str!("system/System.Yog.Native.ys"),
43 ),
44];
45
46/// Every declaration of the library, parsed once.
47pub static DECLS: LazyLock<Vec<Decl>> = LazyLock::new(|| {
48 SOURCES
49 .iter()
50 .flat_map(|(name, src)| crate::parse(name, src).file.decls)
51 .collect()
52});