(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 32 | } |
| 33 | |
| 34 | pub(crate) fn parse_cast_call_expression( |
| 35 | context: &mut ParserContext, |
| 36 | env: &mut Environment, |
| 37 | tokens: &[Token], |
| 38 | position: &mut usize, |
| 39 | ) -> Result<Box<dyn Expr>, Box<Diagnostic>> { |
| 40 | let cast_token_location = |
| 41 | consume_token_or_error(tokens, position, TokenKind::Cast, "Expect 'CAST' Keyword")? |
| 42 | .location; |
| 43 | |
| 44 | consume_token_or_error( |
| 45 | tokens, |
| 46 | position, |
| 47 | TokenKind::LeftParen, |
| 48 | "Expect '(' after 'CAST' Keyword", |
| 49 | )?; |
| 50 | |
| 51 | let expr = parse_expression(context, env, tokens, position)?; |
| 52 | |
| 53 | consume_token_or_error( |
| 54 | tokens, |
| 55 | position, |
| 56 | TokenKind::As, |
| 57 | "Expect 'AS' keyword after 'CAST' expression value", |
| 58 | )?; |
| 59 | |
| 60 | let target_type = parse_type(env, tokens, position)?; |
| 61 | |
| 62 | consume_token_or_error( |
| 63 | tokens, |
| 64 | position, |
| 65 | TokenKind::RightParen, |
| 66 | "Expect ')' at the end of 'CAST' expression", |
| 67 | )?; |
| 68 | |
| 69 | cast_expression_or_error(expr, target_type, cast_token_location) |
| 70 | } |
| 71 | |
| 72 | fn cast_expression_or_error( |
| 73 | expr: Box<dyn Expr>, |
no test coverage detected
searching dependent graphs…