haystack_core/xeto/
ast.rs1use std::collections::HashMap;
4
5use crate::kinds::Kind;
6
7#[derive(Debug, Clone)]
9pub struct SlotDef {
10 pub name: String,
12 pub type_ref: Option<String>,
14 pub meta: HashMap<String, Kind>,
16 pub default: Option<Kind>,
18 pub is_marker: bool,
20 pub is_query: bool,
22 pub is_maybe: bool,
24 pub is_global: bool,
26 pub query_of: Option<String>,
28 pub query_via: Option<String>,
30 pub query_inverse: Option<String>,
32 pub children: Vec<SlotDef>,
34 pub doc: String,
36}
37
38impl SlotDef {
39 pub fn new(name: impl Into<String>) -> Self {
41 Self {
42 name: name.into(),
43 type_ref: None,
44 meta: HashMap::new(),
45 default: None,
46 is_marker: false,
47 is_query: false,
48 is_maybe: false,
49 is_global: false,
50 query_of: None,
51 query_via: None,
52 query_inverse: None,
53 children: Vec::new(),
54 doc: String::new(),
55 }
56 }
57}
58
59#[derive(Debug, Clone)]
61pub struct SpecDef {
62 pub name: String,
64 pub base: Option<String>,
66 pub meta: HashMap<String, Kind>,
68 pub slots: Vec<SlotDef>,
70 pub doc: String,
72 pub default: Option<Kind>,
74}
75
76impl SpecDef {
77 pub fn new(name: impl Into<String>) -> Self {
79 Self {
80 name: name.into(),
81 base: None,
82 meta: HashMap::new(),
83 slots: Vec::new(),
84 doc: String::new(),
85 default: None,
86 }
87 }
88}
89
90#[derive(Debug, Clone)]
92pub struct LibPragma {
93 pub name: String,
95 pub version: String,
97 pub doc: String,
99 pub depends: Vec<String>,
101 pub meta: HashMap<String, Kind>,
103}
104
105#[derive(Debug, Clone)]
107pub struct XetoFile {
108 pub pragma: Option<LibPragma>,
110 pub specs: Vec<SpecDef>,
112}
113
114#[cfg(test)]
115mod tests {
116 use super::*;
117
118 #[test]
119 fn slot_def_new() {
120 let slot = SlotDef::new("discharge");
121 assert_eq!(slot.name, "discharge");
122 assert!(slot.type_ref.is_none());
123 assert!(!slot.is_marker);
124 assert!(!slot.is_query);
125 assert!(!slot.is_maybe);
126 assert!(!slot.is_global);
127 assert!(slot.children.is_empty());
128 }
129
130 #[test]
131 fn spec_def_new() {
132 let spec = SpecDef::new("Ahu");
133 assert_eq!(spec.name, "Ahu");
134 assert!(spec.base.is_none());
135 assert!(spec.slots.is_empty());
136 }
137
138 #[test]
139 fn xeto_file_empty() {
140 let file = XetoFile {
141 pragma: None,
142 specs: vec![],
143 };
144 assert!(file.pragma.is_none());
145 assert!(file.specs.is_empty());
146 }
147}