parent
e9476b9f85
commit
a71562df9f
1 changed files with 17 additions and 18 deletions
|
@ -154,7 +154,7 @@ impl Function {
|
||||||
impl fmt::Display for Function {
|
impl fmt::Display for Function {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Function::Future(ref e) => write!(f, "fn::future -> {{ {} }}", e),
|
Function::Future(ref e) => write!(f, "<future> {{ {} }}", e),
|
||||||
Function::Cast(ref s, ref e) => write!(f, "<{}> {}", s, e),
|
Function::Cast(ref s, ref e) => write!(f, "<{}> {}", s, e),
|
||||||
Function::Script(ref s, ref e) => write!(
|
Function::Script(ref s, ref e) => write!(
|
||||||
f,
|
f,
|
||||||
|
@ -173,21 +173,7 @@ impl fmt::Display for Function {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn function(i: &str) -> IResult<&str, Function> {
|
pub fn function(i: &str) -> IResult<&str, Function> {
|
||||||
alt((future, normal, script, cast))(i)
|
alt((normal, script, future, 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)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normal(i: &str) -> IResult<&str, Function> {
|
fn normal(i: &str) -> IResult<&str, Function> {
|
||||||
|
@ -218,6 +204,19 @@ fn script(i: &str) -> IResult<&str, Function> {
|
||||||
Ok((i, Function::Script(v, a)))
|
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> {
|
fn cast(i: &str) -> IResult<&str, Function> {
|
||||||
let (i, _) = char('<')(i)?;
|
let (i, _) = char('<')(i)?;
|
||||||
let (i, s) = function_casts(i)?;
|
let (i, s) = function_casts(i)?;
|
||||||
|
@ -503,11 +502,11 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_future_expression() {
|
fn function_future_expression() {
|
||||||
let sql = "fn::future -> { 1.2345 + 5.4321 }";
|
let sql = "<future> { 1.2345 + 5.4321 }";
|
||||||
let res = function(sql);
|
let res = function(sql);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!("fn::future -> { 1.2345 + 5.4321 }", format!("{}", out));
|
assert_eq!("<future> { 1.2345 + 5.4321 }", format!("{}", out));
|
||||||
assert_eq!(out, Function::Future(Value::from(Expression::parse("1.2345 + 5.4321"))));
|
assert_eq!(out, Function::Future(Value::from(Expression::parse("1.2345 + 5.4321"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue