Put parsing details into one module

This commit is contained in:
Yuriy Dupyn 2024-01-26 19:45:15 +01:00
parent 61c0a34253
commit 6000b1f242
10 changed files with 30 additions and 29 deletions

View file

@ -1,38 +0,0 @@
use minisql::operation::Operation;
use nom::{
bytes::complete::tag,
character::complete::{char, multispace0, multispace1},
IResult,
};
use crate::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::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
}