1use crate::{ast::*, xkb::Rule};
2use derivative::Derivative;
3use pest_ast::FromPest;
4
5#[derive(Derivative, FromPest, Clone, PartialEq)]
6#[derivative(Debug)]
7#[pest_ast(rule(Rule::xkb_symbols))]
8pub struct XkbSymbols<'src> {
9 pub name: StringContent<'src>,
10 pub value: Vec<XkbSymbolsItem<'src>>,
11}
12
13#[derive(Derivative, FromPest, Clone, PartialEq)]
14#[derivative(Debug)]
15#[pest_ast(rule(Rule::xkb_symbols_item))]
16pub enum XkbSymbolsItem<'src> {
17 #[derivative(Debug = "transparent")]
18 Include(Include<'src>),
19 #[derivative(Debug = "transparent")]
20 Override(Override<'src>),
21 #[derivative(Debug = "transparent")]
22 Augment(Augment<'src>),
23
24 #[derivative(Debug = "transparent")]
25 Name(Name<'src>),
26 #[derivative(Debug = "transparent")]
27 Key(Key<'src>),
28 #[derivative(Debug = "transparent")]
29 KeyType(KeyType<'src>),
30 #[derivative(Debug = "transparent")]
31 VirtualModifiers(VirtualModifiers<'src>),
32 #[derivative(Debug = "transparent")]
33 ModifierMap(ModifierMap<'src>),
34}
35
36#[derive(Derivative, FromPest, Clone, PartialEq)]
37#[derivative(Debug)]
38#[pest_ast(rule(Rule::name))]
39pub struct Name<'src> {
40 pub group: Group<'src>,
41 pub name: StringContent<'src>,
42}
43
44#[derive(Derivative, FromPest, Clone, PartialEq)]
45#[derivative(Debug)]
46#[pest_ast(rule(Rule::key_type))]
47pub struct KeyType<'src> {
48 pub group: Option<Group<'src>>,
49 pub name: StringContent<'src>,
50}
51
52#[derive(Derivative, FromPest, Clone, PartialEq)]
53#[derivative(Debug)]
54#[pest_ast(rule(Rule::key))]
55pub struct Key<'src> {
56 pub mode: Option<KeyMode>,
57 pub id: Symbol<'src>,
58 pub values: Vec<KeyValue<'src>>,
59}
60
61#[derive(Derivative, FromPest, Clone, PartialEq)]
62#[derivative(Debug)]
63#[derivative(Debug = "transparent")]
64#[pest_ast(rule(Rule::key_mode))]
65pub enum KeyMode {
66 KeyModeReplace(KeyModeReplace),
67 KeyModeOverride(KeyModeOverride),
68 KeyModeAugment(KeyModeAugment),
69}
70
71#[derive(Derivative, FromPest, Clone, PartialEq)]
72#[derivative(Debug)]
73#[pest_ast(rule(Rule::key_mode_replace))]
74pub struct KeyModeReplace;
75
76#[derive(Derivative, FromPest, Clone, PartialEq)]
77#[derivative(Debug)]
78#[pest_ast(rule(Rule::key_mode_override))]
79pub struct KeyModeOverride;
80
81#[derive(Derivative, FromPest, Clone, PartialEq)]
82#[derivative(Debug)]
83#[pest_ast(rule(Rule::key_mode_augment))]
84pub struct KeyModeAugment;
85
86#[derive(Derivative, FromPest, Clone, PartialEq)]
87#[derivative(Debug)]
88#[derivative(Debug = "transparent")]
89#[pest_ast(rule(Rule::key_value))]
90pub enum KeyValue<'src> {
91 KeyNames(KeyNames<'src>),
92 KeyDefs(KeyDef<'src>),
93}
94
95#[derive(Derivative, FromPest, Clone, PartialEq)]
96#[derivative(Debug = "transparent")]
97#[pest_ast(rule(Rule::key_names))]
98pub struct KeyNames<'src> {
99 pub values: Vec<Ident<'src>>,
100}
101
102#[derive(Derivative, FromPest, Clone, PartialEq)]
103#[derivative(Debug = "transparent")]
104#[pest_ast(rule(Rule::key_def))]
105pub enum KeyDef<'src> {
106 TypeDef(TypeDef<'src>),
107 SymbolDef(SymbolDef<'src>),
108 VirtualModsDef(VirtualModsDef<'src>),
109 ActionsDef(ActionsDef<'src>),
110 OverlayDef(OverlayDef<'src>),
111}
112
113#[derive(Derivative, FromPest, Clone, PartialEq)]
114#[derivative(Debug)]
115#[pest_ast(rule(Rule::type_def))]
116pub struct TypeDef<'src> {
117 pub group: Option<Group<'src>>,
118 pub content: StringContent<'src>,
119}
120
121#[derive(Derivative, FromPest, Clone, PartialEq)]
122#[derivative(Debug)]
123#[pest_ast(rule(Rule::symbol_def))]
124pub struct SymbolDef<'src> {
125 pub group: Group<'src>,
126 pub values: KeyNames<'src>,
127}
128
129#[derive(Derivative, FromPest, Clone, PartialEq)]
130#[derivative(Debug)]
131#[pest_ast(rule(Rule::virtual_mods_def))]
132pub struct VirtualModsDef<'src> {
133 pub prefix: VirtualModsDefPrefix<'src>,
134 pub name: Ident<'src>,
135}
136
137#[derive(Derivative, FromPest, Clone, PartialEq)]
138#[derivative(Debug)]
139#[pest_ast(rule(Rule::virtual_mods_def_prefix))]
140pub struct VirtualModsDefPrefix<'src> {
141 #[pest_ast(outer(with(span_into_str)))]
142 pub content: &'src str,
143}
144
145#[derive(Derivative, FromPest, Clone, PartialEq)]
146#[derivative(Debug)]
147#[pest_ast(rule(Rule::actions_def))]
148pub struct ActionsDef<'src> {
149 pub group: Group<'src>,
150 pub values: Vec<Action<'src>>,
151}
152
153#[derive(Derivative, FromPest, Clone, PartialEq)]
154#[derivative(Debug)]
155#[pest_ast(rule(Rule::overlay_def))]
156pub struct OverlayDef<'src> {
157 #[pest_ast(inner(with(span_into_str), with(str::parse), with(Result::unwrap)))]
158 pub level: u64,
159 pub key: Symbol<'src>,
160}
161
162#[derive(Derivative, FromPest, Clone, PartialEq)]
163#[derivative(Debug)]
164#[pest_ast(rule(Rule::modifier_map))]
165pub struct ModifierMap<'src> {
166 pub name: Ident<'src>,
167 pub values: Vec<Modifier<'src>>,
168}
169
170#[derive(Derivative, FromPest, Clone, PartialEq)]
171#[derivative(Debug = "transparent")]
172#[pest_ast(rule(Rule::modifier))]
173pub enum Modifier<'src> {
174 KeyId(Symbol<'src>),
175 Ident(Ident<'src>),
176}