(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 14 | use crate::token::TokenKind; |
| 15 | |
| 16 | pub(crate) fn parse_order_by_statement( |
| 17 | context: &mut ParserContext, |
| 18 | env: &mut Environment, |
| 19 | tokens: &[Token], |
| 20 | position: &mut usize, |
| 21 | ) -> Result<Statement, Box<Diagnostic>> { |
| 22 | // Consume `ORDER` keyword |
| 23 | *position += 1; |
| 24 | |
| 25 | context.inside_order_by = true; |
| 26 | |
| 27 | // Consume `BY` keyword |
| 28 | consume_token_or_error( |
| 29 | tokens, |
| 30 | position, |
| 31 | TokenKind::By, |
| 32 | "Expect keyword `BY` after keyword `ORDER", |
| 33 | )?; |
| 34 | |
| 35 | let mut arguments: Vec<Box<dyn Expr>> = vec![]; |
| 36 | let mut sorting_orders: Vec<SortingOrder> = vec![]; |
| 37 | let mut null_ordering_policies: Vec<NullsOrderPolicy> = vec![]; |
| 38 | |
| 39 | loop { |
| 40 | let argument = parse_expression(context, env, tokens, position)?; |
| 41 | let sorting_order = parse_sorting_order(tokens, position)?; |
| 42 | let null_ordering_policy = parse_order_by_nulls_policy(tokens, position, &sorting_order)?; |
| 43 | |
| 44 | arguments.push(argument); |
| 45 | sorting_orders.push(sorting_order); |
| 46 | null_ordering_policies.push(null_ordering_policy); |
| 47 | |
| 48 | if is_current_token(tokens, position, TokenKind::Comma) { |
| 49 | // Consume `,` keyword |
| 50 | *position += 1; |
| 51 | } else { |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | context.inside_order_by = false; |
| 57 | |
| 58 | Ok(Statement::OrderBy(OrderByStatement { |
| 59 | arguments, |
| 60 | sorting_orders, |
| 61 | nulls_order_policies: null_ordering_policies, |
| 62 | })) |
| 63 | } |
| 64 | |
| 65 | fn parse_sorting_order( |
| 66 | tokens: &[Token], |
no test coverage detected
searching dependent graphs…