#[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(),
)
};
}