Use function() {} instead of fn::future -> () => {} syntax for SQL embedded functions
Closes #8
This commit is contained in:
parent
db2208a33a
commit
66946397ed
1 changed files with 4 additions and 9 deletions
|
@ -158,7 +158,7 @@ impl fmt::Display for Function {
|
||||||
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,
|
||||||
"fn::script -> ({}) => {{{}}}",
|
"function({}) {{{}}}",
|
||||||
e.iter().map(|ref v| format!("{}", v)).collect::<Vec<_>>().join(", "),
|
e.iter().map(|ref v| format!("{}", v)).collect::<Vec<_>>().join(", "),
|
||||||
s,
|
s,
|
||||||
),
|
),
|
||||||
|
@ -187,17 +187,12 @@ fn normal(i: &str) -> IResult<&str, Function> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script(i: &str) -> IResult<&str, Function> {
|
fn script(i: &str) -> IResult<&str, Function> {
|
||||||
let (i, _) = tag("fn::script")(i)?;
|
let (i, _) = alt((tag("fn::script"), tag("fn"), tag("function")))(i)?;
|
||||||
let (i, _) = mightbespace(i)?;
|
|
||||||
let (i, _) = char('-')(i)?;
|
|
||||||
let (i, _) = char('>')(i)?;
|
|
||||||
let (i, _) = mightbespace(i)?;
|
let (i, _) = mightbespace(i)?;
|
||||||
let (i, _) = tag("(")(i)?;
|
let (i, _) = tag("(")(i)?;
|
||||||
let (i, a) = separated_list0(commas, value)(i)?;
|
let (i, a) = separated_list0(commas, value)(i)?;
|
||||||
let (i, _) = tag(")")(i)?;
|
let (i, _) = tag(")")(i)?;
|
||||||
let (i, _) = mightbespace(i)?;
|
let (i, _) = mightbespace(i)?;
|
||||||
let (i, _) = tag("=>")(i)?;
|
|
||||||
let (i, _) = mightbespace(i)?;
|
|
||||||
let (i, _) = char('{')(i)?;
|
let (i, _) = char('{')(i)?;
|
||||||
let (i, v) = func(i)?;
|
let (i, v) = func(i)?;
|
||||||
let (i, _) = char('}')(i)?;
|
let (i, _) = char('}')(i)?;
|
||||||
|
@ -512,12 +507,12 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_script_expression() {
|
fn function_script_expression() {
|
||||||
let sql = "fn::script -> () => { return this.tags.filter(t => { return t.length > 3; }); }";
|
let sql = "function() { return this.tags.filter(t => { return t.length > 3; }); }";
|
||||||
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!(
|
assert_eq!(
|
||||||
"fn::script -> () => { return this.tags.filter(t => { return t.length > 3; }); }",
|
"function() { return this.tags.filter(t => { return t.length > 3; }); }",
|
||||||
format!("{}", out)
|
format!("{}", out)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue