luaur_ast/methods/
parser_expect_and_consume_fail.rs1use crate::records::lexeme::{Lexeme, Type};
2use crate::records::location::Location;
3use crate::records::parser::Parser;
4use crate::records::position::Position;
5use luaur_common::macros::luau_noinline::LUAU_NOINLINE;
6
7impl Parser {
8 LUAU_NOINLINE! {
9 pub fn expect_and_consume_fail(&mut self, type_: Type, context: &str) {
10 let type_string = Lexeme::new(Location::new(Position::new(0, 0), Position::new(0, 0)), type_).to_string();
11 let curr_lexeme_string = self.lexer.current().to_string();
12
13 if !context.is_empty() {
14 self.report(
15 self.lexer.current().location,
16 format_args!(
17 "Expected {} when parsing {}, got {}",
18 type_string, context, curr_lexeme_string
19 ),
20 );
21 } else {
22 self.report(
23 self.lexer.current().location,
24 format_args!("Expected {}, got {}", type_string, curr_lexeme_string),
25 );
26 }
27 }
28 }
29}