luaur_ast/methods/
parser_parse_table_indexer.rs1use crate::enums::ast_table_access::AstTableAccess;
2use crate::records::ast_table_indexer::AstTableIndexer;
3use crate::records::lexeme::Lexeme;
4use crate::records::location::Location;
5use crate::records::parser::Parser;
6use crate::records::position::Position;
7use crate::records::table_indexer_result::TableIndexerResult;
8
9impl Parser {
10 pub fn parse_table_indexer(
11 &mut self,
12 access: AstTableAccess,
13 access_location: Option<Location>,
14 begin: Lexeme,
15 ) -> TableIndexerResult {
16 let index = self.parse_type_bool(false);
17
18 let indexer_close_found = self.expect_and_consume_char(']', "table field");
19 let indexer_close_position = if indexer_close_found {
20 self.lexer.previous_location().begin
21 } else {
22 Position::missing()
23 };
24
25 let colon_found = self.expect_and_consume_char(':', "table field");
26 let colon_position = if colon_found {
27 self.lexer.previous_location().begin
28 } else {
29 Position::missing()
30 };
31
32 let result = self.parse_type_bool(false);
33
34 let node = unsafe {
35 (*self.allocator).alloc(AstTableIndexer {
36 index_type: index,
37 result_type: result,
38 location: Location::new(begin.location.begin, unsafe {
39 (*result).base.location.end
40 }),
41 access,
42 access_location,
43 })
44 };
45
46 TableIndexerResult {
47 node,
48 indexer_open_position: begin.location.begin,
49 indexer_close_position,
50 colon_position,
51 }
52 }
53}