diff --git a/mps-interpreter/src/lang/statement.rs b/mps-interpreter/src/lang/statement.rs deleted file mode 100644 index b8ec249..0000000 --- a/mps-interpreter/src/lang/statement.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::iter::Iterator; -use std::fmt::{Debug, Display, Formatter, Error}; - -use std::collections::VecDeque; - -use crate::tokens::MpsToken; -use crate::MpsMusicItem; - -use super::SqlStatement; -use super::{SyntaxError, RuntimeError}; -use super::MpsLanguageDictionary; - -#[derive(Debug)] -pub enum MpsStatement { - Sql(SqlStatement), -} - -impl MpsStatement { - pub fn eat_some(tokens: &mut VecDeque, vocab: MpsLanguageDictionary) -> Result { - vocab.try_build_statement(tokens) - } -} - -impl Iterator for MpsStatement { - type Item = Result; - - fn next(&mut self) -> Option { - match self { - MpsStatement::Sql(s) => s.next(), - } - } -} - -impl Display for MpsStatement { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - match self { - Self::Sql(s) => write!(f, "{}", s), - } - } -} diff --git a/mps-interpreter/src/music_item.rs b/mps-interpreter/src/music_item.rs deleted file mode 100644 index a2af4e8..0000000 --- a/mps-interpreter/src/music_item.rs +++ /dev/null @@ -1,80 +0,0 @@ -use super::lang::db::{ - DatabaseObj, DbAlbumItem, DbArtistItem, DbGenreItem, DbMetaItem, DbMusicItem, -}; -use super::MpsItem; - -#[derive(Clone, Debug)] -pub struct MpsMusicItem { - pub title: String, - pub artist: Option, - pub album: Option, - pub filename: String, - pub genre: Option, - pub track: Option, - pub year: Option, -} - -impl MpsMusicItem { - pub fn map_row(row: &rusqlite::Row) -> rusqlite::Result { - let item = DbMusicItem::map_row(row)?; - Ok(Self { - title: item.title, - artist: None, - album: None, - filename: item.filename, - genre: None, - track: None, - year: None, - }) - } - - pub fn merge( - music: DbMusicItem, - artist: DbArtistItem, - album: DbAlbumItem, - meta: DbMetaItem, - genre: DbGenreItem, - ) -> Self { - Self { - title: music.title, - artist: Some(artist.name), - album: Some(album.title), - filename: music.filename, - genre: Some(genre.title), - track: Some(meta.track), - year: Some(meta.date), - } - } -} - -impl std::convert::From for MpsMusicItem { - fn from(mut item: MpsItem) -> Self { - let default_str = "".to_string(); - Self { - title: item.remove_field("title").and_then(|x| x.to_str()).unwrap_or(default_str.clone()), - artist: item.remove_field("artist").and_then(|x| x.to_str()), - album: item.remove_field("album").and_then(|x| x.to_str()), - filename: item.remove_field("filename").and_then(|x| x.to_str()).unwrap_or(default_str), - genre: item.remove_field("genre").and_then(|x| x.to_str()), - track: item.remove_field("track").and_then(|x| x.to_u64()), - year: item.remove_field("year").and_then(|x| x.to_u64()), - } - } -} - -impl std::convert::Into for MpsMusicItem { - fn into(self) -> MpsItem { - let mut result = MpsItem::new(); - result.set_field("title", self.title.into()); - result.set_field("filename", self.filename.into()); - - if let Some(artist) = self.artist {result.set_field("artist", artist.into());} - if let Some(album) = self.album {result.set_field("album", album.into());} - if let Some(genre) = self.genre {result.set_field("genre", genre.into());} - - if let Some(track) = self.track {result.set_field("track", track.into());} - if let Some(year) = self.year {result.set_field("year", year.into());} - - result - } -} diff --git a/mps-interpreter/src/runner.rs b/mps-interpreter/src/runner.rs deleted file mode 100644 index f1e7476..0000000 --- a/mps-interpreter/src/runner.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::io::Read; -use std::iter::Iterator; - -use super::lang::MpsLanguageDictionary; -use super::tokens::{MpsTokenReader, MpsTokenizer}; -use super::{MpsContext, MpsError, MpsInterpretor, MpsItem}; - -pub struct MpsRunnerSettings { - pub vocabulary: MpsLanguageDictionary, - pub tokenizer: T, - pub context: Option, -} - -impl MpsRunnerSettings { - pub fn default_with_tokenizer(token_reader: T) -> Self { - let mut vocab = MpsLanguageDictionary::default(); - super::interpretor::standard_vocab(&mut vocab); - Self { - vocabulary: vocab, - tokenizer: token_reader, - context: None, - } - } -} - -/// A wrapper around MpsInterpretor which provides a simpler (and more powerful) interface. -pub struct MpsRunner { - interpretor: MpsInterpretor, - new_statement: bool, -} - -impl MpsRunner { - pub fn with_settings(settings: MpsRunnerSettings) -> Self { - let mut interpretor = MpsInterpretor::with_vocab(settings.tokenizer, settings.vocabulary); - if let Some(ctx) = settings.context { - interpretor.context(ctx); - } - Self { - interpretor, - new_statement: true, - } - } - - pub fn is_new_statement(&self) -> bool { - self.new_statement - } -} - -impl MpsRunner> { - pub fn with_stream(stream: R) -> Self { - let tokenizer = MpsTokenizer::new(stream); - Self { - interpretor: MpsInterpretor::with_standard_vocab(tokenizer), - new_statement: true, - } - } -} - -impl Iterator for MpsRunner { - type Item = Result; - - fn next(&mut self) -> Option { - let mut item = self.interpretor.next(); - self.new_statement = false; - while item.is_none() && !self.interpretor.is_done() { - item = self.interpretor.next(); - self.new_statement = true; - } - item - } -}