about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/interpreter.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-11-28T17·20+0100
committertazjin <mail@tazj.in>2020-11-28T17·26+0000
commit36cf7bef24bbd5ffccc8bac47a8c4d10dd5a265c (patch)
treeccec3463fde0fc088f575d534745a1648844578e /users/tazjin/rlox/src/interpreter.rs
parentaf793325c03d88add6efbcc9425a3db488f2cff9 (diff)
refactor(tazjin/rlox): Thread through scanner errors r/1956
... and show them to users, very crudely.

Change-Id: If4491b14db1124313f6ab7e5fbfdce9fea501d11
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2193
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
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);
+    }
+}