fix everything!!!! :D

This commit is contained in:
Ponj 2024-11-10 00:50:04 -05:00
parent 4bb38e0f3e
commit 6dffde0cb7
Signed by: p6nj
GPG key ID: 6FED68D87C479A59
4 changed files with 23 additions and 25 deletions

View file

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

View file

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

View file

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

View file

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