Resolve TODOs in parsing
Return error for queries containing non-ASCII characters Allow underscores in identifiers Add a delete statement test with spaces Remove trailing spaces and semicolons from tests and parsers Complete the multiple statement parser TODO
This commit is contained in:
parent
5d040f15f5
commit
de8c6164cf
7 changed files with 89 additions and 38 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use minisql::type_system::DbType;
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::tag,
|
||||
character::complete::{alphanumeric1, anychar, char, multispace0, multispace1},
|
||||
bytes::complete::{tag, take_while},
|
||||
character::{complete::{alphanumeric1, anychar, char, multispace0, multispace1}, is_alphanumeric},
|
||||
combinator::peek,
|
||||
error::make_error,
|
||||
sequence::{delimited, terminated},
|
||||
|
|
@ -20,10 +20,11 @@ pub fn parse_table_name(input: &str) -> IResult<&str, &str> {
|
|||
}
|
||||
|
||||
pub fn parse_identifier(input: &str) -> IResult<&str, &str> {
|
||||
// TODO: allow underscores
|
||||
let (_, first) = peek(anychar)(input)?;
|
||||
if first.is_alphabetic() {
|
||||
alphanumeric1(input)
|
||||
if first.is_alphabetic() || first == '_' {
|
||||
take_while(|c: char| {
|
||||
is_alphanumeric(c as u8) || c == '_'
|
||||
})(input)
|
||||
} else {
|
||||
Err(nom::Err::Error(make_error(
|
||||
input,
|
||||
|
|
@ -77,7 +78,7 @@ fn parse_equality(input: &str) -> IResult<&str, Condition> {
|
|||
mod tests {
|
||||
use minisql::type_system::DbType;
|
||||
|
||||
use crate::parsing::common::{parse_db_type, parse_equality};
|
||||
use crate::parsing::common::{parse_db_type, parse_equality, parse_identifier};
|
||||
use crate::syntax::Condition;
|
||||
|
||||
#[test]
|
||||
|
|
@ -114,4 +115,16 @@ mod tests {
|
|||
));
|
||||
assert!(matches!(parse_db_type("Unknown"), Err(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_identifier() {
|
||||
assert_eq!(
|
||||
parse_identifier("_variable__Test").expect("should parse").1,
|
||||
"_variable__Test"
|
||||
);
|
||||
assert!(matches!(
|
||||
parse_identifier("123_variable__Test"),
|
||||
Err(_)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue