start unifying error messages

This commit is contained in:
Sebastian Hugentobler 2025-05-25 10:55:50 +02:00
parent a25b6d1e92
commit 283155c38b
Signed by: shu
SSH key fingerprint: SHA256:ppcx6MlixdNZd5EUM1nkHOKoyQYoJwzuQKXM6J/t66M
2 changed files with 29 additions and 29 deletions

View file

@ -17,21 +17,21 @@ use crate::{
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum InterpreterError { pub enum InterpreterError {
#[error("[line {0}] MINUS unary expression expects a number on the right")] #[error("line {0}: MINUS unary expression expects a number on the right")]
UnaryExpressionNotANumber(usize), UnaryExpressionNotANumber(usize),
#[error("[line {0}] unknown unary operator: {1}")] #[error("line {0}: unknown unary operator: {1}")]
UnaryOperatorUnknown(usize, String), UnaryOperatorUnknown(usize, String),
#[error("[line {0}] unknown binary operator: {1}")] #[error("line {0}: unknown binary operator: {1}")]
BinaryOperatorUnknown(usize, String), BinaryOperatorUnknown(usize, String),
#[error("[line {0}] left or right is not a number.")] #[error("line {0}: left or right is not a number.")]
BinaryExpressionNeedsNumber(usize), BinaryExpressionNeedsNumber(usize),
#[error("[line {0}] left or right is neither a number nor string.")] #[error("line {0}: left or right is neither a number nor string.")]
BinaryExpressionNeedsNumberOrString(usize), BinaryExpressionNeedsNumberOrString(usize),
#[error("{0}")] #[error("{0}")]
UndefinedVariable(EnvironmentError), UndefinedVariable(EnvironmentError),
#[error("[line {0}] {1} is not callable.")] #[error("line {0}: {1} is not callable.")]
NotACallable(usize, Value), NotACallable(usize, Value),
#[error("[line {0}] {1}.")] #[error("line {0}: {1}.")]
FailedToCall(usize, CallingError), FailedToCall(usize, CallingError),
} }

View file

@ -13,49 +13,49 @@ use tracing::error;
pub enum ParserError { pub enum ParserError {
#[error("empty token stream")] #[error("empty token stream")]
NoTokens, NoTokens,
#[error("[line {0}] expected expression")] #[error("line {0}: expected expression")]
ExpressionExpected(usize), ExpressionExpected(usize),
#[error("[line {0}] expected ')' after expression.")] #[error("line {0}: expected ')' after expression.")]
ParenAfterExpression(usize), ParenAfterExpression(usize),
#[error("[Out of bounds access at index {0}.")] #[error("Out of bounds access at index {0}.")]
OutOfBoundsAccess(usize), OutOfBoundsAccess(usize),
#[error("[line {0}] literal expected.")] #[error("line {0}: literal expected.")]
LiteralExpected(usize), LiteralExpected(usize),
#[error("[line {0}] expected ';' after value.")] #[error("line {0}: expected ';' after value.")]
SemicolonAfterValueExpected(usize), SemicolonAfterValueExpected(usize),
#[error("[line {0}] expected ';' after expression.")] #[error("line {0}: expected ';' after expression.")]
SemicolonAfterExpressionExpected(usize), SemicolonAfterExpressionExpected(usize),
#[error("[line {0}] expected variable name.")] #[error("line {0}: expected variable name.")]
VariableNameExpected(usize), VariableNameExpected(usize),
#[error("[line {0}] invalid assignment target.")] #[error("line {0}: invalid assignment target.")]
InvalidAssignmentTarget(usize), InvalidAssignmentTarget(usize),
#[error("[line {0}] expected '}}' after block.")] #[error("line {0}: expected '}}' after block.")]
RightBraceAfterBlockExpected(usize), RightBraceAfterBlockExpected(usize),
#[error("[line {0}] expected '(' after if.")] #[error("line {0}: expected '(' after if.")]
LeftParenAfterIfExpected(usize), LeftParenAfterIfExpected(usize),
#[error("[line {0}] expected ')' after condition.")] #[error("line {0}: expected ')' after condition.")]
RightParenAfterConditionExpected(usize), RightParenAfterConditionExpected(usize),
#[error("[line {0}] expected '(' after while.")] #[error("line {0}: expected '(' after while.")]
LeftParenAfterWhileExpected(usize), LeftParenAfterWhileExpected(usize),
#[error("[line {0}] expected '(' after for.")] #[error("line {0}: expected '(' after for.")]
LeftParenAfterForExpected(usize), LeftParenAfterForExpected(usize),
#[error("[line {0}] expected ';' after loop condition.")] #[error("line {0}: expected ';' after loop condition.")]
SemicolonAfterLoopConditionExpected(usize), SemicolonAfterLoopConditionExpected(usize),
#[error("[line {0}] expected ')' after for clauses.")] #[error("line {0}: expected ')' after for clauses.")]
RightParenAfterForClausesExpected(usize), RightParenAfterForClausesExpected(usize),
#[error("[line {0}] expected ')' after arguments.")] #[error("line {0}: expected ')' after arguments.")]
RightParenAfterArgumentsExpected(usize), RightParenAfterArgumentsExpected(usize),
#[error("[line {0}] expected function name.")] #[error("line {0}: expected function name.")]
FunctionNameExpected(usize), FunctionNameExpected(usize),
#[error("[line {0}] expected '(' after function name.")] #[error("line {0}: expected '(' after function name.")]
LeftParenAfterFunctionNameExpected(usize), LeftParenAfterFunctionNameExpected(usize),
#[error("[line {0}] expected ')' after parameters.")] #[error("line {0}: expected ')' after parameters.")]
RightParenAfterParamsExpected(usize), RightParenAfterParamsExpected(usize),
#[error("[line {0}] expected parameter name.")] #[error("line {0}: expected parameter name.")]
ParamNameExpected(usize), ParamNameExpected(usize),
#[error("[line {0}] expected '{{' before function body.")] #[error("line {0}: expected '{{' before function body.")]
LeftBraceBeforeFunctionBodyExpected(usize), LeftBraceBeforeFunctionBodyExpected(usize),
#[error("[line {0}] expected ';' after return value.")] #[error("line {0}: expected ';' after return value.")]
SemicolonAfterReturnExpected(usize), SemicolonAfterReturnExpected(usize),
} }