Use char instead of str for parsing where possible
This commit is contained in:
parent
97c0e50654
commit
5d554d07d3
20 changed files with 218 additions and 198 deletions
|
@ -9,7 +9,7 @@ use crate::sql::number::Number;
|
|||
use crate::sql::operation::Operation;
|
||||
use crate::sql::strand::Strand;
|
||||
use crate::sql::value::{value, Value};
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::opt;
|
||||
use nom::multi::separated_list0;
|
||||
use serde::ser::SerializeStruct;
|
||||
|
@ -357,13 +357,13 @@ impl<T: PartialEq> Difference<T> for Vec<T> {
|
|||
// ------------------------------
|
||||
|
||||
pub fn array(i: &str) -> IResult<&str, Array> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list0(commas, item)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = opt(tag(","))(i)?;
|
||||
let (i, _) = opt(char(','))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((
|
||||
i,
|
||||
Array {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::sql::error::IResult;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::take_until;
|
||||
use nom::character::complete::char;
|
||||
use nom::character::complete::multispace0;
|
||||
use nom::character::complete::multispace1;
|
||||
use nom::character::complete::not_line_ending;
|
||||
|
@ -36,30 +36,34 @@ fn space(i: &str) -> IResult<&str, ()> {
|
|||
|
||||
fn block(i: &str) -> IResult<&str, ()> {
|
||||
let (i, _) = multispace0(i)?;
|
||||
let (i, _) = tag("/*")(i)?;
|
||||
let (i, _) = char('/')(i)?;
|
||||
let (i, _) = char('*')(i)?;
|
||||
let (i, _) = take_until("*/")(i)?;
|
||||
let (i, _) = tag("*/")(i)?;
|
||||
let (i, _) = char('*')(i)?;
|
||||
let (i, _) = char('/')(i)?;
|
||||
let (i, _) = multispace0(i)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
||||
fn slash(i: &str) -> IResult<&str, ()> {
|
||||
let (i, _) = multispace0(i)?;
|
||||
let (i, _) = tag("//")(i)?;
|
||||
let (i, _) = char('/')(i)?;
|
||||
let (i, _) = char('/')(i)?;
|
||||
let (i, _) = not_line_ending(i)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
||||
fn dash(i: &str) -> IResult<&str, ()> {
|
||||
let (i, _) = multispace0(i)?;
|
||||
let (i, _) = tag("--")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = not_line_ending(i)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
||||
fn hash(i: &str) -> IResult<&str, ()> {
|
||||
let (i, _) = multispace0(i)?;
|
||||
let (i, _) = tag("#")(i)?;
|
||||
let (i, _) = char('#')(i)?;
|
||||
let (i, _) = not_line_ending(i)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::sql::comment::mightbespace;
|
||||
use crate::sql::error::Error::ParserError;
|
||||
use crate::sql::error::IResult;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::take_while;
|
||||
use nom::bytes::complete::take_while_m_n;
|
||||
use nom::character::complete::char;
|
||||
use nom::character::is_alphanumeric;
|
||||
use nom::multi::many1;
|
||||
use nom::Err::Error;
|
||||
|
@ -11,14 +11,14 @@ use std::ops::RangeBounds;
|
|||
|
||||
pub fn colons(i: &str) -> IResult<&str, ()> {
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = many1(tag(";"))(i)?;
|
||||
let (i, _) = many1(char(';'))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
||||
pub fn commas(i: &str) -> IResult<&str, ()> {
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(",")(i)?;
|
||||
let (i, _) = char(',')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
Ok((i, ()))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::sql::common::{take_digits, take_digits_range, take_u32};
|
|||
use crate::sql::error::IResult;
|
||||
use chrono::{DateTime, FixedOffset, TimeZone, Utc};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::map;
|
||||
use nom::sequence::delimited;
|
||||
use serde::ser::SerializeStruct;
|
||||
|
@ -71,8 +71,8 @@ impl Serialize for Datetime {
|
|||
|
||||
pub fn datetime(i: &str) -> IResult<&str, Datetime> {
|
||||
alt((
|
||||
delimited(tag("\""), datetime_raw, tag("\"")),
|
||||
delimited(tag("\'"), datetime_raw, tag("\'")),
|
||||
delimited(char('\"'), datetime_raw, char('\"')),
|
||||
delimited(char('\''), datetime_raw, char('\'')),
|
||||
))(i)
|
||||
}
|
||||
|
||||
|
@ -82,9 +82,9 @@ pub fn datetime_raw(i: &str) -> IResult<&str, Datetime> {
|
|||
|
||||
fn date(i: &str) -> IResult<&str, Datetime> {
|
||||
let (i, year) = year(i)?;
|
||||
let (i, _) = tag("-")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, mon) = month(i)?;
|
||||
let (i, _) = tag("-")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, day) = day(i)?;
|
||||
|
||||
let d = Utc.ymd(year, mon, day).and_hms(0, 0, 0);
|
||||
|
@ -98,15 +98,15 @@ fn date(i: &str) -> IResult<&str, Datetime> {
|
|||
|
||||
fn time(i: &str) -> IResult<&str, Datetime> {
|
||||
let (i, year) = year(i)?;
|
||||
let (i, _) = tag("-")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, mon) = month(i)?;
|
||||
let (i, _) = tag("-")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, day) = day(i)?;
|
||||
let (i, _) = tag("T")(i)?;
|
||||
let (i, _) = char('T')(i)?;
|
||||
let (i, hour) = hour(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, min) = minute(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, sec) = second(i)?;
|
||||
let (i, zone) = zone(i)?;
|
||||
|
||||
|
@ -131,15 +131,15 @@ fn time(i: &str) -> IResult<&str, Datetime> {
|
|||
|
||||
fn nano(i: &str) -> IResult<&str, Datetime> {
|
||||
let (i, year) = year(i)?;
|
||||
let (i, _) = tag("-")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, mon) = month(i)?;
|
||||
let (i, _) = tag("-")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, day) = day(i)?;
|
||||
let (i, _) = tag("T")(i)?;
|
||||
let (i, _) = char('T')(i)?;
|
||||
let (i, hour) = hour(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, min) = minute(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, sec) = second(i)?;
|
||||
let (i, nano) = nanosecond(i)?;
|
||||
let (i, zone) = zone(i)?;
|
||||
|
@ -191,7 +191,7 @@ fn second(i: &str) -> IResult<&str, u32> {
|
|||
}
|
||||
|
||||
fn nanosecond(i: &str) -> IResult<&str, u32> {
|
||||
let (i, _) = tag(".")(i)?;
|
||||
let (i, _) = char('.')(i)?;
|
||||
let (i, v) = take_u32(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
@ -201,14 +201,14 @@ fn zone(i: &str) -> IResult<&str, Option<FixedOffset>> {
|
|||
}
|
||||
|
||||
fn zone_utc(i: &str) -> IResult<&str, Option<FixedOffset>> {
|
||||
let (i, _) = tag("Z")(i)?;
|
||||
let (i, _) = char('Z')(i)?;
|
||||
Ok((i, None))
|
||||
}
|
||||
|
||||
fn zone_all(i: &str) -> IResult<&str, Option<FixedOffset>> {
|
||||
let (i, s) = sign(i)?;
|
||||
let (i, h) = hour(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, m) = minute(i)?;
|
||||
if h == 0 && m == 0 {
|
||||
Ok((i, None))
|
||||
|
@ -222,8 +222,8 @@ fn zone_all(i: &str) -> IResult<&str, Option<FixedOffset>> {
|
|||
}
|
||||
|
||||
fn sign(i: &str) -> IResult<&str, i32> {
|
||||
map(alt((tag("-"), tag("+"))), |s: &str| match s {
|
||||
"-" => -1,
|
||||
map(alt((char('-'), char('+'))), |s: char| match s {
|
||||
'-' => -1,
|
||||
_ => 1,
|
||||
})(i)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::sql::script::{script, Script};
|
|||
use crate::sql::value::{single, value, Value};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::multi::separated_list0;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
|
@ -88,33 +89,35 @@ pub fn function(i: &str) -> IResult<&str, Function> {
|
|||
fn future(i: &str) -> IResult<&str, Function> {
|
||||
let (i, _) = tag("fn::future")(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("->")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = value(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, Function::Future(v)))
|
||||
}
|
||||
|
||||
fn embed(i: &str) -> IResult<&str, Function> {
|
||||
let (i, _) = tag("fn::script")(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("->")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = script(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, Function::Script(v)))
|
||||
}
|
||||
|
||||
fn casts(i: &str) -> IResult<&str, Function> {
|
||||
let (i, _) = tag("<")(i)?;
|
||||
let (i, _) = char('<')(i)?;
|
||||
let (i, s) = function_casts(i)?;
|
||||
let (i, _) = tag(">")(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = single(i)?;
|
||||
Ok((i, Function::Cast(s.to_string(), v)))
|
||||
|
@ -122,11 +125,11 @@ fn casts(i: &str) -> IResult<&str, Function> {
|
|||
|
||||
fn normal(i: &str) -> IResult<&str, Function> {
|
||||
let (i, s) = function_names(i)?;
|
||||
let (i, _) = tag("(")(i)?;
|
||||
let (i, _) = char('(')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list0(commas, value)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(")")(i)?;
|
||||
let (i, _) = char(')')(i)?;
|
||||
Ok((i, Function::Normal(s.to_string(), v)))
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use geo::{LineString, Point, Polygon};
|
|||
use geo::{MultiLineString, MultiPoint, MultiPolygon};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::multi::separated_list0;
|
||||
use nom::multi::separated_list1;
|
||||
use nom::number::complete::double;
|
||||
|
@ -18,8 +19,8 @@ use std::cmp::Ordering;
|
|||
use std::fmt;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
const SINGLE: &str = r#"'"#;
|
||||
const DOUBLE: &str = r#"""#;
|
||||
const SINGLE: char = '\'';
|
||||
const DOUBLE: char = '\"';
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||
pub enum Geometry {
|
||||
|
@ -472,169 +473,169 @@ pub fn geometry(i: &str) -> IResult<&str, Geometry> {
|
|||
}
|
||||
|
||||
fn simple(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("(")(i)?;
|
||||
let (i, _) = char('(')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, x) = double(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(",")(i)?;
|
||||
let (i, _) = char(',')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, y) = double(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(")")(i)?;
|
||||
let (i, _) = char(')')(i)?;
|
||||
Ok((i, Geometry::Point((x, y).into())))
|
||||
}
|
||||
|
||||
fn point(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, point_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_vals, point_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_vals, point_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, point_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn line(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, line_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_vals, line_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_vals, line_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, line_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn polygon(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, polygon_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_vals, polygon_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_vals, polygon_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, polygon_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn multipoint(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, multipoint_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_vals, multipoint_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_vals, multipoint_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, multipoint_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn multiline(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, multiline_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_vals, multiline_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_vals, multiline_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, multiline_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn multipolygon(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, multipolygon_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_vals, multipolygon_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_vals, multipolygon_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, multipolygon_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn collection(i: &str) -> IResult<&str, Geometry> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = alt((
|
||||
|i| {
|
||||
let (i, _) = preceded(key_type, collection_type)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, v) = preceded(key_geom, collection_vals)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
|i| {
|
||||
let (i, v) = preceded(key_geom, collection_vals)(i)?;
|
||||
let (i, _) = delimited(mightbespace, tag(","), mightbespace)(i)?;
|
||||
let (i, _) = delimited(mightbespace, char(','), mightbespace)(i)?;
|
||||
let (i, _) = preceded(key_type, collection_type)(i)?;
|
||||
Ok((i, v))
|
||||
},
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
|
@ -648,64 +649,64 @@ fn point_vals(i: &str) -> IResult<&str, Point<f64>> {
|
|||
}
|
||||
|
||||
fn line_vals(i: &str) -> IResult<&str, LineString<f64>> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list1(commas, coordinate)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, v.into()))
|
||||
}
|
||||
|
||||
fn polygon_vals(i: &str) -> IResult<&str, Polygon<f64>> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, e) = line_vals(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
let (i, v) = separated_list0(commas, |i| {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = line_vals(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, v))
|
||||
})(i)?;
|
||||
Ok((i, Polygon::new(e, v)))
|
||||
}
|
||||
|
||||
fn multipoint_vals(i: &str) -> IResult<&str, Vec<Point<f64>>> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list1(commas, point_vals)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn multiline_vals(i: &str) -> IResult<&str, Vec<LineString<f64>>> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list1(commas, line_vals)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn multipolygon_vals(i: &str) -> IResult<&str, Vec<Polygon<f64>>> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list1(commas, polygon_vals)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn collection_vals(i: &str) -> IResult<&str, Vec<Geometry>> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list1(commas, geometry)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
|
@ -714,15 +715,15 @@ fn collection_vals(i: &str) -> IResult<&str, Vec<Geometry>> {
|
|||
//
|
||||
|
||||
fn coordinate(i: &str) -> IResult<&str, (f64, f64)> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, x) = double(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(",")(i)?;
|
||||
let (i, _) = char(',')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, y) = double(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, (x, y)))
|
||||
}
|
||||
|
||||
|
@ -732,56 +733,56 @@ fn coordinate(i: &str) -> IResult<&str, (f64, f64)> {
|
|||
|
||||
fn point_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("Point"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("Point"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("Point"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("Point"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn line_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("LineString"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("LineString"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("LineString"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("LineString"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn polygon_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("Polygon"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("Polygon"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("Polygon"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("Polygon"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn multipoint_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("MultiPoint"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("MultiPoint"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("MultiPoint"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("MultiPoint"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn multiline_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("MultiLineString"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("MultiLineString"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("MultiLineString"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("MultiLineString"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn multipolygon_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("MultiPolygon"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("MultiPolygon"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("MultiPolygon"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("MultiPolygon"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn collection_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
delimited(tag(SINGLE), tag("GeometryCollection"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("GeometryCollection"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("GeometryCollection"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("GeometryCollection"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
@ -793,11 +794,11 @@ fn collection_type(i: &str) -> IResult<&str, &str> {
|
|||
fn key_type(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
tag("type"),
|
||||
delimited(tag(SINGLE), tag("type"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("type"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("type"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("type"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
@ -805,11 +806,11 @@ fn key_type(i: &str) -> IResult<&str, &str> {
|
|||
fn key_vals(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
tag("coordinates"),
|
||||
delimited(tag(SINGLE), tag("coordinates"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("coordinates"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("coordinates"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("coordinates"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
@ -817,11 +818,11 @@ fn key_vals(i: &str) -> IResult<&str, &str> {
|
|||
fn key_geom(i: &str) -> IResult<&str, &str> {
|
||||
let (i, v) = alt((
|
||||
tag("geometries"),
|
||||
delimited(tag(SINGLE), tag("geometries"), tag(SINGLE)),
|
||||
delimited(tag(DOUBLE), tag("geometries"), tag(DOUBLE)),
|
||||
delimited(char(SINGLE), tag("geometries"), char(SINGLE)),
|
||||
delimited(char(DOUBLE), tag("geometries"), char(DOUBLE)),
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::sql::idiom::{idiom, Idiom};
|
|||
use crate::sql::table::{tables, Tables};
|
||||
use crate::sql::value::{value, Value};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::opt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
@ -64,7 +64,8 @@ pub fn graph(i: &str) -> IResult<&str, Graph> {
|
|||
}
|
||||
|
||||
fn graph_in(i: &str) -> IResult<&str, Graph> {
|
||||
let (i, _) = tag("<-")(i)?;
|
||||
let (i, _) = char('<')(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, (what, cond, alias)) = alt((simple, custom))(i)?;
|
||||
Ok((
|
||||
i,
|
||||
|
@ -78,7 +79,8 @@ fn graph_in(i: &str) -> IResult<&str, Graph> {
|
|||
}
|
||||
|
||||
fn graph_out(i: &str) -> IResult<&str, Graph> {
|
||||
let (i, _) = tag("->")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, (what, cond, alias)) = alt((simple, custom))(i)?;
|
||||
Ok((
|
||||
i,
|
||||
|
@ -92,7 +94,9 @@ fn graph_out(i: &str) -> IResult<&str, Graph> {
|
|||
}
|
||||
|
||||
fn graph_both(i: &str) -> IResult<&str, Graph> {
|
||||
let (i, _) = tag("<->")(i)?;
|
||||
let (i, _) = char('<')(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, (what, cond, alias)) = alt((simple, custom))(i)?;
|
||||
Ok((
|
||||
i,
|
||||
|
@ -111,13 +115,13 @@ fn simple(i: &str) -> IResult<&str, (Tables, Option<Value>, Option<Idiom>)> {
|
|||
}
|
||||
|
||||
fn custom(i: &str) -> IResult<&str, (Tables, Option<Value>, Option<Idiom>)> {
|
||||
let (i, _) = tag("(")(i)?;
|
||||
let (i, _) = char('(')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, w) = what(i)?;
|
||||
let (i, c) = opt(cond)(i)?;
|
||||
let (i, a) = opt(alias)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(")")(i)?;
|
||||
let (i, _) = char(')')(i)?;
|
||||
Ok((i, (w, c, a)))
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ use crate::sql::common::val_char;
|
|||
use crate::sql::error::IResult;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::take_while1;
|
||||
use nom::character::complete::char;
|
||||
use nom::sequence::delimited;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
@ -53,12 +53,12 @@ fn ident_default(i: &str) -> IResult<&str, String> {
|
|||
}
|
||||
|
||||
fn ident_backtick(i: &str) -> IResult<&str, String> {
|
||||
let (i, v) = delimited(tag("`"), is_not("`"), tag("`"))(i)?;
|
||||
let (i, v) = delimited(char('`'), is_not("`"), char('`'))(i)?;
|
||||
Ok((i, String::from(v)))
|
||||
}
|
||||
|
||||
fn ident_brackets(i: &str) -> IResult<&str, String> {
|
||||
let (i, v) = delimited(tag("⟨"), is_not("⟩"), tag("⟩"))(i)?;
|
||||
let (i, v) = delimited(char('⟨'), is_not("⟩"), char('⟩'))(i)?;
|
||||
Ok((i, String::from(v)))
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::table::{table, Table};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::map;
|
||||
use nom::multi::many1;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -62,7 +63,7 @@ pub fn kind(i: &str) -> IResult<&str, Kind> {
|
|||
|
||||
fn geometry(i: &str) -> IResult<&str, String> {
|
||||
let (i, _) = tag("geometry")(i)?;
|
||||
let (i, _) = tag("(")(i)?;
|
||||
let (i, _) = char('(')(i)?;
|
||||
let (i, v) = alt((
|
||||
tag("feature"),
|
||||
tag("point"),
|
||||
|
@ -73,14 +74,14 @@ fn geometry(i: &str) -> IResult<&str, String> {
|
|||
tag("multipolygon"),
|
||||
tag("collection"),
|
||||
))(i)?;
|
||||
let (i, _) = tag(")")(i)?;
|
||||
let (i, _) = char(')')(i)?;
|
||||
Ok((i, String::from(v)))
|
||||
}
|
||||
|
||||
fn record(i: &str) -> IResult<&str, Vec<Table>> {
|
||||
let (i, _) = tag("record")(i)?;
|
||||
let (i, _) = tag("(")(i)?;
|
||||
let (i, _) = char('(')(i)?;
|
||||
let (i, v) = many1(table)(i)?;
|
||||
let (i, _) = tag(")")(i)?;
|
||||
let (i, _) = char(')')(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::sql::common::val_char;
|
|||
use crate::sql::error::IResult;
|
||||
use crate::sql::ident::ident_raw;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
|
@ -34,11 +34,11 @@ pub fn model(i: &str) -> IResult<&str, Model> {
|
|||
}
|
||||
|
||||
fn model_count(i: &str) -> IResult<&str, Model> {
|
||||
let (i, _) = tag("|")(i)?;
|
||||
let (i, _) = char('|')(i)?;
|
||||
let (i, t) = ident_raw(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, c) = take_u64(i)?;
|
||||
let (i, _) = tag("|")(i)?;
|
||||
let (i, _) = char('|')(i)?;
|
||||
Ok((
|
||||
i,
|
||||
Model {
|
||||
|
@ -50,13 +50,14 @@ fn model_count(i: &str) -> IResult<&str, Model> {
|
|||
}
|
||||
|
||||
fn model_range(i: &str) -> IResult<&str, Model> {
|
||||
let (i, _) = tag("|")(i)?;
|
||||
let (i, _) = char('|')(i)?;
|
||||
let (i, t) = ident_raw(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, b) = take_u64(i)?;
|
||||
let (i, _) = tag("..")(i)?;
|
||||
let (i, _) = char('.')(i)?;
|
||||
let (i, _) = char('.')(i)?;
|
||||
let (i, e) = take_u64(i)?;
|
||||
let (i, _) = tag("|")(i)?;
|
||||
let (i, _) = char('|')(i)?;
|
||||
Ok((
|
||||
i,
|
||||
Model {
|
||||
|
|
|
@ -9,8 +9,8 @@ use crate::sql::operation::{Op, Operation};
|
|||
use crate::sql::value::{value, Value};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::take_while1;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::opt;
|
||||
use nom::multi::separated_list0;
|
||||
use nom::sequence::delimited;
|
||||
|
@ -145,13 +145,13 @@ impl Serialize for Object {
|
|||
}
|
||||
|
||||
pub fn object(i: &str) -> IResult<&str, Object> {
|
||||
let (i, _) = tag("{")(i)?;
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = separated_list0(commas, item)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = opt(tag(","))(i)?;
|
||||
let (i, _) = opt(char(','))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("}")(i)?;
|
||||
let (i, _) = char('}')(i)?;
|
||||
Ok((
|
||||
i,
|
||||
Object {
|
||||
|
@ -163,7 +163,7 @@ pub fn object(i: &str) -> IResult<&str, Object> {
|
|||
fn item(i: &str) -> IResult<&str, (String, Value)> {
|
||||
let (i, k) = key(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, v) = value(i)?;
|
||||
Ok((i, (String::from(k), v)))
|
||||
|
@ -178,11 +178,11 @@ fn key_none(i: &str) -> IResult<&str, &str> {
|
|||
}
|
||||
|
||||
fn key_single(i: &str) -> IResult<&str, &str> {
|
||||
delimited(tag("\'"), is_not("\'"), tag("\'"))(i)
|
||||
delimited(char('\''), is_not("\'"), char('\''))(i)
|
||||
}
|
||||
|
||||
fn key_double(i: &str) -> IResult<&str, &str> {
|
||||
delimited(tag("\""), is_not("\""), tag("\""))(i)
|
||||
delimited(char('\"'), is_not("\""), char('\"'))(i)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::sql::error::IResult;
|
|||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::map;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
@ -112,7 +113,7 @@ impl fmt::Display for Operator {
|
|||
|
||||
pub fn assigner(i: &str) -> IResult<&str, Operator> {
|
||||
alt((
|
||||
map(tag("="), |_| Operator::Equal),
|
||||
map(char('='), |_| Operator::Equal),
|
||||
map(tag("+="), |_| Operator::Inc),
|
||||
map(tag("-="), |_| Operator::Dec),
|
||||
))(i)
|
||||
|
@ -130,40 +131,40 @@ pub fn symbols(i: &str) -> IResult<&str, Operator> {
|
|||
map(tag("!="), |_| Operator::NotEqual),
|
||||
map(tag("*="), |_| Operator::AllEqual),
|
||||
map(tag("?="), |_| Operator::AnyEqual),
|
||||
map(tag("="), |_| Operator::Equal),
|
||||
map(char('='), |_| Operator::Equal),
|
||||
)),
|
||||
alt((
|
||||
map(tag("!~"), |_| Operator::NotLike),
|
||||
map(tag("*~"), |_| Operator::AllLike),
|
||||
map(tag("?~"), |_| Operator::AnyLike),
|
||||
map(tag("~"), |_| Operator::Like),
|
||||
map(char('~'), |_| Operator::Like),
|
||||
)),
|
||||
alt((
|
||||
map(tag("<="), |_| Operator::LessThanOrEqual),
|
||||
map(tag("<"), |_| Operator::LessThan),
|
||||
map(char('<'), |_| Operator::LessThan),
|
||||
map(tag(">="), |_| Operator::MoreThanOrEqual),
|
||||
map(tag(">"), |_| Operator::MoreThan),
|
||||
map(char('>'), |_| Operator::MoreThan),
|
||||
)),
|
||||
alt((
|
||||
map(tag("+"), |_| Operator::Add),
|
||||
map(tag("-"), |_| Operator::Sub),
|
||||
map(tag("*"), |_| Operator::Mul),
|
||||
map(tag("×"), |_| Operator::Mul),
|
||||
map(tag("∙"), |_| Operator::Mul),
|
||||
map(tag("/"), |_| Operator::Div),
|
||||
map(tag("÷"), |_| Operator::Div),
|
||||
map(char('+'), |_| Operator::Add),
|
||||
map(char('-'), |_| Operator::Sub),
|
||||
map(char('*'), |_| Operator::Mul),
|
||||
map(char('×'), |_| Operator::Mul),
|
||||
map(char('∙'), |_| Operator::Mul),
|
||||
map(char('/'), |_| Operator::Div),
|
||||
map(char('÷'), |_| Operator::Div),
|
||||
)),
|
||||
alt((
|
||||
map(tag("∋"), |_| Operator::Contain),
|
||||
map(tag("∌"), |_| Operator::NotContain),
|
||||
map(tag("∈"), |_| Operator::Inside),
|
||||
map(tag("∉"), |_| Operator::NotInside),
|
||||
map(tag("⊇"), |_| Operator::ContainAll),
|
||||
map(tag("⊃"), |_| Operator::ContainAny),
|
||||
map(tag("⊅"), |_| Operator::ContainNone),
|
||||
map(tag("⊆"), |_| Operator::AllInside),
|
||||
map(tag("⊂"), |_| Operator::AnyInside),
|
||||
map(tag("⊄"), |_| Operator::NoneInside),
|
||||
map(char('∋'), |_| Operator::Contain),
|
||||
map(char('∌'), |_| Operator::NotContain),
|
||||
map(char('∈'), |_| Operator::Inside),
|
||||
map(char('∉'), |_| Operator::NotInside),
|
||||
map(char('⊇'), |_| Operator::ContainAll),
|
||||
map(char('⊃'), |_| Operator::ContainAny),
|
||||
map(char('⊅'), |_| Operator::ContainNone),
|
||||
map(char('⊆'), |_| Operator::AllInside),
|
||||
map(char('⊂'), |_| Operator::AnyInside),
|
||||
map(char('⊄'), |_| Operator::NoneInside),
|
||||
)),
|
||||
))(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::sql::idiom::Idiom;
|
|||
use crate::sql::part::Next;
|
||||
use crate::sql::part::Part;
|
||||
use crate::sql::value::Value;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
@ -62,7 +62,7 @@ impl fmt::Display for Param {
|
|||
}
|
||||
|
||||
pub fn param(i: &str) -> IResult<&str, Param> {
|
||||
let (i, _) = tag("$")(i)?;
|
||||
let (i, _) = char('$')(i)?;
|
||||
let (i, v) = idiom::param(i)?;
|
||||
Ok((i, Param::from(v)))
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::sql::value::{value, Value};
|
|||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::char;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
@ -114,38 +115,38 @@ pub fn first(i: &str) -> IResult<&str, Part> {
|
|||
}
|
||||
|
||||
pub fn all(i: &str) -> IResult<&str, Part> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = tag("*")(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = char('*')(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, Part::All))
|
||||
}
|
||||
|
||||
pub fn last(i: &str) -> IResult<&str, Part> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = tag("$")(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = char('$')(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, Part::Last))
|
||||
}
|
||||
|
||||
pub fn index(i: &str) -> IResult<&str, Part> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, v) = number(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, Part::Index(v)))
|
||||
}
|
||||
|
||||
pub fn field(i: &str) -> IResult<&str, Part> {
|
||||
let (i, _) = tag(".")(i)?;
|
||||
let (i, _) = char('.')(i)?;
|
||||
let (i, v) = ident(i)?;
|
||||
Ok((i, Part::Field(v)))
|
||||
}
|
||||
|
||||
pub fn filter(i: &str) -> IResult<&str, Part> {
|
||||
let (i, _) = tag("[")(i)?;
|
||||
let (i, _) = char('[')(i)?;
|
||||
let (i, _) = alt((tag_no_case("WHERE"), tag("?")))(i)?;
|
||||
let (i, _) = shouldbespace(i)?;
|
||||
let (i, v) = value(i)?;
|
||||
let (i, _) = tag("]")(i)?;
|
||||
let (i, _) = char(']')(i)?;
|
||||
Ok((i, Part::Where(v)))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::sql::error::IResult;
|
||||
use nom::bytes::complete::escaped;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::character::complete::one_of;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
|
@ -49,9 +49,9 @@ impl fmt::Display for Regex {
|
|||
}
|
||||
|
||||
pub fn regex(i: &str) -> IResult<&str, Regex> {
|
||||
let (i, _) = tag("/")(i)?;
|
||||
let (i, _) = char('/')(i)?;
|
||||
let (i, v) = escaped(is_not("\\/"), '\\', one_of("/"))(i)?;
|
||||
let (i, _) = tag("/")(i)?;
|
||||
let (i, _) = char('/')(i)?;
|
||||
Ok((i, Regex::from(v)))
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::ident::{ident, Ident};
|
||||
use derive::Store;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::{map, opt};
|
||||
use nom::sequence::tuple;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -32,8 +32,8 @@ pub fn option(i: &str) -> IResult<&str, OptionStatement> {
|
|||
let (i, _) = shouldbespace(i)?;
|
||||
let (i, n) = ident(i)?;
|
||||
let (i, v) = opt(alt((
|
||||
map(tuple((mightbespace, tag("="), mightbespace, tag_no_case("TRUE"))), |_| true),
|
||||
map(tuple((mightbespace, tag("="), mightbespace, tag_no_case("FALSE"))), |_| false),
|
||||
map(tuple((mightbespace, char('='), mightbespace, tag_no_case("TRUE"))), |_| true),
|
||||
map(tuple((mightbespace, char('='), mightbespace, tag_no_case("FALSE"))), |_| false),
|
||||
)))(i)?;
|
||||
Ok((
|
||||
i,
|
||||
|
|
|
@ -14,8 +14,8 @@ use crate::sql::timeout::{timeout, Timeout};
|
|||
use crate::sql::value::{whats, Value, Values};
|
||||
use derive::Store;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::opt;
|
||||
use nom::sequence::preceded;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -119,11 +119,13 @@ pub fn relate(i: &str) -> IResult<&str, RelateStatement> {
|
|||
fn relate_o(i: &str) -> IResult<&str, (Table, Values, Values)> {
|
||||
let (i, from) = whats(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("->")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, kind) = table(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("->")(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = char('>')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, with) = whats(i)?;
|
||||
Ok((i, (kind, from, with)))
|
||||
|
@ -132,11 +134,13 @@ fn relate_o(i: &str) -> IResult<&str, (Table, Values, Values)> {
|
|||
fn relate_i(i: &str) -> IResult<&str, (Table, Values, Values)> {
|
||||
let (i, with) = whats(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("<-")(i)?;
|
||||
let (i, _) = char('<')(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, kind) = table(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("<-")(i)?;
|
||||
let (i, _) = char('<')(i)?;
|
||||
let (i, _) = char('-')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, from) = whats(i)?;
|
||||
Ok((i, (kind, from, with)))
|
||||
|
|
|
@ -8,8 +8,8 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::ident::ident_raw;
|
||||
use crate::sql::value::{value, Value};
|
||||
use derive::Store;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::bytes::complete::tag_no_case;
|
||||
use nom::character::complete::char;
|
||||
use nom::sequence::preceded;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
@ -41,9 +41,9 @@ impl fmt::Display for SetStatement {
|
|||
pub fn set(i: &str) -> IResult<&str, SetStatement> {
|
||||
let (i, _) = tag_no_case("LET")(i)?;
|
||||
let (i, _) = shouldbespace(i)?;
|
||||
let (i, n) = preceded(tag("$"), ident_raw)(i)?;
|
||||
let (i, n) = preceded(char('$'), ident_raw)(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, _) = tag("=")(i)?;
|
||||
let (i, _) = char('=')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
let (i, w) = value(i)?;
|
||||
Ok((
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::sql::statements::select::{select, SelectStatement};
|
|||
use crate::sql::statements::update::{update, UpdateStatement};
|
||||
use crate::sql::value::{value, Value};
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::map;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
|
@ -210,7 +210,7 @@ fn subquery_ifelse(i: &str) -> IResult<&str, Subquery> {
|
|||
}
|
||||
|
||||
fn subquery_others(i: &str) -> IResult<&str, Subquery> {
|
||||
let (i, _) = tag("(")(i)?;
|
||||
let (i, _) = char('(')(i)?;
|
||||
let (i, v) = alt((
|
||||
map(select, |v| Subquery::Select(Arc::new(v))),
|
||||
map(create, |v| Subquery::Create(Arc::new(v))),
|
||||
|
@ -220,7 +220,7 @@ fn subquery_others(i: &str) -> IResult<&str, Subquery> {
|
|||
map(insert, |v| Subquery::Insert(Arc::new(v))),
|
||||
map(value, Subquery::Value),
|
||||
))(i)?;
|
||||
let (i, _) = tag(")")(i)?;
|
||||
let (i, _) = char(')')(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::sql::common::escape;
|
|||
use crate::sql::common::val_char;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::ident::ident_raw;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
@ -49,8 +49,8 @@ impl Serialize for Thing {
|
|||
|
||||
pub fn thing(i: &str) -> IResult<&str, Thing> {
|
||||
let (i, t) = ident_raw(i)?;
|
||||
let (i, _) = tag(":")(i)?;
|
||||
let (i, v) = ident_raw(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
Ok((
|
||||
i,
|
||||
Thing {
|
||||
|
|
Loading…
Reference in a new issue