Skip to main content

luaur_ast/methods/
parser_parse_call_list.rs

1use crate::records::ast_array::AstArray;
2use crate::records::ast_expr::AstExpr;
3use crate::records::location::Location;
4use crate::records::parser::Parser;
5use crate::records::position::Position;
6use crate::records::temp_vector::TempVector;
7
8impl Parser {
9    pub fn parse_call_list(
10        &mut self,
11        comma_positions: *mut TempVector<'_, Position>,
12    ) -> (AstArray<*mut AstExpr>, Location, Location) {
13        let current_type = self.lexer.current().r#type;
14        luaur_common::LUAU_ASSERT!(
15            current_type == crate::records::lexeme::Type('(' as i32)
16                || current_type == crate::records::lexeme::Type('{' as i32)
17                || current_type == crate::records::lexeme::Type::RawString
18                || current_type == crate::records::lexeme::Type::QuotedString
19        );
20
21        if current_type == crate::records::lexeme::Type('(' as i32) {
22            let arg_start = self.lexer.current().location.end;
23
24            let match_paren = crate::records::match_lexeme::MatchLexeme::new(self.lexer.current());
25            self.next_lexeme();
26
27            let mut args = TempVector::new(&mut self.scratch_expr);
28
29            if self.lexer.current().r#type != crate::records::lexeme::Type(')' as i32) {
30                if !comma_positions.is_null() {
31                    self.parse_expr_list(&mut args, Some(unsafe { &mut *comma_positions }));
32                } else {
33                    self.parse_expr_list(&mut args, None);
34                }
35            }
36
37            let end = self.lexer.current().location;
38            let arg_end = end.end;
39
40            self.expect_match_and_consume(')', &match_paren, false);
41
42            let args_array = self.copy_temp_vector_t(&args);
43            (
44                args_array,
45                Location::new(arg_start, arg_end),
46                Location::new(match_paren.position, self.lexer.previous_location().begin),
47            )
48        } else if current_type == crate::records::lexeme::Type('{' as i32) {
49            let arg_start = self.lexer.current().location.end;
50            let expr = self.parse_table_constructor();
51            let arg_end = self.lexer.previous_location().end;
52
53            let expr_array = self.copy_t_usize(&expr as *const *mut AstExpr, 1);
54            (expr_array, Location::new(arg_start, arg_end), unsafe {
55                (*expr).base.location
56            })
57        } else {
58            let arg_location = self.lexer.current().location;
59            let expr = self.parse_string();
60            let expr_array = self.copy_t_usize(&expr as *const *mut AstExpr, 1);
61            (expr_array, arg_location, unsafe { (*expr).base.location })
62        }
63    }
64}