Put parsing details into one module
This commit is contained in:
parent
61c0a34253
commit
6000b1f242
10 changed files with 30 additions and 29 deletions
38
parser/src/parsing/delete.rs
Normal file
38
parser/src/parsing/delete.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use minisql::operation::Operation;
|
||||
use nom::{
|
||||
bytes::complete::tag,
|
||||
character::complete::{char, multispace0, multispace1},
|
||||
IResult,
|
||||
};
|
||||
|
||||
use super::common::{parse_table_name, parse_condition};
|
||||
|
||||
pub fn parse_delete(input: &str) -> IResult<&str, Operation> {
|
||||
let (input, _) = tag("DELETE")(input)?;
|
||||
let (input, _) = multispace1(input)?;
|
||||
let (input, _) = tag("FROM")(input)?;
|
||||
let (input, _) = multispace1(input)?;
|
||||
let (input, table_name) = parse_table_name(input)?;
|
||||
let (input, _) = multispace0(input)?;
|
||||
let (input, condition) = parse_condition(input)?;
|
||||
let (input, _) = multispace0(input)?;
|
||||
let (input, _) = char(';')(input)?;
|
||||
Ok((
|
||||
input,
|
||||
Operation::Delete(table_name.to_string(), condition),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use minisql::operation::Operation;
|
||||
use crate::parsing::delete::parse_delete;
|
||||
|
||||
#[test]
|
||||
fn test_parse_delete() {
|
||||
let (_, operation) = parse_delete("DELETE FROM \"T1\" WHERE id = 1 ;").expect("should parse");
|
||||
assert!(matches!(operation, Operation::Delete(_, _)))
|
||||
}
|
||||
|
||||
// TODO: add test with condition
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue