From d575adf63b7e87196b636ee91061692a685b605f Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sun, 2 Sep 2018 16:04:22 +0200 Subject: First working version --- src/parsing/equalizer_apo.lalrpop | 42 ++ src/parsing/equalizer_apo.rs | 1164 +++++++++++++++++++++++++++++++++++++ src/parsing/mod.rs | 3 + 3 files changed, 1209 insertions(+) create mode 100644 src/parsing/equalizer_apo.lalrpop create mode 100644 src/parsing/equalizer_apo.rs create mode 100644 src/parsing/mod.rs (limited to 'src/parsing') 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 @@ +use ::Filter; + +use std::str::FromStr; + +grammar; + +pub Main: Filter = { + => { + let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect(); + // TODO: add decibel_to_ratio conversion function + let preamp = 10f64.powf(preamp / 10f64); + Filter { preamp, frequencies: eq.0, coefficients } + } +} + +Preamp: f64 = { + "Preamp:" +} + +Eq: (Vec, Vec) = { + "GraphicEQ:" ";")+> => { + let mut values = values; + values.push(end); + values.into_iter().unzip() + } +} + +Decibel: f64 = { + "dB" +} + +Float: f64 = { + , + => <> as f64, + => <> as f64, +} + +RawFloat: f64 = r"-?[0-9]*\.[0-9]+" => f64::from_str(<>).unwrap(); +SignedInteger: i32 = r"-[0-9]+" => i32::from_str(<>).unwrap(); +Integer: u32 = r"[0-9]+"=> u32::from_str(<>).unwrap(); + +// vim: ft=rust diff --git a/src/parsing/equalizer_apo.rs b/src/parsing/equalizer_apo.rs new file mode 100644 index 0000000..3fab396 --- /dev/null +++ b/src/parsing/equalizer_apo.rs @@ -0,0 +1,1164 @@ +// auto-generated: "lalrpop 0.15.2" +// sha256: 81b6fa5856d7887b20715c2c7f6137db1927ece087e2db9f4bf1fcd8943365c5 +use ::Filter; +use std::str::FromStr; +#[allow(unused_extern_crates)] +extern crate lalrpop_util as __lalrpop_util; + +#[cfg_attr(rustfmt, rustfmt_skip)] +mod __parse__Main { + #![allow(non_snake_case, non_camel_case_types, unused_mut, unused_variables, unused_imports, unused_parens)] + + use ::Filter; + use std::str::FromStr; + #[allow(unused_extern_crates)] + extern crate lalrpop_util as __lalrpop_util; + use super::__intern_token::Token; + #[allow(dead_code)] + pub enum __Symbol<'input> + { + Variant0(&'input str), + Variant1((u32, f64)), + Variant2(::std::vec::Vec<(u32, f64)>), + Variant3(f64), + Variant4((Vec, Vec)), + Variant5(u32), + Variant6(Filter), + Variant7(i32), + } + const __ACTION: &'static [i8] = &[ + // State 0 + 0, 0, 4, 0, 0, 0, 0, + // State 1 + 0, 0, 0, 0, 0, 0, 0, + // State 2 + 0, 6, 0, 0, 0, 0, 0, + // State 3 + 0, 0, 0, 0, 12, 13, 14, + // State 4 + 0, 0, 0, 0, 0, 0, 0, + // State 5 + 0, 0, 0, 0, 0, 0, 14, + // State 6 + 0, -12, 0, 0, 0, 0, 0, + // State 7 + 0, 0, 0, 17, 0, 0, 0, + // State 8 + -9, 0, 0, -9, 0, 0, 0, + // State 9 + -7, 0, 0, -7, 0, 0, 0, + // State 10 + -8, 0, 0, -8, 0, 0, 0, + // State 11 + -13, 0, 0, -13, 0, 0, 0, + // State 12 + -14, 0, 0, -14, 0, 0, 0, + // State 13 + -10, 0, 0, -10, -10, -10, -10, + // State 14 + 0, 0, 0, 0, 0, 0, 14, + // State 15 + 0, 0, 0, 0, 12, 13, 14, + // State 16 + 0, -5, 0, 0, 0, 0, 0, + // State 17 + 0, 0, 0, 0, 12, 13, 14, + // State 18 + 21, 0, 0, 0, 0, 0, 0, + // State 19 + 22, 0, 0, 0, 0, 0, 0, + // State 20 + 0, 0, 0, 0, 0, 0, -2, + // State 21 + 0, 0, 0, 0, 0, 0, -3, + ]; + const __EOF_ACTION: &'static [i8] = &[ + // State 0 + 0, + // State 1 + -15, + // State 2 + 0, + // State 3 + 0, + // State 4 + -11, + // State 5 + 0, + // State 6 + 0, + // State 7 + 0, + // State 8 + -9, + // State 9 + -7, + // State 10 + -8, + // State 11 + -13, + // State 12 + -14, + // State 13 + -10, + // State 14 + 0, + // State 15 + 0, + // State 16 + 0, + // State 17 + 0, + // State 18 + 0, + // State 19 + -6, + // State 20 + 0, + // State 21 + 0, + ]; + const __GOTO: &'static [i8] = &[ + // State 0 + 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, + // State 1 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 2 + 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, + // State 3 + 0, 0, 0, 7, 0, 8, 9, 0, 0, 10, 11, 0, + // State 4 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 5 + 0, 15, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, + // State 6 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 7 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 8 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 9 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 10 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 11 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 12 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 13 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 14 + 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, + // State 15 + 0, 0, 0, 0, 0, 19, 9, 0, 0, 10, 11, 0, + // State 16 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 17 + 0, 0, 0, 0, 0, 20, 9, 0, 0, 10, 11, 0, + // State 18 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 19 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 20 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 21 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + fn __expected_tokens(__state: usize) -> Vec<::std::string::String> { + const __TERMINAL: &'static [&'static str] = &[ + r###"";""###, + r###""GraphicEQ:""###, + r###""Preamp:""###, + r###""dB""###, + r###"r#"-?[0-9]*\\.[0-9]+"#"###, + r###"r#"-[0-9]+"#"###, + r###"r#"[0-9]+"#"###, + ]; + __ACTION[(__state * 7)..].iter().zip(__TERMINAL).filter_map(|(&state, terminal)| { + if state == 0 { + None + } else { + Some(terminal.to_string()) + } + }).collect() + } + pub struct MainParser { + builder: super::__intern_token::__MatcherBuilder, + _priv: (), + } + + impl MainParser { + pub fn new() -> MainParser { + let __builder = super::__intern_token::__MatcherBuilder::new(); + MainParser { + builder: __builder, + _priv: (), + } + } + + #[allow(dead_code)] + pub fn parse< + 'input, + >( + &self, + input: &'input str, + ) -> Result, &'static str>> + { + let mut __tokens = self.builder.matcher(input); + let mut __states = vec![0_i8]; + let mut __symbols = vec![]; + let mut __integer; + let mut __lookahead; + let __last_location = &mut Default::default(); + '__shift: loop { + __lookahead = match __tokens.next() { + Some(Ok(v)) => v, + None => break '__shift, + Some(Err(e)) => return Err(e), + }; + *__last_location = __lookahead.2.clone(); + __integer = match __lookahead.1 { + Token(3, _) if true => 0, + Token(4, _) if true => 1, + Token(5, _) if true => 2, + Token(6, _) if true => 3, + Token(0, _) if true => 4, + Token(1, _) if true => 5, + Token(2, _) if true => 6, + _ => { + let __state = *__states.last().unwrap() as usize; + let __error = __lalrpop_util::ParseError::UnrecognizedToken { + token: Some(__lookahead), + expected: __expected_tokens(__state), + }; + return Err(__error); + } + }; + '__inner: loop { + let __state = *__states.last().unwrap() as usize; + let __action = __ACTION[__state * 7 + __integer]; + if __action > 0 { + let __symbol = match __integer { + 0 => match __lookahead.1 { + Token(3, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + 1 => match __lookahead.1 { + Token(4, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + 2 => match __lookahead.1 { + Token(5, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + 3 => match __lookahead.1 { + Token(6, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + 4 => match __lookahead.1 { + Token(0, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + 5 => match __lookahead.1 { + Token(1, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + 6 => match __lookahead.1 { + Token(2, __tok0) => __Symbol::Variant0((__tok0)), + _ => unreachable!(), + }, + _ => unreachable!(), + }; + __states.push(__action - 1); + __symbols.push((__lookahead.0, __symbol, __lookahead.2)); + continue '__shift; + } else if __action < 0 { + if let Some(r) = __reduce(input, __action, Some(&__lookahead.0), &mut __states, &mut __symbols, ::std::marker::PhantomData::<()>) { + if r.is_err() { + return r; + } + return Err(__lalrpop_util::ParseError::ExtraToken { token: __lookahead }); + } + } else { + let mut __err_lookahead = Some(__lookahead); + let mut __err_integer: Option = Some(__integer); + let __state = *__states.last().unwrap() as usize; + let __error = __lalrpop_util::ParseError::UnrecognizedToken { + token: __err_lookahead, + expected: __expected_tokens(__state), + }; + return Err(__error) + } + } + } + loop { + let __state = *__states.last().unwrap() as usize; + let __action = __EOF_ACTION[__state]; + if __action < 0 { + if let Some(r) = __reduce(input, __action, None, &mut __states, &mut __symbols, ::std::marker::PhantomData::<()>) { + return r; + } + } else { + let mut __err_lookahead = None; + let mut __err_integer: Option = None; + let __state = *__states.last().unwrap() as usize; + let __error = __lalrpop_util::ParseError::UnrecognizedToken { + token: __err_lookahead, + expected: __expected_tokens(__state), + }; + return Err(__error) + } + } + } + } + pub(crate) fn __reduce< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> Option, &'static str>>> + { + let (__pop_states, __symbol, __nonterminal) = match -__action { + 1 => { + __reduce1(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 2 => { + __reduce2(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 3 => { + __reduce3(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 4 => { + __reduce4(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 5 => { + __reduce5(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 6 => { + __reduce6(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 7 => { + __reduce7(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 8 => { + __reduce8(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 9 => { + __reduce9(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 10 => { + __reduce10(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 11 => { + __reduce11(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 12 => { + __reduce12(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 13 => { + __reduce13(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 14 => { + __reduce14(input, __action, __lookahead_start, __states, __symbols, ::std::marker::PhantomData::<()>) + } + 15 => { + // __Main = Main => ActionFn(0); + let __sym0 = __pop_Variant6(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action0::<>(input, __sym0); + return Some(Ok(__nt)); + } + _ => panic!("invalid action code {}", __action) + }; + let __states_len = __states.len(); + __states.truncate(__states_len - __pop_states); + __symbols.push(__symbol); + let __state = *__states.last().unwrap() as usize; + let __next_state = __GOTO[__state * 12 + __nonterminal] - 1; + __states.push(__next_state); + None + } + fn __pop_Variant4< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, (Vec, Vec), usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant4(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant1< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, (u32, f64), usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant1(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant6< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, Filter, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant6(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant3< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, f64, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant3(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant7< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, i32, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant7(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant5< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, u32, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant5(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant2< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, ::std::vec::Vec<(u32, f64)>, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant2(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + fn __pop_Variant0< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, &'input str, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant0(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } + pub(crate) fn __reduce1< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // (<(Integer Float)> ";") = Integer, Float, ";" => ActionFn(15); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant3(__symbols); + let __sym0 = __pop_Variant5(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym2.2.clone(); + let __nt = super::__action15::<>(input, __sym0, __sym1, __sym2); + let __symbol = (__start, __Symbol::Variant1(__nt), __end); + (3, __symbol, 0) + } + pub(crate) fn __reduce2< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // (<(Integer Float)> ";")+ = Integer, Float, ";" => ActionFn(17); + let __sym2 = __pop_Variant0(__symbols); + let __sym1 = __pop_Variant3(__symbols); + let __sym0 = __pop_Variant5(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym2.2.clone(); + let __nt = super::__action17::<>(input, __sym0, __sym1, __sym2); + let __symbol = (__start, __Symbol::Variant2(__nt), __end); + (3, __symbol, 1) + } + pub(crate) fn __reduce3< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // (<(Integer Float)> ";")+ = (<(Integer Float)> ";")+, Integer, Float, ";" => ActionFn(18); + let __sym3 = __pop_Variant0(__symbols); + let __sym2 = __pop_Variant3(__symbols); + let __sym1 = __pop_Variant5(__symbols); + let __sym0 = __pop_Variant2(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym3.2.clone(); + let __nt = super::__action18::<>(input, __sym0, __sym1, __sym2, __sym3); + let __symbol = (__start, __Symbol::Variant2(__nt), __end); + (4, __symbol, 1) + } + pub(crate) fn __reduce4< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // (Integer Float) = Integer, Float => ActionFn(14); + let __sym1 = __pop_Variant3(__symbols); + let __sym0 = __pop_Variant5(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym1.2.clone(); + let __nt = super::__action14::<>(input, __sym0, __sym1); + let __symbol = (__start, __Symbol::Variant1(__nt), __end); + (2, __symbol, 2) + } + pub(crate) fn __reduce5< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Decibel = Float, "dB" => ActionFn(4); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant3(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym1.2.clone(); + let __nt = super::__action4::<>(input, __sym0, __sym1); + let __symbol = (__start, __Symbol::Variant3(__nt), __end); + (2, __symbol, 3) + } + pub(crate) fn __reduce6< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Eq = "GraphicEQ:", (<(Integer Float)> ";")+, Integer, Float => ActionFn(16); + let __sym3 = __pop_Variant3(__symbols); + let __sym2 = __pop_Variant5(__symbols); + let __sym1 = __pop_Variant2(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym3.2.clone(); + let __nt = super::__action16::<>(input, __sym0, __sym1, __sym2, __sym3); + let __symbol = (__start, __Symbol::Variant4(__nt), __end); + (4, __symbol, 4) + } + pub(crate) fn __reduce7< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Float = RawFloat => ActionFn(5); + let __sym0 = __pop_Variant3(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action5::<>(input, __sym0); + let __symbol = (__start, __Symbol::Variant3(__nt), __end); + (1, __symbol, 5) + } + pub(crate) fn __reduce8< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Float = SignedInteger => ActionFn(6); + let __sym0 = __pop_Variant7(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action6::<>(input, __sym0); + let __symbol = (__start, __Symbol::Variant3(__nt), __end); + (1, __symbol, 5) + } + pub(crate) fn __reduce9< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Float = Integer => ActionFn(7); + let __sym0 = __pop_Variant5(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action7::<>(input, __sym0); + let __symbol = (__start, __Symbol::Variant3(__nt), __end); + (1, __symbol, 5) + } + pub(crate) fn __reduce10< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Integer = r#"[0-9]+"# => ActionFn(10); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action10::<>(input, __sym0); + let __symbol = (__start, __Symbol::Variant5(__nt), __end); + (1, __symbol, 6) + } + pub(crate) fn __reduce11< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Main = Preamp, Eq => ActionFn(1); + let __sym1 = __pop_Variant4(__symbols); + let __sym0 = __pop_Variant3(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym1.2.clone(); + let __nt = super::__action1::<>(input, __sym0, __sym1); + let __symbol = (__start, __Symbol::Variant6(__nt), __end); + (2, __symbol, 7) + } + pub(crate) fn __reduce12< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // Preamp = "Preamp:", Decibel => ActionFn(2); + let __sym1 = __pop_Variant3(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym1.2.clone(); + let __nt = super::__action2::<>(input, __sym0, __sym1); + let __symbol = (__start, __Symbol::Variant3(__nt), __end); + (2, __symbol, 8) + } + pub(crate) fn __reduce13< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // RawFloat = r#"-?[0-9]*\\.[0-9]+"# => ActionFn(8); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action8::<>(input, __sym0); + let __symbol = (__start, __Symbol::Variant3(__nt), __end); + (1, __symbol, 9) + } + pub(crate) fn __reduce14< + 'input, + >( + input: &'input str, + __action: i8, + __lookahead_start: Option<&usize>, + __states: &mut ::std::vec::Vec, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<()>, + ) -> (usize, (usize,__Symbol<'input>,usize), usize) + { + // SignedInteger = r#"-[0-9]+"# => ActionFn(9); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action9::<>(input, __sym0); + let __symbol = (__start, __Symbol::Variant7(__nt), __end); + (1, __symbol, 10) + } +} +pub use self::__parse__Main::MainParser; +#[cfg_attr(rustfmt, rustfmt_skip)] +mod __intern_token { + #![allow(unused_imports)] + use ::Filter; + use std::str::FromStr; + #[allow(unused_extern_crates)] + extern crate lalrpop_util as __lalrpop_util; + extern crate regex as __regex; + use std::fmt as __fmt; + + #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] + pub struct Token<'input>(pub usize, pub &'input str); + impl<'a> __fmt::Display for Token<'a> { + fn fmt(&self, formatter: &mut __fmt::Formatter) -> Result<(), __fmt::Error> { + __fmt::Display::fmt(self.1, formatter) + } + } + + pub struct __MatcherBuilder { + regex_set: __regex::RegexSet, + regex_vec: Vec<__regex::Regex>, + } + + impl __MatcherBuilder { + pub fn new() -> __MatcherBuilder { + let __strs: &[&str] = &[ + "^((?u:\\-)?(?u:[0-9])*(?u:\\.)(?u:[0-9])+)", + "^((?u:\\-)(?u:[0-9])+)", + "^((?u:[0-9])+)", + "^((?u:;))", + "^((?u:GraphicEQ:))", + "^((?u:Preamp:))", + "^((?u:dB))", + ]; + let __regex_set = __regex::RegexSet::new(__strs).unwrap(); + let __regex_vec = vec![ + __regex::Regex::new("^((?u:\\-)?(?u:[0-9])*(?u:\\.)(?u:[0-9])+)").unwrap(), + __regex::Regex::new("^((?u:\\-)(?u:[0-9])+)").unwrap(), + __regex::Regex::new("^((?u:[0-9])+)").unwrap(), + __regex::Regex::new("^((?u:;))").unwrap(), + __regex::Regex::new("^((?u:GraphicEQ:))").unwrap(), + __regex::Regex::new("^((?u:Preamp:))").unwrap(), + __regex::Regex::new("^((?u:dB))").unwrap(), + ]; + __MatcherBuilder { regex_set: __regex_set, regex_vec: __regex_vec } + } + pub fn matcher<'input, 'builder>(&'builder self, s: &'input str) -> __Matcher<'input, 'builder> { + __Matcher { + text: s, + consumed: 0, + regex_set: &self.regex_set, + regex_vec: &self.regex_vec, + } + } + } + + pub struct __Matcher<'input, 'builder> { + text: &'input str, + consumed: usize, + regex_set: &'builder __regex::RegexSet, + regex_vec: &'builder Vec<__regex::Regex>, + } + + impl<'input, 'builder> Iterator for __Matcher<'input, 'builder> { + type Item = Result<(usize, Token<'input>, usize), __lalrpop_util::ParseError,&'static str>>; + + fn next(&mut self) -> Option { + let __text = self.text.trim_left(); + let __whitespace = self.text.len() - __text.len(); + let __start_offset = self.consumed + __whitespace; + if __text.is_empty() { + self.text = __text; + self.consumed = __start_offset; + None + } else { + let __matches = self.regex_set.matches(__text); + if !__matches.matched_any() { + Some(Err(__lalrpop_util::ParseError::InvalidToken { + location: __start_offset, + })) + } else { + let mut __longest_match = 0; + let mut __index = 0; + for __i in 0 .. 7 { + if __matches.matched(__i) { + let __match = self.regex_vec[__i].find(__text).unwrap(); + let __len = __match.end(); + if __len >= __longest_match { + __longest_match = __len; + __index = __i; + } + } + } + let __result = &__text[..__longest_match]; + let __remaining = &__text[__longest_match..]; + let __end_offset = __start_offset + __longest_match; + self.text = __remaining; + self.consumed = __end_offset; + Some(Ok((__start_offset, Token(__index, __result), __end_offset))) + } + } + } + } +} +pub use self::__intern_token::Token; + +#[allow(unused_variables)] +fn __action0< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, Filter, usize), +) -> Filter +{ + (__0) +} + +#[allow(unused_variables)] +fn __action1< + 'input, +>( + input: &'input str, + (_, preamp, _): (usize, f64, usize), + (_, eq, _): (usize, (Vec, Vec), usize), +) -> Filter +{ + { + let coefficients: Vec<_> = eq.1.iter().map(|decibel| 10f64.powf(decibel / 10f64)).collect(); + // TODO: add decibel_to_ratio conversion function + let preamp = 10f64.powf(preamp / 10f64); + Filter { preamp, frequencies: eq.0, coefficients } + } +} + +#[allow(unused_variables)] +fn __action2< + 'input, +>( + input: &'input str, + (_, _, _): (usize, &'input str, usize), + (_, __0, _): (usize, f64, usize), +) -> f64 +{ + (__0) +} + +#[allow(unused_variables)] +fn __action3< + 'input, +>( + input: &'input str, + (_, _, _): (usize, &'input str, usize), + (_, values, _): (usize, ::std::vec::Vec<(u32, f64)>, usize), + (_, end, _): (usize, (u32, f64), usize), +) -> (Vec, Vec) +{ + { + let mut values = values; + values.push(end); + values.into_iter().unzip() + } +} + +#[allow(unused_variables)] +fn __action4< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, f64, usize), + (_, _, _): (usize, &'input str, usize), +) -> f64 +{ + (__0) +} + +#[allow(unused_variables)] +fn __action5< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, f64, usize), +) -> f64 +{ + (__0) +} + +#[allow(unused_variables)] +fn __action6< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, i32, usize), +) -> f64 +{ + __0 as f64 +} + +#[allow(unused_variables)] +fn __action7< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, u32, usize), +) -> f64 +{ + __0 as f64 +} + +#[allow(unused_variables)] +fn __action8< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> f64 +{ + f64::from_str(__0).unwrap() +} + +#[allow(unused_variables)] +fn __action9< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> i32 +{ + i32::from_str(__0).unwrap() +} + +#[allow(unused_variables)] +fn __action10< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, &'input str, usize), +) -> u32 +{ + u32::from_str(__0).unwrap() +} + +#[allow(unused_variables)] +fn __action11< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, (u32, f64), usize), +) -> ::std::vec::Vec<(u32, f64)> +{ + vec![__0] +} + +#[allow(unused_variables)] +fn __action12< + 'input, +>( + input: &'input str, + (_, v, _): (usize, ::std::vec::Vec<(u32, f64)>, usize), + (_, e, _): (usize, (u32, f64), usize), +) -> ::std::vec::Vec<(u32, f64)> +{ + { let mut v = v; v.push(e); v } +} + +#[allow(unused_variables)] +fn __action13< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, (u32, f64), usize), + (_, _, _): (usize, &'input str, usize), +) -> (u32, f64) +{ + (__0) +} + +#[allow(unused_variables)] +fn __action14< + 'input, +>( + input: &'input str, + (_, __0, _): (usize, u32, usize), + (_, __1, _): (usize, f64, usize), +) -> (u32, f64) +{ + (__0, __1) +} + +#[allow(unused_variables)] +fn __action15< + 'input, +>( + input: &'input str, + __0: (usize, u32, usize), + __1: (usize, f64, usize), + __2: (usize, &'input str, usize), +) -> (u32, f64) +{ + let __start0 = __0.0.clone(); + let __end0 = __1.2.clone(); + let __temp0 = __action14( + input, + __0, + __1, + ); + let __temp0 = (__start0, __temp0, __end0); + __action13( + input, + __temp0, + __2, + ) +} + +#[allow(unused_variables)] +fn __action16< + 'input, +>( + input: &'input str, + __0: (usize, &'input str, usize), + __1: (usize, ::std::vec::Vec<(u32, f64)>, usize), + __2: (usize, u32, usize), + __3: (usize, f64, usize), +) -> (Vec, Vec) +{ + let __start0 = __2.0.clone(); + let __end0 = __3.2.clone(); + let __temp0 = __action14( + input, + __2, + __3, + ); + let __temp0 = (__start0, __temp0, __end0); + __action3( + input, + __0, + __1, + __temp0, + ) +} + +#[allow(unused_variables)] +fn __action17< + 'input, +>( + input: &'input str, + __0: (usize, u32, usize), + __1: (usize, f64, usize), + __2: (usize, &'input str, usize), +) -> ::std::vec::Vec<(u32, f64)> +{ + let __start0 = __0.0.clone(); + let __end0 = __2.2.clone(); + let __temp0 = __action15( + input, + __0, + __1, + __2, + ); + let __temp0 = (__start0, __temp0, __end0); + __action11( + input, + __temp0, + ) +} + +#[allow(unused_variables)] +fn __action18< + 'input, +>( + input: &'input str, + __0: (usize, ::std::vec::Vec<(u32, f64)>, usize), + __1: (usize, u32, usize), + __2: (usize, f64, usize), + __3: (usize, &'input str, usize), +) -> ::std::vec::Vec<(u32, f64)> +{ + let __start0 = __1.0.clone(); + let __end0 = __3.2.clone(); + let __temp0 = __action15( + input, + __1, + __2, + __3, + ); + let __temp0 = (__start0, __temp0, __end0); + __action12( + input, + __0, + __temp0, + ) +} + +pub trait __ToTriple<'input, > { + type Error; + fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize),Self::Error>; +} + +impl<'input, > __ToTriple<'input, > for (usize, Token<'input>, usize) { + type Error = &'static str; + fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize),&'static str> { + Ok(value) + } +} +impl<'input, > __ToTriple<'input, > for Result<(usize, Token<'input>, usize),&'static str> { + type Error = &'static str; + fn to_triple(value: Self) -> Result<(usize,Token<'input>,usize),&'static str> { + value + } +} diff --git a/src/parsing/mod.rs b/src/parsing/mod.rs new file mode 100644 index 0000000..b613585 --- /dev/null +++ b/src/parsing/mod.rs @@ -0,0 +1,3 @@ +pub mod equalizer_apo; + +pub use self::equalizer_apo::MainParser as EqualizerApoParser; -- cgit v1.2.3