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 = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"config",
|
"config",
|
||||||
"pest",
|
|
||||||
"pest_derive",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
"tide",
|
"tide",
|
||||||
|
@ -9,10 +9,7 @@ edition = "2021"
|
|||||||
#async-graphql = "*"
|
#async-graphql = "*"
|
||||||
async-std = { version = "*", features = ["attributes"] }
|
async-std = { version = "*", features = ["attributes"] }
|
||||||
config = "*"
|
config = "*"
|
||||||
pest = "*"
|
|
||||||
pest_derive = "*"
|
|
||||||
serde = "*"
|
serde = "*"
|
||||||
#serde_json = "*"
|
|
||||||
tide = "*"
|
tide = "*"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
extern crate pest;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate pest_derive;
|
|
||||||
|
|
||||||
use tide::{
|
use tide::{
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
sessions::{MemoryStore, SessionMiddleware},
|
sessions::{MemoryStore, SessionMiddleware},
|
||||||
|
@ -2,21 +2,8 @@ pub mod error;
|
|||||||
|
|
||||||
use async_std::sync::{Arc, RwLock};
|
use async_std::sync::{Arc, RwLock};
|
||||||
use error::DBError;
|
use error::DBError;
|
||||||
use pest::Parser;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
enum Ast {
|
|
||||||
Script,
|
|
||||||
Command,
|
|
||||||
Action,
|
|
||||||
Object,
|
|
||||||
Name,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
|
||||||
#[grammar = "morethantext/mttsql.pest"]
|
|
||||||
struct MTTSQL;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MoreThanText {
|
pub struct MoreThanText {
|
||||||
databases: Arc<RwLock<HashMap<String, Database>>>,
|
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> {
|
async fn create_database(&self, name: &str) -> Result<(), DBError> {
|
||||||
let mut databases = self.databases.write().await;
|
let mut databases = self.databases.write().await;
|
||||||
match databases.get(name) {
|
match databases.get(name) {
|
||||||
@ -78,8 +43,13 @@ impl Database {
|
|||||||
async fn new() -> Self {
|
async fn new() -> Self {
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn add_column(&self, _name: &str) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod engine_functions {
|
mod engine_functions {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -149,35 +119,10 @@ mod database_functions {
|
|||||||
async fn new_database() {
|
async fn new_database() {
|
||||||
Database::new().await;
|
Database::new().await;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod mtt_commands {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn create_database() {
|
async fn new_ccolumn() {
|
||||||
let mtt = MoreThanText::new().await;
|
let db = Database::new().await;
|
||||||
mtt.execute("create database fred;").await.unwrap();
|
db.add_column("fred").await;
|
||||||
}
|
|
||||||
|
|
||||||
#[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
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
whitespace = _{" " | "\t" | "\r" | "\n"}
|
|
||||||
action = {"create"}
|
|
||||||
object = {"database"}
|
|
||||||
char = _{ ASCII_ALPHANUMERIC | "_" }
|
char = _{ ASCII_ALPHANUMERIC | "_" }
|
||||||
|
whitespace = _{" " | "\t" | "\r" | "\n"}
|
||||||
|
|
||||||
name = {char+}
|
name = {char+}
|
||||||
command = {whitespace* ~ action ~ whitespace+ ~ object ~ whitespace+ ~ name ~ whitespace* ~ ";" ~ whitespace*}
|
command = {"create database" ~ whitespace+ ~ name ~ ";"}
|
||||||
script = {command+}
|
script = {command+}
|
||||||
file = _{SOI ~ script ~ EOI}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user