(
tokens: &[Token],
position: &mut usize,
)
| 1188 | } |
| 1189 | |
| 1190 | fn parse_limit_statement( |
| 1191 | tokens: &[Token], |
| 1192 | position: &mut usize, |
| 1193 | ) -> Result<Statement, Box<Diagnostic>> { |
| 1194 | // Consume `LIMIT` keyword |
| 1195 | *position += 1; |
| 1196 | |
| 1197 | if *position >= tokens.len() { |
| 1198 | return Err(Diagnostic::error("Expect number after `LIMIT` keyword") |
| 1199 | .with_location(calculate_safe_location(tokens, *position - 1)) |
| 1200 | .as_boxed()); |
| 1201 | } |
| 1202 | |
| 1203 | match tokens[*position].kind { |
| 1204 | TokenKind::Integer(integer) => { |
| 1205 | // Consume Integer value |
| 1206 | *position += 1; |
| 1207 | |
| 1208 | // Make sure limit value is always positive |
| 1209 | if integer < 0 { |
| 1210 | return Err( |
| 1211 | Diagnostic::error("Expect positive number after `LIMIT` keyword") |
| 1212 | .with_location(calculate_safe_location(tokens, *position - 1)) |
| 1213 | .as_boxed(), |
| 1214 | ); |
| 1215 | } |
| 1216 | |
| 1217 | let count = integer as usize; |
| 1218 | Ok(Statement::Limit(LimitStatement { count })) |
| 1219 | } |
| 1220 | _ => Err(Diagnostic::error("Expect number after `LIMIT` keyword") |
| 1221 | .with_location(calculate_safe_location(tokens, *position - 1)) |
| 1222 | .as_boxed()), |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | fn parse_offset_statement( |
| 1227 | context: &mut ParserContext, |
no test coverage detected
searching dependent graphs…