feat: report errors in macro definition

Reporting macro *definition* error at the macro *call site* is a rather
questionable approach, but at least we don't erase the errors
altogether!
This commit is contained in:
Aleksey Kladov 2021-10-09 15:23:55 +03:00
parent b3d1de93af
commit ef1251f696
10 changed files with 121 additions and 95 deletions

View file

@ -30,7 +30,7 @@ use crate::{
pub use ::parser::ParserEntryPoint;
pub use tt::{Delimiter, DelimiterKind, Punct};
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ParseError {
UnexpectedToken(String),
Expected(String),
@ -38,6 +38,17 @@ pub enum ParseError {
RepetitionEmptyTokenTree,
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ParseError::UnexpectedToken(it) => f.write_str(it),
ParseError::Expected(it) => f.write_str(it),
ParseError::InvalidRepeat => f.write_str("invalid repeat"),
ParseError::RepetitionEmptyTokenTree => f.write_str("empty token tree in repetition"),
}
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ExpandError {
NoMatchingRule,