luaur_ast/methods/
parser_parse_prefix_expr.rs1use crate::enums::type_lexer::Type;
2use crate::records::ast_expr::AstExpr;
3use crate::records::ast_expr_group::AstExprGroup;
4use crate::records::cst_expr_group::CstExprGroup;
5use crate::records::location::Location;
6use crate::records::match_lexeme::MatchLexeme;
7use crate::records::parser::Parser;
8use crate::records::position::Position;
9
10impl Parser {
11 pub fn parse_prefix_expr(&mut self) -> *mut AstExpr {
12 if self.lexer.current().r#type == Type('(' as i32) {
13 let start = self.lexer.current().location.begin;
14 let match_paren = MatchLexeme::new(self.lexer.current());
15 self.next_lexeme();
16
17 let expr = self.parse_expr_i32(0);
18 let mut end = self.lexer.current().location.end;
19 let mut close_paren_found = false;
20
21 if self.lexer.current().r#type != Type(')' as i32) {
22 let suggestion = if self.lexer.current().r#type == Type('=' as i32) {
23 Some("; did you mean to use '{' when defining a table?")
24 } else {
25 None
26 };
27
28 self.expect_match_and_consume_fail(Type(')' as i32), &match_paren, suggestion);
29 end = self.lexer.previous_location().end;
30 } else {
31 close_paren_found = true;
32 self.next_lexeme();
33 }
34
35 let expr_group = unsafe {
36 (*self.allocator).alloc(AstExprGroup::new(Location::new(start, end), expr))
37 };
38
39 if luaur_common::FFlag::LuauCstExprGroup.get() && self.options.store_cst_data {
40 let close_pos = if close_paren_found {
41 self.lexer.previous_location().begin
42 } else {
43 Position::missing()
44 };
45 let cst_node = unsafe { (*self.allocator).alloc(CstExprGroup::new(close_pos)) };
46 self.cst_node_map.try_insert(
47 expr_group as *mut crate::records::ast_node::AstNode,
48 cst_node as *mut crate::records::cst_node::CstNode,
49 );
50 }
51
52 expr_group as *mut AstExpr
53 } else {
54 self.parse_name_expr("expression")
55 }
56 }
57}