From a71562df9f8d6c6ca9c1c47671d0b2b71ce270c4 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 23 Jul 2022 13:28:35 +0100 Subject: [PATCH] Use instead of fn::future syntax for SQL futures Closes #9 --- lib/src/sql/function.rs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 848d7834..97dc108b 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -154,7 +154,7 @@ impl Function { impl fmt::Display for Function { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Function::Future(ref e) => write!(f, "fn::future -> {{ {} }}", e), + Function::Future(ref e) => write!(f, " {{ {} }}", e), Function::Cast(ref s, ref e) => write!(f, "<{}> {}", s, e), Function::Script(ref s, ref e) => write!( f, @@ -173,21 +173,7 @@ impl fmt::Display for Function { } pub fn function(i: &str) -> IResult<&str, Function> { - alt((future, normal, script, cast))(i) -} - -fn future(i: &str) -> IResult<&str, Function> { - let (i, _) = tag("fn::future")(i)?; - let (i, _) = mightbespace(i)?; - let (i, _) = char('-')(i)?; - let (i, _) = char('>')(i)?; - let (i, _) = mightbespace(i)?; - let (i, _) = char('{')(i)?; - let (i, _) = mightbespace(i)?; - let (i, v) = value(i)?; - let (i, _) = mightbespace(i)?; - let (i, _) = char('}')(i)?; - Ok((i, Function::Future(v))) + alt((normal, script, future, cast))(i) } fn normal(i: &str) -> IResult<&str, Function> { @@ -218,6 +204,19 @@ fn script(i: &str) -> IResult<&str, Function> { Ok((i, Function::Script(v, a))) } +fn future(i: &str) -> IResult<&str, Function> { + let (i, _) = char('<')(i)?; + let (i, _) = tag("future")(i)?; + let (i, _) = char('>')(i)?; + let (i, _) = mightbespace(i)?; + let (i, _) = char('{')(i)?; + let (i, _) = mightbespace(i)?; + let (i, v) = value(i)?; + let (i, _) = mightbespace(i)?; + let (i, _) = char('}')(i)?; + Ok((i, Function::Future(v))) +} + fn cast(i: &str) -> IResult<&str, Function> { let (i, _) = char('<')(i)?; let (i, s) = function_casts(i)?; @@ -503,11 +502,11 @@ mod tests { #[test] fn function_future_expression() { - let sql = "fn::future -> { 1.2345 + 5.4321 }"; + let sql = " { 1.2345 + 5.4321 }"; let res = function(sql); assert!(res.is_ok()); let out = res.unwrap().1; - assert_eq!("fn::future -> { 1.2345 + 5.4321 }", format!("{}", out)); + assert_eq!(" { 1.2345 + 5.4321 }", format!("{}", out)); assert_eq!(out, Function::Future(Value::from(Expression::parse("1.2345 + 5.4321")))); }