removed the pest items for now.
This commit is contained in:
parent
786c69d840
commit
1829ff8c4a
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1088,8 +1088,6 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"config",
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"serde",
|
||||
"serial_test",
|
||||
"tide",
|
||||
|
@ -9,10 +9,7 @@ edition = "2021"
|
||||
#async-graphql = "*"
|
||||
async-std = { version = "*", features = ["attributes"] }
|
||||
config = "*"
|
||||
pest = "*"
|
||||
pest_derive = "*"
|
||||
serde = "*"
|
||||
#serde_json = "*"
|
||||
tide = "*"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -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,7 +43,12 @@ impl Database {
|
||||
async fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
async fn add_column(&self, _name: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod engine_functions {
|
||||
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user