complete lib structure
This commit is contained in:
parent
4b2291b7a1
commit
69b6bf9d0f
4 changed files with 109 additions and 2 deletions
|
@ -18,7 +18,8 @@ path = "src/cli/main.rs"
|
|||
[dependencies]
|
||||
anyhow = "1.0.98"
|
||||
clap = { version = "4.5.38", features = ["derive"] }
|
||||
fasteval = "0.2.4"
|
||||
derive_builder = "0.20.2"
|
||||
fasteval = { git = "https://github.com/brevalferrari/fasteval" }
|
||||
flacenc = "0.4.0"
|
||||
hound = "3.5.1"
|
||||
mp3lame-encoder = { version = "0.2.1", features = ["std"] }
|
||||
|
|
50
src/compiler.rs
Normal file
50
src/compiler.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use fasteval::Instruction;
|
||||
|
||||
pub type TokenVec = Vec<Box<dyn Token>>;
|
||||
|
||||
pub trait Token {
|
||||
fn apply(&self, context: Context) -> Context;
|
||||
}
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Silence;
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Marker;
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Note(pub u8);
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
#[derive(Clone)]
|
||||
pub struct VariableChange(pub char, pub Instruction);
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
pub struct Loop(pub usize, pub TokenVec);
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
pub struct Tuplet(pub TokenVec);
|
||||
|
||||
#[cfg_attr(debug_assertions, derive(Default))]
|
||||
pub struct Slope(pub VariableChange, pub TokenVec);
|
||||
|
||||
pub struct Context {
|
||||
pub result: Vec<f64>,
|
||||
pub variables: HashMap<char, f64>,
|
||||
pub instrument: Instruction,
|
||||
pub slopes: HashMap<char, Instruction>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn current_length(&self) -> f64 {
|
||||
todo!()
|
||||
}
|
||||
pub fn render(&self, n: Option<u8>) -> Vec<f64> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
pub struct Test;
|
||||
pub mod compiler;
|
||||
pub mod parser;
|
||||
|
|
55
src/parser.rs
Normal file
55
src/parser.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use derive_builder::Builder;
|
||||
use nom::{Compare, Input, combinator::success, error::Error};
|
||||
use nom_locate::LocatedSpan;
|
||||
|
||||
use crate::compiler::{Marker, Note, Silence, Token, VariableChange};
|
||||
|
||||
pub trait TokenParser<I, O>:
|
||||
nom::Parser<LocatedSpan<I>, Output = O, Error = Error<LocatedSpan<I>>>
|
||||
{
|
||||
}
|
||||
|
||||
impl<I, T, O> TokenParser<I, O> for T where
|
||||
T: nom::Parser<LocatedSpan<I>, Output = O, Error = Error<LocatedSpan<I>>>
|
||||
{
|
||||
}
|
||||
|
||||
pub struct ParserParametters<'n, 's, 'v, I: Input + Clone + Compare<I>, C: Into<char>> {
|
||||
pub notes: &'n [I],
|
||||
pub slopes: &'s HashMap<I, VariableChange>,
|
||||
pub variables: &'v [C],
|
||||
}
|
||||
|
||||
#[derive(Builder)]
|
||||
pub struct Parser<'i, 'n, 's, 'v, I: Input + Clone + Compare<I>, C: Into<char>> {
|
||||
input: &'i I,
|
||||
notes: &'n [I],
|
||||
slopes: &'s HashMap<I, VariableChange>,
|
||||
variables: &'v [C],
|
||||
}
|
||||
|
||||
impl<'i, 'n, 's, 'v, I: Input + Clone + Compare<I>, C: Into<char>> Parser<'i, 'n, 's, 'v, I, C> {
|
||||
pub fn parse_all() -> Result<Vec<Box<dyn Token>>, Error<nom_locate::LocatedSpan<&'i I>>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Silence {
|
||||
fn parser<I: Input>() -> impl TokenParser<I, Self> {
|
||||
success(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl Marker {
|
||||
fn parser<I: Input>() -> impl TokenParser<I, Self> {
|
||||
success(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl Note {
|
||||
fn parser<I: Input>() -> impl TokenParser<I, Self> {
|
||||
success(Default::default())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue