diff options
| author | Mel <einebeere@gmail.com> | 2021-11-21 19:44:47 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2021-11-21 19:44:47 +0100 |
| commit | 4e9d846fbd51cec9e8d931c4aa3f399668ac316e (patch) | |
| tree | cda2e8645662b6c083add5ac87a279381eec054f /src/parse/macros.rs | |
| parent | abaa72af8a1be00f3f84d7771a7994bfbbccf719 (diff) | |
| download | rabbithole-4e9d846fbd51cec9e8d931c4aa3f399668ac316e.tar.zst rabbithole-4e9d846fbd51cec9e8d931c4aa3f399668ac316e.zip | |
Basic errors for parsing.
Diffstat (limited to 'src/parse/macros.rs')
| -rw-r--r-- | src/parse/macros.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/parse/macros.rs b/src/parse/macros.rs index 97e0104..9cf995c 100644 --- a/src/parse/macros.rs +++ b/src/parse/macros.rs @@ -16,15 +16,15 @@ macro_rules! consume { if let Token {kind: $( $kind )|+, ..} = token { Ok(token) } else { - Err(anyhow!( - // Make a better error message - "Received unexpected token: '{:?}'.", - token.kind - )) + Err(parser_error(ErrorLocation::Specific(token.location), ParserError::UnexpectedToken { + received: token.kind, + expected: merge_token_names!($($kind),+), + })) } } else { - // Here too - Err(anyhow!("Expected a token.")) + Err(parser_error(ErrorLocation::Eof, ParserError::UnexpectedEof { + expected: merge_token_names!($($kind),+), + })) } }; } @@ -49,3 +49,11 @@ macro_rules! inner { } }; } + +// TODO: Better names for the tokens. +#[macro_export] +macro_rules! merge_token_names { + ($($kind:pat_param),+) => { + vec![$( stringify!($kind) ),+].join(", ") + }; +} |
