From 1829ff8c4a922d5aa31dbd1e52e2f06ab25ccb03 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sun, 23 Oct 2022 16:55:29 -0400 Subject: [PATCH] removed the pest items for now. --- Cargo.lock | 2 - Cargo.toml | 3 -- src/main.rs | 4 -- src/morethantext/mod.rs | 71 ++++-------------------------------- src/morethantext/mttsql.pest | 8 ++-- 5 files changed, 11 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d691003..e4d4195 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,8 +1088,6 @@ version = "0.1.0" dependencies = [ "async-std", "config", - "pest", - "pest_derive", "serde", "serial_test", "tide", diff --git a/Cargo.toml b/Cargo.toml index 9aa41e8..0982732 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,7 @@ edition = "2021" #async-graphql = "*" async-std = { version = "*", features = ["attributes"] } config = "*" -pest = "*" -pest_derive = "*" serde = "*" -#serde_json = "*" tide = "*" [dev-dependencies] diff --git a/src/main.rs b/src/main.rs index 0086c54..98c5002 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,3 @@ -extern crate pest; -#[macro_use] -extern crate pest_derive; - use tide::{ http::StatusCode, sessions::{MemoryStore, SessionMiddleware}, diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index b6c4cc9..b86f85e 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -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>>, @@ -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; } } diff --git a/src/morethantext/mttsql.pest b/src/morethantext/mttsql.pest index ba00aed..f16b4b7 100644 --- a/src/morethantext/mttsql.pest +++ b/src/morethantext/mttsql.pest @@ -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}