avoid parsing if string is empty
This commit is contained in:
parent
2176f5dd89
commit
304a360608
2 changed files with 8 additions and 4 deletions
|
@ -33,7 +33,7 @@ pub use de::*;
|
|||
|
||||
use super::Expression as Instruction;
|
||||
|
||||
#[derive(Deref, From)]
|
||||
#[derive(Deref, From, Default)]
|
||||
#[cfg_attr(debug_assertions, derive(Serialize, Debug))]
|
||||
pub struct Atoms(Vec<Atom>);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use derive_new::new;
|
|||
use nom::{
|
||||
character::complete::one_of,
|
||||
combinator::all_consuming,
|
||||
multi::many0,
|
||||
multi::{many0, many1},
|
||||
sequence::{preceded, terminated},
|
||||
Parser,
|
||||
};
|
||||
|
@ -108,7 +108,11 @@ impl<'de> Deserialize<'de> for Atoms {
|
|||
const FIELDS: &[&str] = &["notes", "sheet"];
|
||||
let NotesSheet { notes, sheet } =
|
||||
deserializer.deserialize_struct("NotesSheet", FIELDS, NotesSheetVisitor)?;
|
||||
flat_atom_parser_mapper::<D, _>(&sheet, flat_atom_parser(¬es))
|
||||
if sheet.is_empty() {
|
||||
Ok(Default::default())
|
||||
} else {
|
||||
flat_atom_parser_mapper::<D, _>(&sheet, flat_atom_parser(¬es))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +132,7 @@ where
|
|||
P: Parser<&'a str, FlatAtom, nom::error::Error<&'a str>>,
|
||||
{
|
||||
all_consuming(terminated(
|
||||
many0(preceded(maybe_yml_str_space(), parser)),
|
||||
many1(preceded(maybe_yml_str_space(), parser)),
|
||||
maybe_yml_str_space(),
|
||||
))(input)
|
||||
.map_err(nom_err_message)
|
||||
|
|
Loading…
Reference in a new issue