1#[derive(Debug, Clone, PartialEq)]
4pub struct SynFile {
5 pub items: Vec<Item>,
6}
7
8#[derive(Debug, Clone, PartialEq)]
9pub enum Item {
10 Namespace(NamespaceDecl),
11 Import(ImportDecl),
12 Const(ConstDecl),
13 Enum(EnumDef),
14 Struct(StructDef),
15 Table(StructDef),
16 Command(MessageDef),
17 Telemetry(MessageDef),
18 Message(MessageDef),
19}
20
21#[derive(Debug, Clone, PartialEq)]
22pub struct NamespaceDecl {
23 pub name: ScopedIdent,
24}
25
26#[derive(Debug, Clone, PartialEq)]
27pub struct ImportDecl {
28 pub path: String,
29}
30
31#[derive(Debug, Clone, PartialEq)]
32pub struct ConstDecl {
33 pub name: String,
34 pub ty: TypeExpr,
35 pub value: Literal,
36 pub doc: Vec<String>,
37 pub attrs: Vec<Attribute>,
38}
39
40#[derive(Debug, Clone, PartialEq)]
41pub struct EnumDef {
42 pub name: String,
43 pub repr: Option<PrimitiveType>,
44 pub variants: Vec<EnumVariant>,
45 pub doc: Vec<String>,
46 pub attrs: Vec<Attribute>,
47}
48
49#[derive(Debug, Clone, PartialEq)]
50pub struct EnumVariant {
51 pub name: String,
52 pub value: Option<i64>,
53 pub doc: Vec<String>,
54}
55
56#[derive(Debug, Clone, PartialEq)]
57pub struct StructDef {
58 pub name: String,
59 pub fields: Vec<FieldDef>,
60 pub doc: Vec<String>,
61 pub attrs: Vec<Attribute>,
62}
63
64#[derive(Debug, Clone, PartialEq)]
65pub struct MessageDef {
66 pub kind: PacketKind,
67 pub command_group: Option<String>,
71 pub name: String,
72 pub fields: Vec<FieldDef>,
73 pub doc: Vec<String>,
74 pub attrs: Vec<Attribute>,
75}
76
77#[derive(Debug, Clone, Copy, PartialEq, Eq)]
78pub enum PacketKind {
79 Message,
81 Command,
83 Telemetry,
85}
86
87#[derive(Debug, Clone, PartialEq)]
88pub struct FieldDef {
89 pub name: String,
90 pub optional: bool,
91 pub ty: TypeExpr,
92 pub default: Option<Literal>,
93 pub doc: Vec<String>,
94}
95
96#[derive(Debug, Clone, PartialEq)]
97pub struct TypeExpr {
98 pub base: BaseType,
99 pub array: Option<ArraySuffix>,
100}
101
102#[derive(Debug, Clone, PartialEq)]
103pub enum BaseType {
104 Primitive(PrimitiveType),
105 String,
106 Ref(ScopedIdent),
107}
108
109#[derive(Debug, Clone, Copy, PartialEq, Eq)]
110pub enum PrimitiveType {
111 F32,
112 F64,
113 I8,
114 I16,
115 I32,
116 I64,
117 U8,
118 U16,
119 U32,
120 U64,
121 Bool,
122 Bytes,
123}
124
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub enum ArraySuffix {
127 Dynamic,
129 Fixed(u64),
131 Bounded(u64),
133}
134
135pub type ScopedIdent = Vec<String>;
138
139#[derive(Debug, Clone, PartialEq)]
140pub enum Literal {
141 Float(f64),
142 Int(i64),
143 Hex(u64),
144 Bool(bool),
145 Str(String),
146 Ident(ScopedIdent),
148}
149
150#[derive(Debug, Clone, PartialEq)]
152pub struct Attribute {
153 pub name: String,
154 pub value: Literal,
155}
156
157mod builder;
158
159pub use builder::parse;
160
161#[cfg(test)]
162mod tests;