aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-02-26 17:50:53 +0100
committerGitHub <noreply@github.com>2021-02-26 17:50:53 +0100
commit21b70835bfbc6b8a9c1099bb4a618f1cd457aac0 (patch)
tree58d3a61762c85e4165af1dbd2dbafa6efdec6e9c /src
parent701c38433454d5afd833bb94723ab2e1f4bbe9bd (diff)
parentcab32da3a8f4b4e25e1d1f287315fe75256ecc89 (diff)
downloadsylt-21b70835bfbc6b8a9c1099bb4a618f1cd457aac0.tar.gz
Merge branch 'compiler-rewrite' into breaking-into-sections
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/main.rs2
-rw-r--r--src/tokenizer.rs5
5 files changed, 52 insertions, 19 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index aa491e6..2244198 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -543,6 +543,18 @@ impl<'a> Compiler<'a> {
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 06df162..4fc02a4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1369,4 +1369,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/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,
};
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,