From 51a407030574e44266b2c841748324ca19474698 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 13 Jun 2024 15:24:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20(parser):=20Improve=20error=20me?= =?UTF-8?q?ssages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit semver: patch --- src/parser/expression.rs | 2 +- src/parser/typing.rs | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/parser/expression.rs b/src/parser/expression.rs index 21a2348..61decee 100644 --- a/src/parser/expression.rs +++ b/src/parser/expression.rs @@ -26,7 +26,7 @@ pub fn parse( .ok_or(Diagnostic::error( cursor, range.length, - format!("Cannot create an expression from {}", token.token_type), + "Expected a new expression", ))?; let (mut left_hand_side, new_cursor) = expression_handler(parser, cursor)?; diff --git a/src/parser/typing.rs b/src/parser/typing.rs index abc5620..f42219d 100644 --- a/src/parser/typing.rs +++ b/src/parser/typing.rs @@ -15,16 +15,11 @@ pub fn parse( ) -> Result<(Type, usize), Diagnostic> { let mut cursor = cursor; let (token, range) = expect_valid_token!(parser, cursor); - let type_handler = - parser - .lookup - .type_lookup - .get(&token.token_type) - .ok_or(Diagnostic::error( - cursor, - range.length, - format!("Cannot create a type from {}", token.token_type), - ))?; + let type_handler = parser + .lookup + .type_lookup + .get(&token.token_type) + .ok_or(Diagnostic::error(cursor, range.length, "Expected a type"))?; let (mut left_hand_side, new_cursor) = type_handler(parser, cursor)?;