about summary refs log tree commit diff
path: root/src/parse/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/macros.rs')
-rw-r--r--src/parse/macros.rs22
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(", ")
+    };
+}