Compare commits

..

No commits in common. "219d3e88fb09052c071680c59a5e15e49c5dd4e1" and "4bb38e0f3e1234ae9758af55846c088b37de0083" have entirely different histories.

6 changed files with 27 additions and 25 deletions

View file

@ -50,4 +50,4 @@ channels:
volume modifier prefix: v
octave modifier prefix: o
length modifier prefix: l
tempo modifier prefix: t,
tempo modifier prefix: t

View file

@ -13,5 +13,5 @@ use super::Expression as Instruction;
pub struct Instrument {
#[target]
expr: Instruction,
vars: Option<HashMap<String, f64>>,
vars: Option<HashMap<String, f32>>,
}

View file

@ -45,8 +45,7 @@ impl<'de> Deserialize<'de> for Atoms {
Ok(Default::default())
} else {
set_notes(notes).unwrap();
all_consuming(root)
.parse(&sheet)
all_consuming(root)(&sheet)
.map_err(|e| pretty_verbose_err.curry().call1(sheet.as_str()).call1(e))
.map_err(de::Error::custom)
.map(|(i, r)| r)

View file

@ -12,9 +12,9 @@ use nom::{
branch::alt,
bytes::complete::{is_not, tag, take_till, take_till1},
character::complete::{anychar, char, one_of, space1, u16, u8},
combinator::{all_consuming, cut, eof, map_opt, map_res, not, opt, value, verify},
combinator::{all_consuming, map_opt, map_res, not, opt, value, verify},
error::{context, ContextError, ErrorKind, FromExternalError, ParseError},
multi::{many0, many1, many_till},
multi::{many0, many1},
sequence::{delimited, pair, preceded, separated_pair, terminated},
Err, IResult, Parser,
};
@ -52,7 +52,10 @@ where
+ FromExternalError<&'a str, TryFromIntError>
+ FromExternalError<&'a str, E>,
{
many0(delimited(maybe_yml_str_space, atom, maybe_yml_str_space))
terminated(
many1(preceded(maybe_yml_str_space, atom)),
maybe_yml_str_space,
)
.map(Atoms)
.parse(i)
}
@ -96,7 +99,7 @@ where
E: ParseError<&'a str> + ContextError<&'a str>,
{
use super::super::modifier;
context("modifier", preceded(char(Atom::MODIFIER), cut(modifier)))
context("modifier", preceded(char(Atom::MODIFIER), modifier))
.map(Atom::Modifier)
.parse(i)
}
@ -122,7 +125,7 @@ where
"loop",
delimited(
char(Atom::LOOP.0),
cut(pair(
pair(
map_opt(opt(u8), |n| {
if let Some(n) = n {
NonZeroU8::new(n)
@ -131,8 +134,8 @@ where
}
}),
root,
)),
cut(char(Atom::LOOP.1)),
),
char(Atom::LOOP.1),
),
)
.map(|(n, v)| Atom::Loop(n, v))
@ -148,7 +151,7 @@ where
{
context(
"tuple",
delimited(char(Atom::TUPLE.0), cut(root), cut(char(Atom::TUPLE.1))),
delimited(char(Atom::TUPLE.0), root, char(Atom::TUPLE.1)),
)
.map(Atom::Tuple)
.parse(i)
@ -166,7 +169,7 @@ where
"slope_starts",
delimited(
char(Atom::SLOPE.0),
cut(separated_pair(
separated_pair(
separated_pair(
slope_modifier,
char(' '),
@ -177,8 +180,8 @@ where
),
char(','),
root,
)),
cut(char(Atom::SLOPE.1)),
),
char(Atom::SLOPE.1),
),
)
.map(|((sm, i), v)| Atom::Slope(sm, i, v))
@ -199,7 +202,7 @@ where
value((), comment),
value((), is_not(concatcp!(Atom::COMMENT.0, Atom::COMMENT.1))),
))),
cut(char(Atom::COMMENT.1)),
char(Atom::COMMENT.1),
),
),
)(i)
@ -215,15 +218,15 @@ where
context(
"atom",
alt((
comment,
note,
rest,
start_here,
modifier,
quick_modifier,
r#loop,
tuple,
slope,
rest,
note,
comment,
)),
)
.parse(i)

View file

@ -123,9 +123,9 @@ mod flat_atom {
))
);
assert_eq!(
Err(nom::Err::Failure(Error::new(
concatcp!(0u8, SAMPLE_STR),
ErrorKind::MapOpt
Err(nom::Err::Error(Error::new(
concatcp!(Atom::LOOP.0, 0u8, SAMPLE_STR),
ErrorKind::Char
))),
atom.parse(concatcp!(Atom::LOOP.0, 0u8, SAMPLE_STR))
)

View file

@ -41,7 +41,7 @@ fn bngfile_generator() -> BngFile {
"square".to_string(),
Instrument::new(
"v*abs(sin(2*PI*f*t))".parse().unwrap(),
Some(HashMap::from([("v".to_string(), 1f64)])),
Some(HashMap::from([("v".to_string(), 1f32)])),
),
),
]),