~starkingdoms/starkingdoms

ref: 8275afd2a78ba022ad6a32b762b55aa6b2583eaa starkingdoms/kabel/src/macros.rs -rw-r--r-- 1.3 KiB
8275afd2 — ghostlyzsh increment and decrement, desugaring 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#[macro_export]
macro_rules! token {
    ($self:expr, $token:expr) => {
        crate::lexer::Token {
            line: $self.line,
            line_start: $self.line_start,
            column: $self.column,
            start: $self.start,
            end: $self.current,
            token_type: $token,
        }
    };
}

#[macro_export]
macro_rules! lit {
    ($type:ident, $data:expr, $token:expr) => {
        $crate::parser::AST {
            ast_type: $crate::parser::ASTType::Lit($crate::parser::Lit::$type($data)),
            start: $token.start,
            end: $token.end,
            line: $token.line,
            column: $token.column,
        }
    };
}

#[macro_export]
macro_rules! ast {
    ($ast_type:expr, $start:expr, $end:expr) => {
        AST {
            ast_type: $ast_type,
            start: $start.start,
            end: $end.end,
            line: $start.line,
            column: $start.column,
        }
    };
}

#[macro_export]
macro_rules! unexpected_token {
    ($self:expr, $message:expr, $token:expr) => {
        $crate::error::KabelError::new(
            $crate::error::ErrorKind::UnexpectedToken,
            format!($message, $self.text[$token.start..$token.end].to_string()),
            $token.line,
            $token.column,
            $self.text[$token.line_start..$token.end].to_string(),
        )
    };
}