Compare commits

..

No commits in common. "df342893eebdb0d64f4219389b234510ea8b5b70" and "674f7e49d243ab8e38a8e107e76331afd5b9ea91" have entirely different histories.

4 changed files with 17 additions and 48 deletions

View file

@ -47,11 +47,3 @@ raw = ["raw_audio"]
name = "blip" name = "blip"
path = "src/cli/main.rs" path = "src/cli/main.rs"
required-features = ["bin"] required-features = ["bin"]
[[example]]
name = "blip"
path = "src/cli/main.rs"
required-features = ["bin"]
[lints.rust]
missing_docs = "warn"

View file

@ -1,8 +1,8 @@
notes: dorémi abc... as they appear in the note list notes: dorémi abc... as they appear in the note list
variables: $v8 assign '8' to the variable named 'v' variables: $v8
$v1+2 $v1+2
$vv+1 $vv+1
$v-4.1 as soon as the variable mutation string stops being valid, usual sheet music parsing continues (https://en.wikipedia.org/wiki/Maximal_munch) $v-4.1 as soon as the variable mutation string stops being valid, usual sheet music parsing continues
loops: (...) loops: (...)
(2...) to loop 2 times (2...) to loop 2 times
(n...) to loop n times (taking the integer part with the floor function) (n...) to loop n times (taking the integer part with the floor function)

View file

@ -166,7 +166,7 @@ fn parse_and_compile(opts: &PlayOpts) -> anyhow::Result<Vec<f64>> {
compiler compiler
.compile_all(tokens) .compile_all(tokens)
.inspect(|v| { .inspect(|v| {
let is_nan = |sample: &f64| sample.abs().is_nan(); let is_nan = |sample| sample.abs().is_nan();
if v.iter().all(is_nan) { if v.iter().all(is_nan) {
error!("🎉 All your samples are NaN, you got yourself a \"Not a Song\" (NaS)!") error!("🎉 All your samples are NaN, you got yourself a \"Not a Song\" (NaS)!")
} else if v.iter().any(is_nan) { } else if v.iter().any(is_nan) {

View file

@ -10,17 +10,10 @@ use derive_new::new;
use fasteval::Evaler; use fasteval::Evaler;
use log::{debug, trace, warn}; use log::{debug, trace, warn};
use nom::{ use nom::{
AsChar, Compare, Input, Parser as _, branch::alt, bytes::complete::{tag, take, take_till}, character::{
branch::alt,
bytes::complete::{tag, take, take_till},
character::{
complete::{char, space1, usize}, complete::{char, space1, usize},
streaming::one_of, streaming::one_of,
}, }, combinator::{all_consuming, cut, opt, value}, error::{ErrorKind, FromExternalError, ParseError}, multi::many0, sequence::{delimited, preceded}, AsChar, Compare, Input, Parser as _
combinator::{all_consuming, cut, opt, value},
error::{ErrorKind, FromExternalError, ParseError},
multi::many0,
sequence::{delimited, preceded},
}; };
use nom_locate::LocatedSpan; use nom_locate::LocatedSpan;
@ -101,10 +94,7 @@ where
impl<I> FromExternalError<I, anyhow::Error> for LocatedVerboseError<I> { impl<I> FromExternalError<I, anyhow::Error> for LocatedVerboseError<I> {
fn from_external_error(input: I, _kind: ErrorKind, e: anyhow::Error) -> Self { fn from_external_error(input: I, _kind: ErrorKind, e: anyhow::Error) -> Self {
Self { Self { location: input, error: Some(e) }
location: input,
error: Some(e),
}
} }
} }
@ -240,7 +230,6 @@ impl Note {
sorted sorted
}; };
move |input: I| { move |input: I| {
#[allow(clippy::type_complexity)]
let mut parsers: Vec<Box<dyn Fn(I) -> IResult<I, Self>>> = notes let mut parsers: Vec<Box<dyn Fn(I) -> IResult<I, Self>>> = notes
.clone() .clone()
.drain(..) .drain(..)
@ -351,11 +340,7 @@ impl Tuplet {
{ {
trace!("making the {} parser", type_name::<Self>()); trace!("making the {} parser", type_name::<Self>());
|input| { |input| {
delimited(char('['), delimited(char('['), cut(take_till(|c| c == ']').and_then(cut(expect(all_consuming(token_parser(parser)), "input did not match any known grammar for inner tokens (typo?)")))), cut(
cut(take_till(|c| c == ']')
.and_then(cut(expect(
all_consuming(token_parser(parser)),
"input did not match any known grammar for inner tokens (typo?)")))), cut(
expect( expect(
char(']'), char(']'),
format!( format!(
@ -420,14 +405,8 @@ impl Slope {
-> IResult<LocatedSpan<&'a str>, VariableChange>, -> IResult<LocatedSpan<&'a str>, VariableChange>,
>, >,
>>() >>()
.as_mut_slice()), .as_mut_slice()), format!("expected a slope name from available slope names ({:?})", parser.slopes.clone().into_iter().map(|(s1, _)| s1.as_ref().to_string()).collect::<Vec<_>>())))
format!( .and(cut(take_till(|c| c == '}').and_then(cut(expect(all_consuming(token_parser(parser)), "input did not match any known grammar for inner tokens (typo?)"))))),
"expected a slope name from available slope names ({:?})",
parser.slopes.clone().into_iter().map(|(s1, _)| s1.as_ref().to_string()).collect::<Vec<_>>()
)))
.and(cut(take_till(|c| c == '}').and_then(cut(
expect(all_consuming(token_parser(parser)),
"input did not match any known grammar for inner tokens (typo?)"))))),
cut( cut(
expect( expect(
char('}'), char('}'),
@ -541,16 +520,14 @@ mod tests {
VariableChange('n', "1".parse().unwrap()) VariableChange('n', "1".parse().unwrap())
} }
type DefaultParser = Parser< fn parser_generator() -> Parser<
[&'static str; 3], [&'static str; 3],
&'static str, &'static str,
HashMap<String, VariableChange>, HashMap<String, VariableChange>,
String, String,
VariableChange, VariableChange,
[char; 1], [char; 1],
>; > {
fn parser_generator() -> DefaultParser {
Parser::new( Parser::new(
["do", "", "mi"], ["do", "", "mi"],
HashMap::from([ HashMap::from([