Remove unused code files

This commit is contained in:
NGnius (Graham) 2022-03-27 11:52:59 -04:00
parent d88ec8951a
commit 313c7e9ab7
3 changed files with 0 additions and 191 deletions

View file

@ -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<MpsToken>, vocab: MpsLanguageDictionary) -> Result<Self, SyntaxError> {
vocab.try_build_statement(tokens)
}
}
impl Iterator for MpsStatement {
type Item = Result<MpsMusicItem, RuntimeError>;
fn next(&mut self) -> Option<Self::Item> {
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),
}
}
}

View file

@ -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<String>,
pub album: Option<String>,
pub filename: String,
pub genre: Option<String>,
pub track: Option<u64>,
pub year: Option<u64>,
}
impl MpsMusicItem {
pub fn map_row(row: &rusqlite::Row) -> rusqlite::Result<Self> {
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<MpsItem> 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<MpsItem> 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
}
}

View file

@ -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<T: MpsTokenReader> {
pub vocabulary: MpsLanguageDictionary,
pub tokenizer: T,
pub context: Option<MpsContext>,
}
impl<T: MpsTokenReader> MpsRunnerSettings<T> {
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<T: MpsTokenReader> {
interpretor: MpsInterpretor<T>,
new_statement: bool,
}
impl<T: MpsTokenReader> MpsRunner<T> {
pub fn with_settings(settings: MpsRunnerSettings<T>) -> 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<R: Read> MpsRunner<MpsTokenizer<R>> {
pub fn with_stream(stream: R) -> Self {
let tokenizer = MpsTokenizer::new(stream);
Self {
interpretor: MpsInterpretor::with_standard_vocab(tokenizer),
new_statement: true,
}
}
}
impl<T: MpsTokenReader> Iterator for MpsRunner<T> {
type Item = Result<MpsItem, MpsError>;
fn next(&mut self) -> Option<Self::Item> {
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
}
}