luaur_ast/methods/
parser_parse_index_expr.rs1use crate::records::allocator::Allocator;
2use crate::records::ast_expr::AstExpr;
3use crate::records::ast_expr_index_expr::AstExprIndexExpr;
4use crate::records::cst_expr_index_expr::CstExprIndexExpr;
5use crate::records::location::Location;
6use crate::records::match_lexeme::MatchLexeme;
7use crate::records::parser::Parser;
8use crate::records::position::Position;
9
10impl Parser {
11 pub(crate) fn parse_index_expr(&mut self, start: Position, expr: *mut AstExpr) -> *mut AstExpr {
12 let match_bracket = MatchLexeme::new(self.lexer.current());
13 self.next_lexeme();
14
15 let index = self.parse_expr_i32(0);
16
17 let close_bracket_position = self.lexer.current().location.begin;
18 let end = self.lexer.current().location.end;
19
20 let closing_bracket_found = self.expect_match_and_consume(']', &match_bracket, true);
21
22 let expr = unsafe {
23 (*self.allocator).alloc(AstExprIndexExpr::new(
24 Location::new(start, end),
25 expr,
26 index,
27 ))
28 };
29
30 if self.options.store_cst_data {
31 let cst_node = unsafe {
32 (*self.allocator).alloc(CstExprIndexExpr::new(
33 match_bracket.position,
34 if closing_bracket_found {
35 close_bracket_position
36 } else {
37 Position::missing()
38 },
39 ))
40 };
41 self.cst_node_map.try_insert(
42 expr as *mut crate::records::ast_node::AstNode,
43 cst_node as *mut crate::records::cst_node::CstNode,
44 );
45 }
46
47 expr as *mut AstExpr
48 }
49}