inflate passing L1 tests
This commit is contained in:
parent
aa512e6206
commit
66b42e2aa0
2 changed files with 16 additions and 7 deletions
|
@ -8,7 +8,7 @@ use strum::EnumDiscriminants;
|
||||||
mod lex;
|
mod lex;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
|
||||||
pub(super) enum Atom {
|
pub(super) enum Atom {
|
||||||
Note(u8),
|
Note(u8),
|
||||||
Rest,
|
Rest,
|
||||||
|
@ -21,7 +21,7 @@ pub(super) enum Atom {
|
||||||
Comment,
|
Comment,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
|
||||||
pub(super) enum FlatAtom {
|
pub(super) enum FlatAtom {
|
||||||
Note(u8),
|
Note(u8),
|
||||||
Rest,
|
Rest,
|
||||||
|
@ -53,7 +53,7 @@ impl Clone for FlatAtom {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
|
||||||
pub(super) enum Modifier {
|
pub(super) enum Modifier {
|
||||||
Volume(u8),
|
Volume(u8),
|
||||||
Octave(u8),
|
Octave(u8),
|
||||||
|
@ -68,7 +68,7 @@ impl Default for Modifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(QuickModifierParser, Clone)]
|
#[derive(QuickModifierParser, Clone)]
|
||||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
|
||||||
pub(super) enum QuickModifier {
|
pub(super) enum QuickModifier {
|
||||||
Volume(bool),
|
Volume(bool),
|
||||||
Octave(bool),
|
Octave(bool),
|
||||||
|
@ -77,7 +77,7 @@ pub(super) enum QuickModifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, SlopeModifierParser)]
|
#[derive(Clone, Copy, SlopeModifierParser)]
|
||||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
#[cfg_attr(debug_assertions, derive(Debug, PartialEq))]
|
||||||
pub(super) enum SlopeModifier {
|
pub(super) enum SlopeModifier {
|
||||||
Note,
|
Note,
|
||||||
Volume,
|
Volume,
|
||||||
|
|
|
@ -6,6 +6,7 @@ mod tests;
|
||||||
// TODO: replace panics with custom error type
|
// TODO: replace panics with custom error type
|
||||||
fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
|
fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
|
||||||
#[derive(EnumDiscriminants)]
|
#[derive(EnumDiscriminants)]
|
||||||
|
#[cfg_attr(debug_assertions, derive(Debug))]
|
||||||
enum CurrentStack {
|
enum CurrentStack {
|
||||||
Loop(NonZeroU8),
|
Loop(NonZeroU8),
|
||||||
Tuple,
|
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 slope_stack: Vec<Vec<Atom>> = Vec::new();
|
||||||
let mut stack_history: Vec<CurrentStack> = Vec::new();
|
let mut stack_history: Vec<CurrentStack> = Vec::new();
|
||||||
for mut atom in flat_atoms.into_iter() {
|
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() {
|
if let Some(stack) = stack_history.last() {
|
||||||
match CurrentStackDiscriminants::from(stack) {
|
match CurrentStackDiscriminants::from(stack) {
|
||||||
CurrentStackDiscriminants::Loop => match atom {
|
CurrentStackDiscriminants::Loop => match atom {
|
||||||
|
@ -92,7 +101,7 @@ fn inflate(mut flat_atoms: Vec<FlatAtom>) -> Vec<Atom> {
|
||||||
stack_history.push(CurrentStack::Tuple);
|
stack_history.push(CurrentStack::Tuple);
|
||||||
}
|
}
|
||||||
FlatAtom::TupleEnds => {
|
FlatAtom::TupleEnds => {
|
||||||
let popped = loop_stack.pop().unwrap();
|
let popped = tuple_stack.pop().unwrap();
|
||||||
if stack_history.len() > 1 {
|
if stack_history.len() > 1 {
|
||||||
match CurrentStackDiscriminants::from(
|
match CurrentStackDiscriminants::from(
|
||||||
stack_history.get(stack_history.len() - 2).unwrap(),
|
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));
|
stack_history.push(CurrentStack::Slope(s, i));
|
||||||
}
|
}
|
||||||
FlatAtom::SlopeEnds => {
|
FlatAtom::SlopeEnds => {
|
||||||
let popped = loop_stack.pop().unwrap();
|
let popped = slope_stack.pop().unwrap();
|
||||||
if stack_history.len() > 1 {
|
if stack_history.len() > 1 {
|
||||||
match CurrentStackDiscriminants::from(
|
match CurrentStackDiscriminants::from(
|
||||||
stack_history.get(stack_history.len() - 2).unwrap(),
|
stack_history.get(stack_history.len() - 2).unwrap(),
|
||||||
|
|
Loading…
Reference in a new issue