2022-06-09 08:18:08 +00:00
|
|
|
use crate::sql::comment::comment;
|
2023-02-20 20:40:05 +00:00
|
|
|
use crate::sql::comment::{mightbespace, shouldbespace};
|
2022-06-09 08:18:08 +00:00
|
|
|
use crate::sql::error::IResult;
|
2023-06-20 23:31:23 +00:00
|
|
|
use crate::sql::operator::{assigner, binary};
|
2022-06-09 08:18:08 +00:00
|
|
|
use nom::branch::alt;
|
2022-08-31 13:00:43 +00:00
|
|
|
use nom::bytes::complete::tag;
|
2023-02-20 14:24:37 +00:00
|
|
|
use nom::bytes::complete::tag_no_case;
|
2022-06-09 08:18:08 +00:00
|
|
|
use nom::character::complete::char;
|
|
|
|
use nom::character::complete::multispace1;
|
|
|
|
use nom::combinator::eof;
|
|
|
|
use nom::combinator::map;
|
|
|
|
use nom::combinator::peek;
|
2023-02-20 14:24:37 +00:00
|
|
|
use nom::sequence::preceded;
|
2022-06-09 08:18:08 +00:00
|
|
|
|
|
|
|
pub fn number(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
|
|
|
map(multispace1, |_| ()),
|
2023-06-20 23:31:23 +00:00
|
|
|
map(binary, |_| ()),
|
2022-06-09 08:18:08 +00:00
|
|
|
map(assigner, |_| ()),
|
|
|
|
map(comment, |_| ()),
|
|
|
|
map(char(')'), |_| ()),
|
|
|
|
map(char(']'), |_| ()),
|
|
|
|
map(char('}'), |_| ()),
|
2022-09-14 22:40:19 +00:00
|
|
|
map(char('"'), |_| ()),
|
2022-10-16 23:03:46 +00:00
|
|
|
map(char('\''), |_| ()),
|
2022-06-09 08:18:08 +00:00
|
|
|
map(char(';'), |_| ()),
|
|
|
|
map(char(','), |_| ()),
|
2022-08-31 13:00:43 +00:00
|
|
|
map(tag(".."), |_| ()),
|
2022-06-09 08:18:08 +00:00
|
|
|
map(eof, |_| ()),
|
|
|
|
)))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ident(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
|
|
|
map(multispace1, |_| ()),
|
2023-06-20 23:31:23 +00:00
|
|
|
map(binary, |_| ()),
|
2022-06-09 08:18:08 +00:00
|
|
|
map(assigner, |_| ()),
|
|
|
|
map(comment, |_| ()),
|
|
|
|
map(char(')'), |_| ()),
|
|
|
|
map(char(']'), |_| ()),
|
|
|
|
map(char('}'), |_| ()),
|
|
|
|
map(char(';'), |_| ()),
|
|
|
|
map(char(','), |_| ()),
|
|
|
|
map(char('.'), |_| ()),
|
|
|
|
map(char('['), |_| ()),
|
|
|
|
map(char('-'), |_| ()),
|
|
|
|
map(eof, |_| ()),
|
|
|
|
)))(i)
|
|
|
|
}
|
2022-09-29 06:26:34 +00:00
|
|
|
|
|
|
|
pub fn duration(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
|
|
|
map(multispace1, |_| ()),
|
2023-06-20 23:31:23 +00:00
|
|
|
map(binary, |_| ()),
|
2022-09-29 06:26:34 +00:00
|
|
|
map(assigner, |_| ()),
|
|
|
|
map(comment, |_| ()),
|
|
|
|
map(char(')'), |_| ()),
|
|
|
|
map(char(']'), |_| ()),
|
|
|
|
map(char('}'), |_| ()),
|
|
|
|
map(char(';'), |_| ()),
|
|
|
|
map(char(','), |_| ()),
|
|
|
|
map(char('.'), |_| ()),
|
|
|
|
map(char('-'), |_| ()),
|
|
|
|
map(eof, |_| ()),
|
|
|
|
)))(i)
|
|
|
|
}
|
2023-02-20 14:24:37 +00:00
|
|
|
|
2023-03-17 11:32:31 +00:00
|
|
|
pub fn field(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
|
|
|
map(preceded(shouldbespace, tag_no_case("FROM")), |_| ()),
|
|
|
|
map(preceded(comment, tag_no_case("FROM")), |_| ()),
|
|
|
|
map(char(';'), |_| ()),
|
|
|
|
map(eof, |_| ()),
|
|
|
|
)))(i)
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:24:37 +00:00
|
|
|
pub fn subquery(i: &str) -> IResult<&str, ()> {
|
2023-02-20 20:40:05 +00:00
|
|
|
alt((
|
|
|
|
|i| {
|
|
|
|
let (i, _) = mightbespace(i)?;
|
|
|
|
let (i, _) = char(';')(i)?;
|
|
|
|
let (i, _) = peek(alt((
|
|
|
|
preceded(shouldbespace, tag_no_case("THEN")),
|
|
|
|
preceded(shouldbespace, tag_no_case("ELSE")),
|
|
|
|
preceded(shouldbespace, tag_no_case("END")),
|
|
|
|
)))(i)?;
|
|
|
|
Ok((i, ()))
|
|
|
|
},
|
|
|
|
peek(alt((
|
|
|
|
map(preceded(shouldbespace, tag_no_case("THEN")), |_| ()),
|
|
|
|
map(preceded(shouldbespace, tag_no_case("ELSE")), |_| ()),
|
|
|
|
map(preceded(shouldbespace, tag_no_case("END")), |_| ()),
|
|
|
|
map(comment, |_| ()),
|
|
|
|
map(char(']'), |_| ()),
|
|
|
|
map(char('}'), |_| ()),
|
|
|
|
map(char(';'), |_| ()),
|
|
|
|
map(char(','), |_| ()),
|
|
|
|
map(eof, |_| ()),
|
|
|
|
))),
|
|
|
|
))(i)
|
2023-02-20 14:24:37 +00:00
|
|
|
}
|