From 5449818b0975341e03720a450eec877453dee7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 22 Feb 2021 11:39:42 +0100 Subject: Squash-merge remote tracking branch 'origin/automatic-link' --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index bc68d40..28e4e79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ struct Args { fn main() { let args = parse_args(); let file = args.file.unwrap_or_else(|| Path::new("progs/tests/simple.sy").to_owned()); - let errs = match run_file(&file, args.print, vec![(String::from("extern_test"), extern_test)]) { + let errs = match run_file(&file, args.print, sylt_macro::link!(extern_test as test)) { Err(it) => it, _ => return, }; -- cgit v1.2.1 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') 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') 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/compiler.rs | 12 ++++++++++++ src/error.rs | 5 +++++ src/tokenizer.rs | 5 +++++ 3 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/compiler.rs b/src/compiler.rs index cd4ffda..124606e 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -473,6 +473,18 @@ impl Compiler { fn eat(&mut self) -> Token { let t = self.peek(); self.curr += 1; + match t { + Token::GitConflictBegin => { + self.curr -= 1; + let start = self.line(); + self.curr += 1; + while !matches!(self.eat(), Token::GitConflictEnd) {} + self.panic = false; + self.error_on_line(ErrorKind::GitConflictError(start, self.line()), start, None); + self.panic = true; + } + _ => {} + } t } 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) } } } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index b54e194..2c8e5e8 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -127,6 +127,11 @@ pub enum Token { #[token("\n")] Newline, + #[token("<<<<<<<")] + GitConflictBegin, + #[token(">>>>>>>")] + GitConflictEnd, + #[regex(r"//[^\n]*", logos::skip)] Comment, -- cgit v1.2.1 From 7b2dd8497967bb2a78f7ff2055a4976a9bb2a4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 22 Feb 2021 18:35:26 +0100 Subject: add conflict marker test --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 91938f1..858c88f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1367,4 +1367,14 @@ q <=> 3 ); + test_string!(conflict_markers, " +<<<<<<< HEAD +print extern_test(4.0) +======= +print extern_test(5.0) +>>>>>>> 2 +", + [ErrorKind::SyntaxError(_, _), ErrorKind::GitConflictError(2, 6)] + ); + } -- cgit v1.2.1