summaryrefslogtreecommitdiffstats
path: root/src/parsing/equalizer_apo.lalrpop
diff options
context:
space:
mode:
Diffstat (limited to 'src/parsing/equalizer_apo.lalrpop')
-rw-r--r--src/parsing/equalizer_apo.lalrpop42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/parsing/equalizer_apo.lalrpop b/src/parsing/equalizer_apo.lalrpop
new file mode 100644
index 0000000..b1faad9
--- /dev/null
+++ b/src/parsing/equalizer_apo.lalrpop
@@ -0,0 +1,42 @@
1use ::Filter;
2
3use std::str::FromStr;
4
5grammar;
6
7pub Main: Filter = {
8 <preamp: Preamp> <eq: Eq> => {
9 let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect();
10 // TODO: add decibel_to_ratio conversion function
11 let preamp = 10f64.powf(preamp / 10f64);
12 Filter { preamp, frequencies: eq.0, coefficients }
13 }
14}
15
16Preamp: f64 = {
17 "Preamp:" <Decibel>
18}
19
20Eq: (Vec<u32>, Vec<f64>) = {
21 "GraphicEQ:" <values:(<(Integer Float)> ";")+> <end:(Integer Float)> => {
22 let mut values = values;
23 values.push(end);
24 values.into_iter().unzip()
25 }
26}
27
28Decibel: f64 = {
29 <Float> "dB"
30}
31
32Float: f64 = {
33 <RawFloat>,
34 <SignedInteger> => <> as f64,
35 <Integer> => <> as f64,
36}
37
38RawFloat: f64 = r"-?[0-9]*\.[0-9]+" => f64::from_str(<>).unwrap();
39SignedInteger: i32 = r"-[0-9]+" => i32::from_str(<>).unwrap();
40Integer: u32 = r"[0-9]+"=> u32::from_str(<>).unwrap();
41
42// vim: ft=rust