Skip to main content

luaur_ast/methods/
parser_report_function_args_error.rs

1use crate::records::ast_expr::AstExpr;
2use crate::records::location::Location;
3use crate::records::parser::Parser;
4use luaur_common::macros::luau_noinline::LUAU_NOINLINE;
5
6impl Parser {
7    LUAU_NOINLINE! {
8        pub fn report_function_args_error(&mut self, func: *mut AstExpr, self_flag: bool) -> *mut AstExpr {
9            let current_lexeme = self.lexer.current();
10            let func_loc = unsafe { (*func).base.location };
11
12            if self_flag && current_lexeme.location.begin.line != func_loc.end.line {
13                let expressions = self.copy_initializer_list_t(&[func]);
14                self.report_expr_error(
15                    func_loc,
16                    expressions,
17                    format_args!("Expected function call arguments after '('"),
18                ) as *mut AstExpr
19            } else {
20                // Read everything off `current_lexeme` (which borrows self.lexer)
21                // BEFORE the `&mut self` calls below, or the borrow conflicts.
22                let loc = Location::new(func_loc.begin, current_lexeme.location.begin);
23                let lexeme_str = current_lexeme.to_string();
24                let expressions = self.copy_initializer_list_t(&[func]);
25                self.report_expr_error(
26                    loc,
27                    expressions,
28                    format_args!(
29                        "Expected '(', '{{' or <string> when parsing function call, got {}",
30                        lexeme_str
31                    ),
32                ) as *mut AstExpr
33            }
34        }
35    }
36}