quick modifier parser macro

This commit is contained in:
Breval Ferrari 2024-10-10 19:43:40 -04:00
parent f9841267ec
commit 2d5291c07b
No known key found for this signature in database
GPG key ID: 6FED68D87C479A59
4 changed files with 67 additions and 3 deletions

View file

@ -1,4 +1,4 @@
use bng_macros::{ModifierParser, SlopeModifierParser};
use bng_macros::{ModifierParser, QuickModifierParser, SlopeModifierParser};
use fasteval::Instruction;
mod lex;
@ -22,6 +22,7 @@ pub(super) enum Modifier {
Tempo(u16),
}
#[derive(QuickModifierParser)]
pub(super) enum QuickModifier {
Volume(bool),
Octave(bool),

View file

@ -1,4 +1,4 @@
use super::{Atom, Modifier, SlopeModifier, WrapperKind};
use super::{Atom, Modifier, QuickModifier, SlopeModifier, WrapperKind};
pub(super) mod lexer;
@ -13,6 +13,10 @@ impl WrappingTokens {
const SQUARE_BRACKETS: (char, char) = ('[', ']');
const BRACKETS: (char, char) = ('{', '}');
const SEMICOLON_COMMA: (char, char) = (';', ',');
const PLUS_MINUS: (char, char) = ('+', '-');
const RIGHT_LEFT: (char, char) = ('>', '<');
const SLASH_BACKSLASH: (char, char) = ('/', '\\');
const QUOTE_DEG: (char, char) = ('\'', '°');
}
pub(super) trait Token<T> {
@ -30,6 +34,17 @@ impl Token<(char, char)> for WrapperKind {
}
}
impl Token<(char, char)> for QuickModifier {
fn token(self) -> (char, char) {
match self {
Self::Volume(_) => WrappingTokens::PLUS_MINUS,
Self::Octave(_) => WrappingTokens::RIGHT_LEFT,
Self::Length(_) => WrappingTokens::SLASH_BACKSLASH,
Self::Pizz(_) => WrappingTokens::QUOTE_DEG,
}
}
}
impl Token<char> for Modifier {
fn token(self) -> char {
match self {

View file

@ -1,4 +1,6 @@
use nom::IResult;
use nom::{branch::alt, character::complete::char, combinator::value, IResult, Parser};
use crate::bng::score::QuickModifier;
pub(crate) trait Parse: Sized {
fn parse(input: &str) -> IResult<&str, Self>;