Skip to main content

luaur_ast/methods/
parser_check_unary_confusables.rs

1use crate::records::ast_expr_unary::AstExprUnaryOp;
2use crate::records::lexeme::Type;
3use crate::records::parser::Parser;
4
5impl Parser {
6    pub fn check_unary_confusables(&mut self) -> Option<AstExprUnaryOp> {
7        let curr = self.lexer.current();
8
9        // early-out: need to check if this is a possible confusable quickly
10        if curr.r#type != Type('!' as i32) {
11            return None;
12        }
13
14        // slow path: possible confusable
15        let start = curr.location;
16
17        if curr.r#type == Type('!' as i32) {
18            self.report_location_c_char_item(
19                start,
20                format_args!("Unexpected '!'; did you mean 'not'?"),
21            );
22            return Some(AstExprUnaryOp::Not);
23        }
24
25        None
26    }
27}
28
29pub fn parser_check_unary_confusables(this: &mut Parser) -> Option<AstExprUnaryOp> {
30    this.check_unary_confusables()
31}