luaur_ast/methods/
parser_parse_do.rs1use crate::records::allocator::Allocator;
2use crate::records::ast_stat::AstStat;
3use crate::records::ast_stat_block::AstStatBlock;
4use crate::records::cst_stat_do::CstStatDo;
5use crate::records::lexeme::Lexeme;
6use crate::records::location::Location;
7use crate::records::match_lexeme::MatchLexeme;
8use crate::records::parser::Parser;
9use crate::records::position::Position;
10
11impl Parser {
12 pub fn parse_do(&mut self) -> *mut AstStat {
13 let start = self.lexer.current().location;
14
15 let match_do = *self.lexer.current();
16 self.next_lexeme(); let stats_start = self.lexer.current().location.begin;
19
20 let body = self.parse_block();
21
22 unsafe {
23 (*body).base.base.location.begin = start.begin;
24 }
25
26 let end_location = self.lexer.current().location;
27 let has_end = self.expect_match_end_and_consume(
28 crate::records::lexeme::Type::ReservedEnd,
29 &MatchLexeme::new(&match_do),
30 );
31 unsafe {
32 (*body).has_end = has_end;
33 }
34 if has_end {
35 unsafe {
36 (*body).base.base.location.end = end_location.end;
37 }
38 }
39
40 if self.options.store_cst_data {
41 let end_position = if has_end {
42 end_location.begin
43 } else {
44 Position::missing()
45 };
46 let cst_node =
47 unsafe { (*self.allocator).alloc(CstStatDo::new(stats_start, end_position)) };
48 self.cst_node_map.try_insert(
49 body as *mut crate::records::ast_node::AstNode,
50 cst_node as *mut crate::records::cst_node::CstNode,
51 );
52 }
53
54 body as *mut AstStat
55 }
56}