Improved bug implementations

This commit is contained in:
2026-05-16 05:32:10 +02:00
parent cbd060149d
commit 1a80fe074b
4 changed files with 41 additions and 31 deletions
+16
View File
@@ -32,6 +32,22 @@ pub fn parse<'a>(source: &'a str) -> Result<Vec<TopLevel>, ParseError<'a, Vec<To
}
}
#[macro_export]
macro_rules! ast_ensure {
($pair:expr, $rule:expr => $body:block) => {
if $pair.as_rule() == $rule
$body
else {
Err(AstError {
span: $pair.as_span(),
error_code: crate::error::ErrorCode::AstGenBug,
error_message: format!("Possible bug: expected {:?}, got {}", $rule, $pair),
recovered: None,
})
}
};
}
#[macro_export]
macro_rules! ast_expr {
($($item:ident)::+ { $($k:ident: $v:expr),* $(,)? }) => {{