diff --git a/Cargo.toml b/Cargo.toml index b4ff9ae..a315900 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,11 +47,3 @@ raw = ["raw_audio"] name = "blip" path = "src/cli/main.rs" required-features = ["bin"] - -[[example]] -name = "blip" -path = "src/cli/main.rs" -required-features = ["bin"] - -[lints.rust] -missing_docs = "warn" diff --git a/doc/language-design.txt b/doc/language-design.txt index bfd0cc0..b948e1f 100644 --- a/doc/language-design.txt +++ b/doc/language-design.txt @@ -1,8 +1,8 @@ notes: dorémi abc... as they appear in the note list -variables: $v8 assign '8' to the variable named 'v' +variables: $v8 $v1+2 $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: (...) (2...) to loop 2 times (n...) to loop n times (taking the integer part with the floor function) diff --git a/src/cli/main.rs b/src/cli/main.rs index d3d6d6c..ca419af 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -166,7 +166,7 @@ fn parse_and_compile(opts: &PlayOpts) -> anyhow::Result> { compiler .compile_all(tokens) .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) { error!("🎉 All your samples are NaN, you got yourself a \"Not a Song\" (NaS)!") } else if v.iter().any(is_nan) { diff --git a/src/parser.rs b/src/parser.rs index 673474b..bb24d69 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -10,17 +10,10 @@ use derive_new::new; use fasteval::Evaler; use log::{debug, trace, warn}; 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}, streaming::one_of, - }, - combinator::{all_consuming, cut, opt, value}, - error::{ErrorKind, FromExternalError, ParseError}, - multi::many0, - sequence::{delimited, preceded}, + }, combinator::{all_consuming, cut, opt, value}, error::{ErrorKind, FromExternalError, ParseError}, multi::many0, sequence::{delimited, preceded}, AsChar, Compare, Input, Parser as _ }; use nom_locate::LocatedSpan; @@ -101,10 +94,7 @@ where impl FromExternalError for LocatedVerboseError { fn from_external_error(input: I, _kind: ErrorKind, e: anyhow::Error) -> Self { - Self { - location: input, - error: Some(e), - } + Self { location: input, error: Some(e) } } } @@ -240,7 +230,6 @@ impl Note { sorted }; move |input: I| { - #[allow(clippy::type_complexity)] let mut parsers: Vec IResult>> = notes .clone() .drain(..) @@ -321,10 +310,10 @@ impl Loop { .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( expect( - char(')'), + char(')'), format!( "the loop started at line {line} column {column} was not closed at this point", - line = input.location_line(), + line = input.location_line(), column = input.get_utf8_column() ) ) @@ -351,16 +340,12 @@ impl Tuplet { { trace!("making the {} parser", type_name::()); |input| { - 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( + 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( expect( - char(']'), + char(']'), format!( "the tuplet started at line {line} column {column} was not closed at this point", - line = input.location_line(), + line = input.location_line(), column = input.get_utf8_column() ) ) @@ -420,20 +405,14 @@ impl Slope { -> IResult, VariableChange>, >, >>() - .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::>() - ))) - .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?)"))))), + .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::>()))) + .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( expect( - char('}'), + char('}'), format!( "the slope started at line {line} column {column} was not closed at this point", - line = input.location_line(), + line = input.location_line(), column = input.get_utf8_column() ) ) @@ -541,16 +520,14 @@ mod tests { VariableChange('n', "1".parse().unwrap()) } - type DefaultParser = Parser< + fn parser_generator() -> Parser< [&'static str; 3], &'static str, HashMap, String, VariableChange, [char; 1], - >; - - fn parser_generator() -> DefaultParser { + > { Parser::new( ["do", "ré", "mi"], HashMap::from([