about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode
diff options
context:
space:
mode:
Diffstat (limited to 'users/tazjin/rlox/src/bytecode')
-rw-r--r--users/tazjin/rlox/src/bytecode/errors.rs23
-rw-r--r--users/tazjin/rlox/src/bytecode/mod.rs2
2 files changed, 22 insertions, 3 deletions
diff --git a/users/tazjin/rlox/src/bytecode/errors.rs b/users/tazjin/rlox/src/bytecode/errors.rs
index c7871bc384f2..513708df7e85 100644
--- a/users/tazjin/rlox/src/bytecode/errors.rs
+++ b/users/tazjin/rlox/src/bytecode/errors.rs
@@ -1,15 +1,18 @@
+use crate::scanner::ScannerError;
+
 use std::fmt;
 
 #[derive(Debug)]
 pub enum ErrorKind {
-    // CompileError,
-    // RuntimeError,
+    UnexpectedChar(char),
+    UnterminatedString,
     InternalError(&'static str),
 }
 
 #[derive(Debug)]
 pub struct Error {
     pub kind: ErrorKind,
+    pub line: usize,
 }
 
 impl fmt::Display for Error {
@@ -18,4 +21,20 @@ impl fmt::Display for Error {
     }
 }
 
+impl From<ScannerError> for Error {
+    fn from(err: ScannerError) -> Self {
+        match err {
+            ScannerError::UnexpectedChar { line, unexpected } => Error {
+                line,
+                kind: ErrorKind::UnexpectedChar(unexpected),
+            },
+
+            ScannerError::UnterminatedString { line } => Error {
+                line,
+                kind: ErrorKind::UnterminatedString,
+            },
+        }
+    }
+}
+
 pub type LoxResult<T> = Result<T, Error>;
diff --git a/users/tazjin/rlox/src/bytecode/mod.rs b/users/tazjin/rlox/src/bytecode/mod.rs
index 31278f8c4b8d..34ceaf28bfa4 100644
--- a/users/tazjin/rlox/src/bytecode/mod.rs
+++ b/users/tazjin/rlox/src/bytecode/mod.rs
@@ -19,7 +19,7 @@ impl crate::Lox for Interpreter {
         Interpreter {}
     }
 
-    fn interpret(&mut self, _: String) -> Result<Self::Value, Vec<Self::Error>> {
+    fn interpret(&mut self, code: String) -> Result<Self::Value, Vec<Self::Error>> {
         let chunk: Chunk = Default::default();
         vm::interpret(chunk).map_err(|e| vec![e])
     }