B:BD[
2.4180] → [
2.4180:5039]
fn compact(notation: String) -> Vec<Mana> {
let mut mana = HashMap::new();
let mut start_index = 0;
let mut end_index = 0;
let notation = notation.to_ascii_lowercase();
while start_index < notation.len() {
// inc end_index
end_index += 1;
let slice = ¬ation[start_index..end_index];
match slice {
"m" => {
*mana.entry(Some(Color::Mundane)).or_insert(0) += 1;
start_index = end_index;
}
"d" => {
*mana.entry(Some(Color::Divine)).or_insert(0) += 1;
start_index = end_index;
}
"r" => {
*mana.entry(Some(Color::Revelation)).or_insert(0) += 1;
start_index = end_index;
fn compact_parser<'a>() -> impl Parser<
'a,
&'a str,
Vec<(Option<Color>, usize)>,
chumsky::extra::Err<chumsky::prelude::Rich<'a, char>>,
> {
use chumsky::prelude::*;
choice((
just('m')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Mundane), s.len())),
just('d')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Divine), s.len())),
just('r')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Revelation), s.len())),
just('a')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Grace), s.len())),
just('g')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Growth), s.len())),
just('u')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Crusade), s.len())),
just('s')
.repeated()
.at_least(1)
.collect::<String>()
.map(|s: String| (Some(Color::Suffering), s.len())),
text::int(10).try_map(|i: &str, span| {
i.parse::<usize>()
.map(|i| (None, i))
.map_err(|e| Rich::custom(span, e))
}),
))
.repeated()
.collect()
}
fn compact(notation: String) -> Result<Vec<Mana>, String> {
let notation_input = notation.to_ascii_lowercase();
let (output, errs) = Self::compact_parser()
.parse(¬ation_input)
.into_output_errors();
match output {
Some(outputs) => {
let mut mana = HashMap::new();
for (maybe_color, count) in outputs.into_iter() {
*mana.entry(maybe_color).or_insert(0) += count;