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
octave modifier prefix: o
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())
} else {
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(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, 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},
multi::{many0, many1},
multi::{many0, many1, many_till},
sequence::{delimited, pair, preceded, separated_pair, terminated},
Err, IResult, Parser,
};
@ -52,12 +52,9 @@ where
+ FromExternalError<&'a str, TryFromIntError>
+ FromExternalError<&'a str, E>,
{
terminated(
many1(preceded(maybe_yml_str_space, atom)),
maybe_yml_str_space,
)
.map(Atoms)
.parse(i)
many0(delimited(maybe_yml_str_space, atom, maybe_yml_str_space))
.map(Atoms)
.parse(i)
}
fn note<'a, E>(i: &'a str) -> IResult<&'a str, Atom, E>
@ -99,7 +96,7 @@ where
E: ParseError<&'a str> + ContextError<&'a str>,
{
use super::super::modifier;
context("modifier", preceded(char(Atom::MODIFIER), modifier))
context("modifier", preceded(char(Atom::MODIFIER), cut(modifier)))
.map(Atom::Modifier)
.parse(i)
}
@ -125,7 +122,7 @@ where
"loop",
delimited(
char(Atom::LOOP.0),
pair(
cut(pair(
map_opt(opt(u8), |n| {
if let Some(n) = n {
NonZeroU8::new(n)
@ -134,8 +131,8 @@ where
}
}),
root,
),
char(Atom::LOOP.1),
)),
cut(char(Atom::LOOP.1)),
),
)
.map(|(n, v)| Atom::Loop(n, v))
@ -151,7 +148,7 @@ where
{
context(
"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)
.parse(i)
@ -169,7 +166,7 @@ where
"slope_starts",
delimited(
char(Atom::SLOPE.0),
separated_pair(
cut(separated_pair(
separated_pair(
slope_modifier,
char(' '),
@ -180,8 +177,8 @@ where
),
char(','),
root,
),
char(Atom::SLOPE.1),
)),
cut(char(Atom::SLOPE.1)),
),
)
.map(|((sm, i), v)| Atom::Slope(sm, i, v))
@ -202,7 +199,7 @@ where
value((), comment),
value((), is_not(concatcp!(Atom::COMMENT.0, Atom::COMMENT.1))),
))),
char(Atom::COMMENT.1),
cut(char(Atom::COMMENT.1)),
),
),
)(i)
@ -218,15 +215,15 @@ where
context(
"atom",
alt((
note,
rest,
comment,
start_here,
modifier,
quick_modifier,
r#loop,
tuple,
slope,
comment,
rest,
note,
)),
)
.parse(i)

View file

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