move things around, add curry
This commit is contained in:
parent
315238f14d
commit
900b8b198e
4 changed files with 35 additions and 26 deletions
|
@ -21,6 +21,7 @@ bng_macros = { path = "bng_macros" }
|
||||||
const_format = "0.2.33"
|
const_format = "0.2.33"
|
||||||
thiserror = "1.0.64"
|
thiserror = "1.0.64"
|
||||||
derive-new = "0.7.0"
|
derive-new = "0.7.0"
|
||||||
|
naan = "0.1.32"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["play", "save"]
|
default = ["play", "save"]
|
||||||
|
|
|
@ -8,7 +8,6 @@ use anyhow::Context;
|
||||||
use bng_macros::{ModifierParser, QuickModifierParser, SlopeModifierParser};
|
use bng_macros::{ModifierParser, QuickModifierParser, SlopeModifierParser};
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use derived_deref::Deref;
|
use derived_deref::Deref;
|
||||||
use lex::lexer::atom;
|
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
character::{complete::char, streaming::one_of},
|
character::{complete::char, streaming::one_of},
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
num::TryFromIntError,
|
num::TryFromIntError,
|
||||||
|
ops::Deref,
|
||||||
};
|
};
|
||||||
|
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
|
use naan::fun::{F1Once, F2Once};
|
||||||
use nom::{
|
use nom::{
|
||||||
character::complete::one_of,
|
character::complete::one_of,
|
||||||
combinator::all_consuming,
|
combinator::all_consuming,
|
||||||
|
@ -18,7 +20,7 @@ use serde::{
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::bng::score::lex::lexer::atom;
|
use crate::bng::score::lex::lexer::root;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
utils::{inflate, InflateError},
|
utils::{inflate, InflateError},
|
||||||
|
@ -54,11 +56,7 @@ impl<'de> Deserialize<'de> for Atoms {
|
||||||
Ok(Default::default())
|
Ok(Default::default())
|
||||||
} else {
|
} else {
|
||||||
root(&sheet, ¬es)
|
root(&sheet, ¬es)
|
||||||
.map_err(|e: nom::Err<VerboseError<&str>>| match e {
|
.map_err(|e| pretty_verbose_err.curry().call1(sheet.as_str()).call1(e))
|
||||||
nom::Err::Incomplete(Needed::Unknown) => "needed some more bytes".to_string(),
|
|
||||||
nom::Err::Incomplete(Needed::Size(n)) => format!("needed {} more bytes", n),
|
|
||||||
nom::Err::Error(e) | nom::Err::Failure(e) => convert_error(sheet.as_str(), e),
|
|
||||||
})
|
|
||||||
.map_err(AtomsSerializeError::Parsing)
|
.map_err(AtomsSerializeError::Parsing)
|
||||||
.map_err(de::Error::custom)
|
.map_err(de::Error::custom)
|
||||||
.and_then(|(_, v)| {
|
.and_then(|(_, v)| {
|
||||||
|
@ -71,22 +69,13 @@ impl<'de> Deserialize<'de> for Atoms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_yml_str_space<'a, E>() -> impl Parser<&'a str, Vec<char>, E>
|
fn pretty_verbose_err<I>(input: I, e: nom::Err<VerboseError<I>>) -> String
|
||||||
where
|
where
|
||||||
E: nom::error::ParseError<&'a str> + ContextError<&'a str>,
|
I: Deref<Target = str>,
|
||||||
{
|
{
|
||||||
context("yml white space", many0(one_of(" \t\r\n")))
|
match e {
|
||||||
|
nom::Err::Incomplete(Needed::Unknown) => "needed some more bytes".to_string(),
|
||||||
|
nom::Err::Incomplete(Needed::Size(n)) => format!("needed {} more bytes", n),
|
||||||
|
nom::Err::Error(e) | nom::Err::Failure(e) => convert_error(input, e),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn root<'a, E>(i: &'a str, notes: &'a str) -> IResult<&'a str, Vec<FlatAtom>, E>
|
|
||||||
where
|
|
||||||
E: ParseError<&'a str>
|
|
||||||
+ ContextError<&'a str>
|
|
||||||
+ FromExternalError<&'a str, TryFromIntError>
|
|
||||||
+ FromExternalError<&'a str, E>,
|
|
||||||
{
|
|
||||||
all_consuming(terminated(
|
|
||||||
many1(preceded(maybe_yml_str_space(), atom(notes))),
|
|
||||||
maybe_yml_str_space(),
|
|
||||||
))(i)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{take_till, take_till1},
|
bytes::complete::{take_till, take_till1},
|
||||||
character::complete::{anychar, char, one_of, space1, u16, u8},
|
character::complete::{anychar, char, one_of, space1, u16, u8},
|
||||||
combinator::{map_opt, map_res, opt, value, verify},
|
combinator::{all_consuming, map_opt, map_res, opt, value, verify},
|
||||||
error::{context, ContextError, ErrorKind, FromExternalError, ParseError},
|
error::{context, ContextError, ErrorKind, FromExternalError, ParseError},
|
||||||
multi::many0,
|
multi::{many0, many1},
|
||||||
sequence::{delimited, pair, preceded, separated_pair, terminated},
|
sequence::{delimited, pair, preceded, separated_pair, terminated},
|
||||||
Err, IResult, Parser,
|
Err, IResult, Parser,
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,27 @@ use super::{
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub fn atom<'a, E>(notes: &'a str) -> impl Parser<&'a str, FlatAtom, E>
|
fn maybe_yml_str_space<'a, E>() -> impl Parser<&'a str, Vec<char>, E>
|
||||||
|
where
|
||||||
|
E: nom::error::ParseError<&'a str> + ContextError<&'a str>,
|
||||||
|
{
|
||||||
|
context("yml white space", many0(one_of(" \t\r\n")))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn root<'a, E>(i: &'a str, notes: &'a str) -> IResult<&'a str, Vec<FlatAtom>, E>
|
||||||
|
where
|
||||||
|
E: ParseError<&'a str>
|
||||||
|
+ ContextError<&'a str>
|
||||||
|
+ FromExternalError<&'a str, TryFromIntError>
|
||||||
|
+ FromExternalError<&'a str, E>,
|
||||||
|
{
|
||||||
|
all_consuming(terminated(
|
||||||
|
many1(preceded(maybe_yml_str_space(), atom(notes))),
|
||||||
|
maybe_yml_str_space(),
|
||||||
|
))(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn atom<'a, E>(notes: &'a str) -> impl Parser<&'a str, FlatAtom, E>
|
||||||
where
|
where
|
||||||
E: ParseError<&'a str>
|
E: ParseError<&'a str>
|
||||||
+ ContextError<&'a str>
|
+ ContextError<&'a str>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue