~starkingdoms/starkingdoms

ref: fdb3bfb1e0bf0eea64a9aad0f81d305728daedc2 starkingdoms/kabel/src/macros.rs -rw-r--r-- 1.1 KiB
fdb3bfb1 — ghostlyzsh functions added 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
#[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! 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(),
        )
    };
}