From 040bb4ecb3c642077e06d9748c5c0f3edd935648 Mon Sep 17 00:00:00 2001 From: p6nj Date: Sat, 12 Oct 2024 14:08:01 -0400 Subject: [PATCH] remove WrapperType enum to ease parsing --- src/bng/score.rs | 13 ++++--------- src/bng/score/lex.rs | 13 +------------ src/bng/score/lex/lexer.rs | 6 +++++- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/bng/score.rs b/src/bng/score.rs index 2eda638..94fd3af 100644 --- a/src/bng/score.rs +++ b/src/bng/score.rs @@ -10,8 +10,10 @@ pub(super) enum Atom { StartHere, Modifier(Modifier), QuickModifier(QuickModifier), - Wrapper(WrapperKind, Vec), - EmptyWrapper(WrapperKind), + Loop(u8, Vec), + Tuple(Vec), + Slope(SlopeModifier, Instruction, Vec), + Comment, } #[derive(ModifierParser)] @@ -30,13 +32,6 @@ pub(super) enum QuickModifier { Pizz(bool), } -pub(super) enum WrapperKind { - Loop(u8), - Tuple, - Slope(SlopeModifier, Instruction), - Comment, -} - #[derive(Clone, Copy, SlopeModifierParser)] pub(super) enum SlopeModifier { Note, diff --git a/src/bng/score/lex.rs b/src/bng/score/lex.rs index 53f883a..6dce07a 100644 --- a/src/bng/score/lex.rs +++ b/src/bng/score/lex.rs @@ -1,4 +1,4 @@ -use super::{Atom, Modifier, QuickModifier, SlopeModifier, WrapperKind}; +use super::{Atom, Modifier, QuickModifier, SlopeModifier}; pub(super) mod lexer; @@ -23,17 +23,6 @@ pub(super) trait Token { fn token(self) -> T; } -impl Token<(char, char)> for WrapperKind { - fn token(self) -> (char, char) { - match self { - Self::Loop(_) => WrappingTokens::PARENTHESES, - Self::Tuple => WrappingTokens::SQUARE_BRACKETS, - Self::Slope(_, _) => WrappingTokens::BRACKETS, - WrapperKind::Comment => WrappingTokens::SEMICOLON_COMMA, - } - } -} - impl Token<(char, char)> for QuickModifier { fn token(self) -> (char, char) { match self { diff --git a/src/bng/score/lex/lexer.rs b/src/bng/score/lex/lexer.rs index 2a02856..1c9690a 100644 --- a/src/bng/score/lex/lexer.rs +++ b/src/bng/score/lex/lexer.rs @@ -1,7 +1,11 @@ -use nom::{branch::alt, character::complete::char, combinator::value, IResult, Parser}; +use nom::{ + branch::alt, character::complete::char, combinator::value, sequence::delimited, IResult, Parser, +}; use crate::bng::score::QuickModifier; +use super::Token; + pub(crate) trait Parse: Sized { fn parse(input: &str) -> IResult<&str, Self>; }