luaur_ast/methods/
parser_parse_block_no_scope.rs1use crate::functions::is_stat_last::is_stat_last;
2use crate::records::allocator::Allocator;
3use crate::records::ast_array::AstArray;
4use crate::records::ast_stat::AstStat;
5use crate::records::ast_stat_block::AstStatBlock;
6use crate::records::cst_node::CstNode;
7use crate::records::lexeme::Lexeme;
8use crate::records::location::Location;
9use crate::records::parser::Parser;
10use crate::records::position::Position;
11use crate::records::temp_vector::TempVector;
12
13impl Parser {
14 pub fn parse_block_no_scope(&mut self) -> *mut AstStatBlock {
15 let mut body = TempVector::new(&mut self.scratch_stat);
16
17 let prev_position = self.lexer.previous_location().end;
18
19 while !self.block_follow(self.lexer.current()) {
20 let old_recursion_count = self.recursion_counter;
21
22 self.increment_recursion_counter("block");
23
24 let stat = self.parse_stat();
25
26 self.recursion_counter = old_recursion_count;
27
28 if self.lexer.current().r#type == crate::records::lexeme::Type::Semicolon {
29 self.next_lexeme();
30 unsafe {
31 (*stat).has_semicolon = true;
32 }
33 unsafe {
34 (*stat).base.location.end = self.lexer.previous_location().end;
35 }
36 }
37
38 body.push_back(stat);
39
40 if is_stat_last(stat) {
41 break;
42 }
43 }
44
45 let location = Location::new(prev_position, self.lexer.current().location.begin);
46
47 let node = unsafe {
48 (*self.allocator).alloc(AstStatBlock::new(
49 location,
50 self.copy_temp_vector_t(&body),
51 true,
52 ))
53 };
54
55 node as *mut AstStatBlock
61 }
62}