removed the pest items for now.
This commit is contained in:
		@@ -1,7 +1,3 @@
 | 
			
		||||
extern crate pest;
 | 
			
		||||
#[macro_use]
 | 
			
		||||
extern crate pest_derive;
 | 
			
		||||
 | 
			
		||||
use tide::{
 | 
			
		||||
    http::StatusCode,
 | 
			
		||||
    sessions::{MemoryStore, SessionMiddleware},
 | 
			
		||||
 
 | 
			
		||||
@@ -2,21 +2,8 @@ pub mod error;
 | 
			
		||||
 | 
			
		||||
use async_std::sync::{Arc, RwLock};
 | 
			
		||||
use error::DBError;
 | 
			
		||||
use pest::Parser;
 | 
			
		||||
use std::collections::HashMap;
 | 
			
		||||
 | 
			
		||||
enum Ast {
 | 
			
		||||
    Script,
 | 
			
		||||
    Command,
 | 
			
		||||
    Action,
 | 
			
		||||
    Object,
 | 
			
		||||
    Name,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Parser)]
 | 
			
		||||
#[grammar = "morethantext/mttsql.pest"]
 | 
			
		||||
struct MTTSQL;
 | 
			
		||||
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
pub struct MoreThanText {
 | 
			
		||||
    databases: Arc<RwLock<HashMap<String, Database>>>,
 | 
			
		||||
@@ -29,28 +16,6 @@ impl MoreThanText {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn execute(&self, script: &str) -> Result<(), DBError> {
 | 
			
		||||
        match MTTSQL::parse(Rule::file, script) {
 | 
			
		||||
            Ok(mut commands) => {
 | 
			
		||||
                let pair = commands.next().unwrap();
 | 
			
		||||
                match pair.as_rule() {
 | 
			
		||||
                    Rule::script => Ast::Script,
 | 
			
		||||
                    Rule::command => Ast::Command,
 | 
			
		||||
                    Rule::action => Ast::Action,
 | 
			
		||||
                    Rule::object => Ast::Object,
 | 
			
		||||
                    Rule::name => Ast::Name,
 | 
			
		||||
                    Rule::char | Rule::whitespace | Rule::file | Rule::EOI => unreachable!(),
 | 
			
		||||
                };
 | 
			
		||||
                Ok(())
 | 
			
		||||
            }
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                let mut error = DBError::new("script parsing error");
 | 
			
		||||
                error.add_source(err);
 | 
			
		||||
                Err(error)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn create_database(&self, name: &str) -> Result<(), DBError> {
 | 
			
		||||
        let mut databases = self.databases.write().await;
 | 
			
		||||
        match databases.get(name) {
 | 
			
		||||
@@ -78,8 +43,13 @@ impl Database {
 | 
			
		||||
    async fn new() -> Self {
 | 
			
		||||
        Self {}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn add_column(&self, _name: &str) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod engine_functions {
 | 
			
		||||
    use super::*;
 | 
			
		||||
@@ -149,35 +119,10 @@ mod database_functions {
 | 
			
		||||
    async fn new_database() {
 | 
			
		||||
        Database::new().await;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod mtt_commands {
 | 
			
		||||
    use super::*;
 | 
			
		||||
 | 
			
		||||
    #[async_std::test]
 | 
			
		||||
    async fn create_database() {
 | 
			
		||||
        let mtt = MoreThanText::new().await;
 | 
			
		||||
        mtt.execute("create database fred;").await.unwrap();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[async_std::test]
 | 
			
		||||
    async fn unsuccessful_parse() -> Result<(), DBError> {
 | 
			
		||||
        let msg = "script parsing error";
 | 
			
		||||
        let mtt = MoreThanText::new().await;
 | 
			
		||||
        match mtt.execute("#$%^&").await {
 | 
			
		||||
            Ok(_) => Err(DBError::new("Should show a parse failure.")),
 | 
			
		||||
            Err(err) => {
 | 
			
		||||
                if err.to_string() == msg {
 | 
			
		||||
                    Ok(())
 | 
			
		||||
                } else {
 | 
			
		||||
                    Err(DBError::new(format!(
 | 
			
		||||
                        "Error message is incorrect: Got: '{}' Want: '{}'",
 | 
			
		||||
                        err.to_string(),
 | 
			
		||||
                        msg
 | 
			
		||||
                    )))
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    async fn new_ccolumn() {
 | 
			
		||||
        let db = Database::new().await;
 | 
			
		||||
        db.add_column("fred").await;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,6 @@
 | 
			
		||||
whitespace = _{" " | "\t" | "\r" | "\n"}
 | 
			
		||||
action = {"create"}
 | 
			
		||||
object = {"database"}
 | 
			
		||||
char = _{ ASCII_ALPHANUMERIC | "_" }
 | 
			
		||||
whitespace = _{" " | "\t" | "\r" | "\n"}
 | 
			
		||||
 | 
			
		||||
name = {char+}
 | 
			
		||||
command = {whitespace* ~ action ~ whitespace+ ~ object ~ whitespace+ ~ name ~ whitespace* ~ ";" ~ whitespace*}
 | 
			
		||||
command = {"create database" ~ whitespace+ ~ name ~ ";"}
 | 
			
		||||
script = {command+}
 | 
			
		||||
file = _{SOI ~ script ~ EOI}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user