From b7e163bbabc0d361f6c17aa35fc3af1c74586355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 22 Feb 2021 17:52:57 +0100 Subject: polish error message output --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index c2ad228..dbcdbdb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -109,7 +109,7 @@ impl fmt::Display for ErrorKind { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let prompt = "*****".red(); + let prompt = " "; let message = match &self.message { Some(s) => format!("\n{} {}", prompt, s), None => String::from(""), @@ -123,7 +123,7 @@ impl fmt::Display for Error { String::new() }; - write!(f, "\n {} {}:{} \n{} {}{}{}\n", "ERR".red(), + write!(f, "{} {}:{}\n{} {}{}{}", "ERROR".red(), self.file.display().blue(), self.line.blue(), prompt, self.kind, message, line) } } -- cgit v1.2.1 From 12b2c5a161a2922ec86ef003e626ffb78b8f60ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 22 Feb 2021 18:10:45 +0100 Subject: reorder errors to match declaration --- src/error.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index dbcdbdb..74f5af3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -67,9 +67,8 @@ impl fmt::Display for ErrorKind { write!(f, "Argument types do not match, expected [{:?}] but got [{:?}]", expected, given) } - ErrorKind::IndexOutOfBounds(value, len, slot) => { - write!(f, "Failed to index for {:?} - length is {} but index is {}", - value, len, slot) + ErrorKind::IndexError(value, slot) => { + write!(f, "Cannot index value '{:?}' with type '{:?}'.", value, slot) } ErrorKind::ExternTypeMismatch(name, types) => { write!(f, "Extern function '{}' doesn't accept argument(s) with type(s) {:?}", @@ -81,27 +80,29 @@ impl fmt::Display for ErrorKind { .fold(String::new(), |a, v| { format!("{}{:?}, ", a, v) }); write!(f, "Cannot apply {:?} to values {}", op, values) } - ErrorKind::AssertFailed => { - write!(f, "Assertion failed") + ErrorKind::UnknownField(obj, field) => { + write!(f, "Cannot find field '{}' on {:?}", field, obj) } - ErrorKind::SyntaxError(line, token) => { - write!(f, "Syntax Error on line {} at token {:?}", line, token) + ErrorKind::ArgumentCount(expected, given) => { + write!(f, "Incorrect argument count, expected {} but got {}.", + expected, given) } - ErrorKind::Unreachable => { - write!(f, "Reached unreachable code.") + ErrorKind::IndexOutOfBounds(value, len, slot) => { + write!(f, "Failed to index for {:?} - length is {} but index is {}", + value, len, slot) + } + ErrorKind::AssertFailed => { + write!(f, "Assertion failed") } ErrorKind::InvalidProgram => { write!(f, "{}", "[!!] Invalid program [!!]".bold()) } - ErrorKind::IndexError(value, slot) => { - write!(f, "Cannot index value '{:?}' with type '{:?}'.", value, slot) + ErrorKind::Unreachable => { + write!(f, "Reached unreachable code.") } - ErrorKind::UnknownField(obj, field) => { - write!(f, "Cannot find field '{}' on {:?}", field, obj) + ErrorKind::SyntaxError(line, token) => { + write!(f, "Syntax Error on line {} at token {:?}", line, token) } - ErrorKind::ArgumentCount(expected, given) => { - write!(f, "Incorrect argument count, expected {} but got {}.", - expected, given) } } } -- cgit v1.2.1 From 0d1d548032420c0e7daccfe14bc2fed18775d797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 22 Feb 2021 18:11:50 +0100 Subject: tokenize and report git conflict markers --- src/error.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index 74f5af3..9aca985 100644 --- a/src/error.rs +++ b/src/error.rs @@ -32,6 +32,8 @@ pub enum ErrorKind { /// (line, token) SyntaxError(usize, Token), + /// (start, end) + GitConflictError(usize, usize), } #[derive(Debug, Clone)] @@ -103,6 +105,9 @@ impl fmt::Display for ErrorKind { ErrorKind::SyntaxError(line, token) => { write!(f, "Syntax Error on line {} at token {:?}", line, token) } + ErrorKind::GitConflictError(start_line, end_line) => { + write!(f, "Git conflict markers found between lines {} and {}", + start_line, end_line) } } } -- cgit v1.2.1