cargo format
This commit is contained in:
parent
4d45da0cd1
commit
845db102c2
33 changed files with 885 additions and 530 deletions
|
|
@ -1,20 +1,21 @@
|
|||
use minisql::type_system::DbType;
|
||||
use nom::{
|
||||
character::complete::{alphanumeric1, char, multispace0, anychar, multispace1},
|
||||
branch::alt,
|
||||
bytes::complete::tag,
|
||||
character::complete::{alphanumeric1, anychar, char, multispace0, multispace1},
|
||||
combinator::peek,
|
||||
error::make_error,
|
||||
sequence::{delimited, terminated},
|
||||
bytes::complete::tag,
|
||||
IResult, branch::alt,
|
||||
IResult,
|
||||
};
|
||||
use minisql::type_system::DbType;
|
||||
|
||||
use crate::syntax::Condition;
|
||||
use super::literal::parse_db_value;
|
||||
use crate::syntax::Condition;
|
||||
|
||||
pub fn parse_table_name(input: &str) -> IResult<&str, &str> {
|
||||
alt((
|
||||
delimited(char('"'), alphanumeric1, char('"')),
|
||||
parse_identifier
|
||||
parse_identifier,
|
||||
))(input)
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +25,10 @@ pub fn parse_identifier(input: &str) -> IResult<&str, &str> {
|
|||
if first.is_alphabetic() {
|
||||
alphanumeric1(input)
|
||||
} else {
|
||||
Err(nom::Err::Error(make_error(input, nom::error::ErrorKind::Alpha)))
|
||||
Err(nom::Err::Error(make_error(
|
||||
input,
|
||||
nom::error::ErrorKind::Alpha,
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +43,12 @@ pub fn parse_db_type(input: &str) -> IResult<&str, DbType> {
|
|||
"INT" => DbType::Int,
|
||||
"UUID" => DbType::Uuid,
|
||||
"NUMBER" => DbType::Number,
|
||||
_ => return Err(nom::Err::Failure(make_error(input, nom::error::ErrorKind::IsNot)))
|
||||
_ => {
|
||||
return Err(nom::Err::Failure(make_error(
|
||||
input,
|
||||
nom::error::ErrorKind::IsNot,
|
||||
)))
|
||||
}
|
||||
};
|
||||
Ok((input, db_type))
|
||||
}
|
||||
|
|
@ -51,9 +60,7 @@ pub fn parse_condition(input: &str) -> IResult<&str, Option<Condition>> {
|
|||
let (input, condition) = parse_equality(input)?;
|
||||
Ok((input, Some(condition)))
|
||||
}
|
||||
Err(_) => {
|
||||
Ok((input, None))
|
||||
}
|
||||
Err(_) => Ok((input, None)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,9 +77,9 @@ fn parse_equality(input: &str) -> IResult<&str, Condition> {
|
|||
mod tests {
|
||||
use minisql::type_system::DbType;
|
||||
|
||||
use crate::syntax::Condition;
|
||||
use crate::parsing::common::{parse_db_type, parse_equality};
|
||||
|
||||
use crate::syntax::Condition;
|
||||
|
||||
#[test]
|
||||
fn test_parse_equality() {
|
||||
use minisql::type_system::{IndexableValue, Value};
|
||||
|
|
@ -89,10 +96,22 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_parse_db_type() {
|
||||
assert!(matches!(parse_db_type("INT").expect("should parse").1, DbType::Int));
|
||||
assert!(matches!(parse_db_type("STRING").expect("should parse").1, DbType::String));
|
||||
assert!(matches!(parse_db_type("UUID").expect("should parse").1, DbType::Uuid));
|
||||
assert!(matches!(parse_db_type("NUMBER").expect("should parse").1, DbType::Number));
|
||||
assert!(matches!(
|
||||
parse_db_type("INT").expect("should parse").1,
|
||||
DbType::Int
|
||||
));
|
||||
assert!(matches!(
|
||||
parse_db_type("STRING").expect("should parse").1,
|
||||
DbType::String
|
||||
));
|
||||
assert!(matches!(
|
||||
parse_db_type("UUID").expect("should parse").1,
|
||||
DbType::Uuid
|
||||
));
|
||||
assert!(matches!(
|
||||
parse_db_type("NUMBER").expect("should parse").1,
|
||||
DbType::Number
|
||||
));
|
||||
assert!(matches!(parse_db_type("Unknown"), Err(_)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue