about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/interpreter.rs
diff options
context:
space:
mode:
Diffstat (limited to 'users/tazjin/rlox/src/interpreter.rs')
-rw-r--r--users/tazjin/rlox/src/interpreter.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/users/tazjin/rlox/src/interpreter.rs b/users/tazjin/rlox/src/interpreter.rs
index 8031329e7074..77f2492a46a2 100644
--- a/users/tazjin/rlox/src/interpreter.rs
+++ b/users/tazjin/rlox/src/interpreter.rs
@@ -1,9 +1,24 @@
-use crate::scanner;
+use crate::errors::{report, Error};
+use crate::scanner::{self, Token};
 
 // Run some Lox code and print it to stdout
 pub fn run(code: &str) {
     let chars: Vec<char> = code.chars().collect();
-    for token in scanner::scan(&chars) {
+
+    match scanner::scan(&chars) {
+        Ok(tokens) => print_tokens(tokens),
+        Err(errors) => report_errors(errors),
+    }
+}
+
+fn print_tokens<'a>(tokens: Vec<Token<'a>>) {
+    for token in tokens {
         println!("{:?}", token);
     }
 }
+
+fn report_errors(errors: Vec<Error>) {
+    for error in errors {
+        report(&error);
+    }
+}