formatting
This commit is contained in:
parent
ad98cfafb2
commit
c25c6edc6a
29 changed files with 886 additions and 571 deletions
|
|
@ -1,6 +1,12 @@
|
|||
use crate::syntax::RawQuerySyntax;
|
||||
use minisql::{interpreter2::DbSchema, operation::Operation};
|
||||
use nom::{branch::alt, character::complete::{multispace0, char}, multi::many1, sequence::{delimited, terminated}, IResult};
|
||||
use nom::{
|
||||
branch::alt,
|
||||
character::complete::{char, multispace0},
|
||||
multi::many1,
|
||||
sequence::{delimited, terminated},
|
||||
IResult,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -35,7 +41,10 @@ fn parse_statement(input: &str) -> IResult<&str, RawQuerySyntax> {
|
|||
/// Parse one or more statements
|
||||
#[allow(dead_code)]
|
||||
fn parse_statement1(input: &str) -> IResult<&str, Vec<RawQuerySyntax>> {
|
||||
many1(terminated(parse_statement, delimited(multispace0, char(';'), multispace0)))(input)
|
||||
many1(terminated(
|
||||
parse_statement,
|
||||
delimited(multispace0, char(';'), multispace0),
|
||||
))(input)
|
||||
}
|
||||
|
||||
pub fn parse_and_validate(str_query: String, db_schema: &DbSchema) -> Result<Operation, Error> {
|
||||
|
|
@ -53,11 +62,9 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_parse_two_select() {
|
||||
let (rest, sntx) = parse_statement1("SELECT * FROM users ; SELECT * FROM cities ; ").expect("should parse");
|
||||
assert_eq!(
|
||||
sntx.len(),
|
||||
2
|
||||
);
|
||||
let (rest, sntx) = parse_statement1("SELECT * FROM users ; SELECT * FROM cities ; ")
|
||||
.expect("should parse");
|
||||
assert_eq!(sntx.len(), 2);
|
||||
assert_eq!(rest, "");
|
||||
}
|
||||
|
||||
|
|
@ -68,11 +75,10 @@ mod test {
|
|||
SELECT * FROM users ;
|
||||
INSERT INTO table1 (id, data) VALUES (u4, 30) ;
|
||||
INSERT INTO table1 (id, data) VALUES (u5, 40) ;
|
||||
"#).expect("should parse");
|
||||
assert_eq!(
|
||||
sntx.len(),
|
||||
4
|
||||
);
|
||||
"#,
|
||||
)
|
||||
.expect("should parse");
|
||||
assert_eq!(sntx.len(), 4);
|
||||
assert_eq!(rest, "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue