inflate passing L1 tests

This commit is contained in:
Ponj 2024-10-14 11:17:44 -04:00
parent aa512e6206
commit 66b42e2aa0
Signed by: p6nj
GPG key ID: 6FED68D87C479A59
2 changed files with 16 additions and 7 deletions

View file

@ -8,7 +8,7 @@ use strum::EnumDiscriminants;
mod lex;
mod utils;
#[cfg_attr(test, derive(Debug, PartialEq))]
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
pub(super) enum Atom {
Note(u8),
Rest,
@ -21,7 +21,7 @@ pub(super) enum Atom {
Comment,
}
#[cfg_attr(test, derive(Debug, PartialEq))]
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
pub(super) enum FlatAtom {
Note(u8),
Rest,
@ -53,7 +53,7 @@ impl Clone for FlatAtom {
}
#[derive(Clone)]
#[cfg_attr(test, derive(Debug, PartialEq))]
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
pub(super) enum Modifier {
Volume(u8),
Octave(u8),
@ -68,7 +68,7 @@ impl Default for Modifier {
}
#[derive(QuickModifierParser, Clone)]
#[cfg_attr(test, derive(Debug, PartialEq))]
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
pub(super) enum QuickModifier {
Volume(bool),
Octave(bool),
@ -77,7 +77,7 @@ pub(super) enum QuickModifier {
}
#[derive(Clone, Copy, SlopeModifierParser)]
#[cfg_attr(test, derive(Debug, PartialEq))]
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
pub(super) enum SlopeModifier {
Note,
Volume,

View file

@ -6,6 +6,7 @@ mod tests;
// TODO: replace panics with custom error type
fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
#[derive(EnumDiscriminants)]
#[cfg_attr(debug_assertions, derive(Debug))]
enum CurrentStack {
Loop(NonZeroU8),
Tuple,
@ -17,6 +18,14 @@ fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
let mut slope_stack: Vec<Vec<Atom>> = Vec::new();
let mut stack_history: Vec<CurrentStack> = Vec::new();
for mut atom in flat_atoms.into_iter() {
// #[cfg(test)]
// {
// dbg!(&atom);
// dbg!(&loop_stack);
// dbg!(&tuple_stack);
// dbg!(&slope_stack);
// dbg!(&stack_history);
// }
if let Some(stack) = stack_history.last() {
match CurrentStackDiscriminants::from(stack) {
CurrentStackDiscriminants::Loop => match atom {
@ -92,7 +101,7 @@ fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
stack_history.push(CurrentStack::Tuple);
}
FlatAtom::TupleEnds => {
let popped = loop_stack.pop().unwrap();
let popped = tuple_stack.pop().unwrap();
if stack_history.len() > 1 {
match CurrentStackDiscriminants::from(
stack_history.get(stack_history.len() - 2).unwrap(),
@ -140,7 +149,7 @@ fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
stack_history.push(CurrentStack::Slope(s, i));
}
FlatAtom::SlopeEnds => {
let popped = loop_stack.pop().unwrap();
let popped = slope_stack.pop().unwrap();
if stack_history.len() > 1 {
match CurrentStackDiscriminants::from(
stack_history.get(stack_history.len() - 2).unwrap(),