From 6dffde0cb765d7298b642adc2a2968cf40396345 Mon Sep 17 00:00:00 2001 From: p6nj Date: Sun, 10 Nov 2024 00:50:04 -0500 Subject: [PATCH] fix everything!!!! :D --- poc/poc.yml | 2 +- src/bng/score/de.rs | 3 ++- src/bng/score/lex/lexer.rs | 37 +++++++++++++++----------------- src/bng/score/lex/lexer/tests.rs | 6 +++--- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/poc/poc.yml b/poc/poc.yml index 92c4b32..87f09d9 100644 --- a/poc/poc.yml +++ b/poc/poc.yml @@ -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, diff --git a/src/bng/score/de.rs b/src/bng/score/de.rs index 459e232..cf5aba7 100644 --- a/src/bng/score/de.rs +++ b/src/bng/score/de.rs @@ -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) diff --git a/src/bng/score/lex/lexer.rs b/src/bng/score/lex/lexer.rs index ef37ccc..75c552e 100644 --- a/src/bng/score/lex/lexer.rs +++ b/src/bng/score/lex/lexer.rs @@ -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) diff --git a/src/bng/score/lex/lexer/tests.rs b/src/bng/score/lex/lexer/tests.rs index 55d7675..8e73570 100644 --- a/src/bng/score/lex/lexer/tests.rs +++ b/src/bng/score/lex/lexer/tests.rs @@ -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)) )