diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-22 18:37:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-22 18:37:43 +0100 |
| commit | a9d943e2d93be0e741874cb1ef85488dacc6eeab (patch) | |
| tree | e6591f07da1455d170d5c20c1f49beeeefcd5bbd /src | |
| parent | 02bb836d9a9261b0ba9eb5ef6a9f02cc3605b672 (diff) | |
| parent | 7b2dd8497967bb2a78f7ff2055a4976a9bb2a4e5 (diff) | |
| download | sylt-a9d943e2d93be0e741874cb1ef85488dacc6eeab.tar.gz | |
Merge pull request #87 from FredTheDino/conflict-markers
Detect conflict markers
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler.rs | 12 | ||||
| -rw-r--r-- | src/error.rs | 42 | ||||
| -rw-r--r-- | src/lib.rs | 10 | ||||
| -rw-r--r-- | src/tokenizer.rs | 5 |
4 files changed, 51 insertions, 18 deletions
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 c2ad228..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)] @@ -67,9 +69,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 +82,32 @@ 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) + ErrorKind::GitConflictError(start_line, end_line) => { + write!(f, "Git conflict markers found between lines {} and {}", + start_line, end_line) } } } @@ -109,7 +115,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 +129,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) } } @@ -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)] + ); + } 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, |
