about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/errors.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-11-23T01·00+0100
committertazjin <mail@tazj.in>2020-11-23T01·15+0000
commit3d1b116f7fdcdd7af77a4abc7dbedef4df8fd0a4 (patch)
treef0f0aa71e199da39daefe3f218b4d619fe56238f /users/tazjin/rlox/src/errors.rs
parent9d2b001c4cc86cc57bdb890037c80b7a1c766ecd (diff)
feat(tazjin/rlox): Implement single-character scanning r/1914
... still not that interesting, but at this point slightly divergent
from the book:

The book embraces mutability for interpreter state, initially for
tracking whether an error condition has occured.

I avoid this by instead defining an error type and collecting the
error values, to be handled later on.

Notes: So far nothing special, but this is just the beginning of the
book. I like the style it is written in and it has pointed to some
interesting resources, such as a 1965 paper titled "The Next 700
Languages".

Change-Id: I030b38438fec9eb55372bf547af225138908230a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2144
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/errors.rs')
-rw-r--r--users/tazjin/rlox/src/errors.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/errors.rs b/users/tazjin/rlox/src/errors.rs
new file mode 100644
index 0000000000..46c739ef2f
--- /dev/null
+++ b/users/tazjin/rlox/src/errors.rs
@@ -0,0 +1,14 @@
+#[derive(Debug)]
+pub enum ErrorKind {
+    UnexpectedChar(char),
+}
+
+#[derive(Debug)]
+pub struct Error {
+    pub line: usize,
+    pub kind: ErrorKind,
+}
+
+pub fn report(loc: &str, err: &Error) {
+    eprintln!("[line {}] Error {}: {:?}", err.line, loc, err.kind);
+}