kproc_parser/
macros.rs

1#[macro_export]
2macro_rules! check {
3    ($a:literal, $b:expr) => {
4        KParserError::expect($a, &$b, line!().to_string(), file!().to_string())
5    };
6}
7
8#[macro_export]
9/// emit a warning when the expression
10/// is verified
11macro_rules! warn {
12    ($when: expr, $tok: expr, $($msg:tt)*) => {
13        if $when {
14            use $crate::kdiagnostic::KDiagnInfo;
15            let msg = format!($($msg)*);
16            KDiagnInfo::new(&msg, $tok, line!().to_string(), file!().to_string()).warn().emit()
17        }
18    };
19}
20
21#[macro_export]
22/// emit a compiler error
23macro_rules! error {
24    ($tok: expr, $($msg:tt)*) => {{
25        use $crate::kdiagnostic::KDiagnInfo;
26        let msg = format!($($msg)*);
27        KDiagnInfo::new(&msg, $tok, line!().to_string(), file!().to_string()).emit()
28    }};
29}
30
31#[macro_export]
32/// emit a compiler error
33macro_rules! build_error {
34    ($tok: expr, $($msg:tt)*) => {{
35        let msg = format!($($msg)*);
36        KParserError::with_msg($tok, &msg, line!().to_string(), file!().to_string())
37    }};
38}
39
40#[macro_export]
41macro_rules! trace {
42    ($trace:expr, $($msg:tt)*) => {
43        $trace.log(&format!($($msg)*))
44    };
45}