about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/treewalk/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'users/tazjin/rlox/src/treewalk/errors.rs')
-rw-r--r--users/tazjin/rlox/src/treewalk/errors.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/treewalk/errors.rs b/users/tazjin/rlox/src/treewalk/errors.rs
index 54d2718eeda2..391663d51b18 100644
--- a/users/tazjin/rlox/src/treewalk/errors.rs
+++ b/users/tazjin/rlox/src/treewalk/errors.rs
@@ -1,4 +1,6 @@
+use crate::scanner::ScannerError;
 use crate::treewalk::interpreter::Value;
+
 use std::fmt;
 
 #[derive(Debug)]
@@ -39,3 +41,19 @@ impl fmt::Display for Error {
         write!(f, "[line {}] Error: {:?}", self.line, self.kind)
     }
 }
+
+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,
+            },
+        }
+    }
+}