Put parsing details into one module
This commit is contained in:
parent
61c0a34253
commit
6000b1f242
10 changed files with 30 additions and 29 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use minisql::{operation::Operation, schema::TableSchema};
|
use minisql::{operation::Operation, schema::TableSchema};
|
||||||
use nom::{branch::alt, multi::many0, IResult};
|
use nom::{branch::alt, multi::many0, IResult};
|
||||||
|
|
||||||
use crate::{create::parse_create, delete::parse_delete, index::parse_create_index, insert::parse_insert, select::parse_select, validation::{validate_operation, ValidationError}};
|
use crate::{parsing::{create::parse_create, delete::parse_delete, index::parse_create_index, insert::parse_insert, select::parse_select}, validation::{validate_operation, ValidationError}};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
@ -38,4 +38,4 @@ pub fn parse_and_validate(query: String, db_metadata: &Vec<(String, &TableSchema
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn test_select() {
|
// fn test_select() {
|
||||||
// parse_and_validate("SELECT * FROM users;".to_string(), &Vec::new()).unwrap();
|
// parse_and_validate("SELECT * FROM users;".to_string(), &Vec::new()).unwrap();
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,5 @@
|
||||||
|
|
||||||
mod literal;
|
mod parsing;
|
||||||
mod select;
|
|
||||||
mod common;
|
|
||||||
mod create;
|
|
||||||
mod insert;
|
|
||||||
mod delete;
|
|
||||||
mod index;
|
|
||||||
mod validation;
|
mod validation;
|
||||||
mod core;
|
mod core;
|
||||||
|
|
||||||
|
|
@ -13,4 +7,4 @@ pub use core::parse_and_validate;
|
||||||
pub use core::Error;
|
pub use core::Error;
|
||||||
pub use validation::validate_operation;
|
pub use validation::validate_operation;
|
||||||
|
|
||||||
pub use minisql;
|
pub use minisql;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use nom::{
|
||||||
};
|
};
|
||||||
use minisql::{operation::Condition, type_system::DbType};
|
use minisql::{operation::Condition, type_system::DbType};
|
||||||
|
|
||||||
use crate::literal::parse_db_value;
|
use super::literal::parse_db_value;
|
||||||
|
|
||||||
pub fn parse_table_name(input: &str) -> IResult<&str, &str> {
|
pub fn parse_table_name(input: &str) -> IResult<&str, &str> {
|
||||||
alt((
|
alt((
|
||||||
|
|
@ -68,7 +68,7 @@ fn parse_equality(input: &str) -> IResult<&str, Condition> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minisql::{operation::Condition, type_system::DbType};
|
use minisql::{operation::Condition, type_system::DbType};
|
||||||
use crate::common::{parse_db_type, parse_equality};
|
use crate::parsing::common::{parse_db_type, parse_equality};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_equality() {
|
fn test_parse_equality() {
|
||||||
|
|
@ -92,4 +92,4 @@ mod tests {
|
||||||
assert!(matches!(parse_db_type("NUMBER").expect("should parse").1, DbType::Number));
|
assert!(matches!(parse_db_type("NUMBER").expect("should parse").1, DbType::Number));
|
||||||
assert!(matches!(parse_db_type("Unknown"), Err(_)));
|
assert!(matches!(parse_db_type("Unknown"), Err(_)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ use nom::{
|
||||||
IResult, combinator::opt,
|
IResult, combinator::opt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::common::{parse_table_name, parse_identifier, parse_db_type};
|
use super::common::{parse_table_name, parse_identifier, parse_db_type};
|
||||||
|
|
||||||
pub fn parse_create(input: &str) -> IResult<&str, Operation> {
|
pub fn parse_create(input: &str) -> IResult<&str, Operation> {
|
||||||
let (input, _) = tag("CREATE")(input)?;
|
let (input, _) = tag("CREATE")(input)?;
|
||||||
|
|
@ -69,7 +69,7 @@ pub fn parse_column_definition(input: &str) -> IResult<&str, (ColumnName, DbType
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minisql::operation::Operation;
|
use minisql::operation::Operation;
|
||||||
use crate::create::parse_create;
|
use crate::parsing::create::parse_create;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_create_no_spaces() {
|
fn test_parse_create_no_spaces() {
|
||||||
|
|
@ -106,4 +106,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ use nom::{
|
||||||
IResult,
|
IResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::common::{parse_table_name, parse_condition};
|
use super::common::{parse_table_name, parse_condition};
|
||||||
|
|
||||||
pub fn parse_delete(input: &str) -> IResult<&str, Operation> {
|
pub fn parse_delete(input: &str) -> IResult<&str, Operation> {
|
||||||
let (input, _) = tag("DELETE")(input)?;
|
let (input, _) = tag("DELETE")(input)?;
|
||||||
|
|
@ -26,7 +26,7 @@ pub fn parse_delete(input: &str) -> IResult<&str, Operation> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minisql::operation::Operation;
|
use minisql::operation::Operation;
|
||||||
use crate::delete::parse_delete;
|
use crate::parsing::delete::parse_delete;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_delete() {
|
fn test_parse_delete() {
|
||||||
|
|
@ -35,4 +35,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add test with condition
|
// TODO: add test with condition
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ use nom::{
|
||||||
IResult, combinator::opt,
|
IResult, combinator::opt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::common::{parse_identifier, parse_table_name};
|
use super::common::{parse_identifier, parse_table_name};
|
||||||
|
|
||||||
pub fn parse_create_index(input: &str) -> IResult<&str, Operation> {
|
pub fn parse_create_index(input: &str) -> IResult<&str, Operation> {
|
||||||
let (input, _) = tag("CREATE")(input)?;
|
let (input, _) = tag("CREATE")(input)?;
|
||||||
|
|
@ -39,7 +39,7 @@ pub fn parse_create_index(input: &str) -> IResult<&str, Operation> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minisql::operation::Operation;
|
use minisql::operation::Operation;
|
||||||
use crate::index::parse_create_index;
|
use crate::parsing::index::parse_create_index;
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -67,4 +67,4 @@ mod tests {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{literal::parse_db_value, common::{parse_table_name, parse_identifier}};
|
use super::{literal::parse_db_value, common::{parse_table_name, parse_identifier}};
|
||||||
use minisql::{operation::Operation, type_system::Value};
|
use minisql::{operation::Operation, type_system::Value};
|
||||||
use nom::{
|
use nom::{
|
||||||
bytes::complete::tag,
|
bytes::complete::tag,
|
||||||
|
|
@ -91,4 +91,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +110,7 @@ fn parse_uuid(input: &str) -> IResult<&str, Value> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minisql::type_system::{IndexableValue, Value};
|
use minisql::type_system::{IndexableValue, Value};
|
||||||
use crate::literal::{parse_db_value, parse_string};
|
use crate::parsing::literal::{parse_db_value, parse_string};
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -161,4 +161,4 @@ mod tests {
|
||||||
fn test_parse_int() {
|
fn test_parse_int() {
|
||||||
assert_eq!(parse_db_value("5134616"), Ok(("", Value::Indexable(IndexableValue::Int(5134616)))));
|
assert_eq!(parse_db_value("5134616"), Ok(("", Value::Indexable(IndexableValue::Int(5134616)))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
7
parser/src/parsing/mod.rs
Normal file
7
parser/src/parsing/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
pub(crate) mod literal;
|
||||||
|
pub(crate) mod select;
|
||||||
|
pub(crate) mod common;
|
||||||
|
pub(crate) mod create;
|
||||||
|
pub(crate) mod insert;
|
||||||
|
pub(crate) mod delete;
|
||||||
|
pub(crate) mod index;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::common::{parse_table_name, parse_column_name, parse_condition};
|
use super::common::{parse_table_name, parse_column_name, parse_condition};
|
||||||
use minisql::operation::{ColumnSelection, Operation};
|
use minisql::operation::{ColumnSelection, Operation};
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
|
|
@ -45,7 +45,7 @@ pub fn try_parse_column_selection(input: &str) -> IResult<&str, ColumnSelection>
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use minisql::operation::{ColumnSelection, Operation};
|
use minisql::operation::{ColumnSelection, Operation};
|
||||||
use crate::{common::{parse_column_name, parse_table_name}, select::parse_select};
|
use crate::parsing::{common::{parse_column_name, parse_table_name}, select::parse_select};
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -119,4 +119,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
// TODO: a test with multiple statements
|
// TODO: a test with multiple statements
|
||||||
// TODO: allow underscores in identifiers
|
// TODO: allow underscores in identifiers
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue