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::peek;
|
2023-08-29 10:50:00 +00:00
|
|
|
use nom::combinator::{eof, value};
|
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((
|
2023-08-29 10:50:00 +00:00
|
|
|
value((), multispace1), // 1 + 1
|
|
|
|
value((), binary), // 1+1
|
|
|
|
value((), assigner), // 1=1
|
|
|
|
value((), comment), // 1/*comment*/
|
|
|
|
value((), char(')')), // (1)
|
|
|
|
value((), char(']')), // a[1]
|
|
|
|
value((), char('}')), // {k: 1}
|
|
|
|
value((), char('"')),
|
|
|
|
value((), char('\'')),
|
|
|
|
value((), char(';')), // SET a = 1;
|
|
|
|
value((), char(',')), // [1, 2]
|
|
|
|
value((), tag("..")), // thing:1..2
|
|
|
|
value((), eof), // SET a = 1
|
2022-06-09 08:18:08 +00:00
|
|
|
)))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ident(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
2023-08-29 10:50:00 +00:00
|
|
|
value((), multispace1), // a + 1
|
|
|
|
value((), binary), // a+1
|
|
|
|
value((), assigner), // a+=1
|
|
|
|
value((), comment), // a/*comment*/
|
|
|
|
value((), char(')')), // (a)
|
|
|
|
value((), char(']')), // foo[a]
|
|
|
|
value((), char('}')), // {k: a}
|
|
|
|
value((), char(';')), // SET k = a;
|
|
|
|
value((), char(',')), // [a, b]
|
|
|
|
value((), char('.')), // a.k
|
|
|
|
value((), char('…')), // a…
|
|
|
|
value((), char('[')), // a[0]
|
|
|
|
value((), eof), // SET k = a
|
2023-07-27 08:14:55 +00:00
|
|
|
)))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// none, false, etc.
|
|
|
|
pub fn keyword(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
2023-08-29 10:50:00 +00:00
|
|
|
value((), multispace1), // false || true
|
|
|
|
value((), binary), // false||true
|
|
|
|
value((), comment), // false/*comment*/
|
|
|
|
value((), char(')')), // (false)
|
|
|
|
value((), char(']')), // [WHERE k = false]
|
|
|
|
value((), char('}')), // {k: false}
|
|
|
|
value((), char(';')), // SET a = false;
|
|
|
|
value((), char(',')), // [false, true]
|
|
|
|
value((), eof), // SET a = false
|
2022-06-09 08:18:08 +00:00
|
|
|
)))(i)
|
|
|
|
}
|
2022-09-29 06:26:34 +00:00
|
|
|
|
|
|
|
pub fn duration(i: &str) -> IResult<&str, ()> {
|
|
|
|
peek(alt((
|
2023-08-29 10:50:00 +00:00
|
|
|
value((), multispace1),
|
|
|
|
value((), binary),
|
|
|
|
value((), assigner),
|
|
|
|
value((), comment),
|
|
|
|
value((), char(')')),
|
|
|
|
value((), char(']')),
|
|
|
|
value((), char('}')),
|
|
|
|
value((), char(';')),
|
|
|
|
value((), char(',')),
|
|
|
|
value((), char('.')),
|
|
|
|
value((), eof),
|
2022-09-29 06:26:34 +00:00
|
|
|
)))(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((
|
2023-08-29 10:50:00 +00:00
|
|
|
value((), preceded(shouldbespace, tag_no_case("FROM"))),
|
|
|
|
value((), char(';')),
|
|
|
|
value((), eof),
|
2023-03-17 11:32:31 +00:00
|
|
|
)))(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((
|
2023-08-29 10:50:00 +00:00
|
|
|
value((), preceded(shouldbespace, tag_no_case("THEN"))),
|
|
|
|
value((), preceded(shouldbespace, tag_no_case("ELSE"))),
|
|
|
|
value((), preceded(shouldbespace, tag_no_case("END"))),
|
|
|
|
value((), comment),
|
|
|
|
value((), char(']')),
|
|
|
|
value((), char('}')),
|
|
|
|
value((), char(';')),
|
|
|
|
value((), char(',')),
|
|
|
|
value((), eof),
|
2023-02-20 20:40:05 +00:00
|
|
|
))),
|
|
|
|
))(i)
|
2023-02-20 14:24:37 +00:00
|
|
|
}
|