(input: ParseStream)
| 1139 | } |
| 1140 | |
| 1141 | fn parse_apply(input: ParseStream) -> Result { |
| 1142 | let ident = input.parse::<syn::Ident>()?; |
| 1143 | |
| 1144 | // parse parentheses |
| 1145 | let inner; |
| 1146 | syn::parenthesized!(inner in input); |
| 1147 | |
| 1148 | let parse_nullary = |func: UnmaterializableFunc| -> Result { |
| 1149 | Ok(MirScalarExpr::CallUnmaterializable(func)) |
| 1150 | }; |
| 1151 | let parse_unary = |func: UnaryFunc| -> Result { |
| 1152 | let expr = Box::new(parse_expr(&inner)?); |
| 1153 | Ok(MirScalarExpr::CallUnary { func, expr }) |
| 1154 | }; |
| 1155 | let parse_binary = |func: BinaryFunc| -> Result { |
| 1156 | let expr1 = Box::new(parse_expr(&inner)?); |
| 1157 | inner.parse::<syn::Token![,]>()?; |
| 1158 | let expr2 = Box::new(parse_expr(&inner)?); |
| 1159 | Ok(MirScalarExpr::CallBinary { func, expr1, expr2 }) |
| 1160 | }; |
| 1161 | let parse_variadic = |func: VariadicFunc| -> Result { |
| 1162 | let exprs = inner.parse_comma_sep(parse_expr)?; |
| 1163 | Ok(MirScalarExpr::call_variadic(func, exprs)) |
| 1164 | }; |
| 1165 | |
| 1166 | // Infix binary and variadic function calls are handled in `parse_scalar_expr`. |
| 1167 | // |
| 1168 | // Some restrictions apply with the current state of the code, |
| 1169 | // most notably one cannot handle overloaded function names because we don't want to do |
| 1170 | // name resolution in the parser. |
| 1171 | match ident.to_string().to_lowercase().as_str() { |
| 1172 | // Supported unmaterializable (a.k.a. nullary) functions: |
| 1173 | "mz_environment_id" => parse_nullary(UnmaterializableFunc::MzEnvironmentId), |
| 1174 | // Supported unary functions: |
| 1175 | "abs" => parse_unary(func::AbsInt64.into()), |
| 1176 | "not" => parse_unary(func::Not.into()), |
| 1177 | // Supported binary functions: |
| 1178 | "ltrim" => parse_binary(func::TrimLeading.into()), |
| 1179 | // Supported variadic functions: |
| 1180 | "greatest" => parse_variadic(VariadicFunc::Greatest(func::variadic::Greatest)), |
| 1181 | "coalesce" => parse_variadic(VariadicFunc::Coalesce(func::variadic::Coalesce)), |
| 1182 | _ => Err(Error::new(ident.span(), "unsupported function name")), |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | pub fn parse_join_equivalences(input: ParseStream) -> syn::Result<Vec<Vec<MirScalarExpr>>> { |
| 1187 | let mut equivalences = vec![]; |
no test coverage detected