(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 1141 | } |
| 1142 | |
| 1143 | fn parse_qualify_statement( |
| 1144 | context: &mut ParserContext, |
| 1145 | env: &mut Environment, |
| 1146 | tokens: &[Token], |
| 1147 | position: &mut usize, |
| 1148 | ) -> Result<Statement, Box<Diagnostic>> { |
| 1149 | // Consume `QUALIFY` token |
| 1150 | *position += 1; |
| 1151 | |
| 1152 | if *position >= tokens.len() { |
| 1153 | return Err( |
| 1154 | Diagnostic::error("Expect expression after `QUALIFY` keyword") |
| 1155 | .add_help("Try to add boolean expression after `QUALIFY` keyword") |
| 1156 | .add_note("`QUALIFY` statement expects expression as condition") |
| 1157 | .with_location(calculate_safe_location(tokens, *position - 1)) |
| 1158 | .as_boxed(), |
| 1159 | ); |
| 1160 | } |
| 1161 | |
| 1162 | // Make sure QUALIFY condition expression has boolean type |
| 1163 | let condition_location = tokens[*position].location; |
| 1164 | let mut condition = parse_expression(context, env, tokens, position)?; |
| 1165 | |
| 1166 | // Make sure that the condition type is boolean, or can implicit cast to boolean. |
| 1167 | if !condition.expr_type().is_bool() { |
| 1168 | let expected_type: Box<dyn DataType> = Box::new(BoolType); |
| 1169 | if !expected_type.has_implicit_cast_from(&condition) { |
| 1170 | return Err(Diagnostic::error(&format!( |
| 1171 | "Expect `QUALIFY` condition to be type {} but got {}", |
| 1172 | "Boolean", |
| 1173 | condition.expr_type().literal() |
| 1174 | )) |
| 1175 | .add_note("`QUALIFY` statement condition must be Boolean") |
| 1176 | .with_location(condition_location) |
| 1177 | .as_boxed()); |
| 1178 | } |
| 1179 | |
| 1180 | // Implicit cast the condition to boolean |
| 1181 | condition = Box::new(CastExpr { |
| 1182 | value: condition, |
| 1183 | result_type: expected_type.clone(), |
| 1184 | }) |
| 1185 | } |
| 1186 | |
| 1187 | Ok(Statement::Qualify(QualifyStatement { condition })) |
| 1188 | } |
| 1189 | |
| 1190 | fn parse_limit_statement( |
| 1191 | tokens: &[Token], |
no test coverage detected
searching dependent graphs…