aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.rs12
-rw-r--r--src/error.rs42
-rw-r--r--src/lib.rs10
-rw-r--r--src/tokenizer.rs5
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)
}
}
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)]
+ );
+
}
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,