luaur_ast/methods/
parser_parse_assertion_expr.rs1use crate::records::ast_expr::AstExpr;
2use crate::records::ast_expr_type_assertion::AstExprTypeAssertion;
3use crate::records::cst_expr_type_assertion::CstExprTypeAssertion;
4use crate::records::lexeme::Lexeme;
5use crate::records::location::Location;
6use crate::records::parser::Parser;
7
8impl Parser {
9 pub fn parse_assertion_expr(&mut self) -> *mut AstExpr {
10 let start = self.lexer.current().location;
11 let expr = self.parse_simple_expr();
12
13 if self.lexer.current().r#type == crate::records::lexeme::Type::DoubleColon {
14 let op_position = self.lexer.current().location.begin;
15 self.next_lexeme();
16 let annotation = self.parse_type_bool(false);
17
18 let node = unsafe {
19 (*self.allocator).alloc(AstExprTypeAssertion::new(
20 Location::new(start.begin, (*annotation).base.location.end),
21 expr,
22 annotation,
23 ))
24 };
25
26 if self.options.store_cst_data {
27 let cst_node =
28 unsafe { (*self.allocator).alloc(CstExprTypeAssertion::new(op_position)) };
29 self.cst_node_map.try_insert(
30 node as *mut crate::records::ast_node::AstNode,
31 cst_node as *mut crate::records::cst_node::CstNode,
32 );
33 }
34
35 node as *mut AstExpr
36 } else {
37 expr
38 }
39 }
40}