From 36cf7bef24bbd5ffccc8bac47a8c4d10dd5a265c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 28 Nov 2020 18:20:10 +0100 Subject: refactor(tazjin/rlox): Thread through scanner errors ... and show them to users, very crudely. Change-Id: If4491b14db1124313f6ab7e5fbfdce9fea501d11 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2193 Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/tazjin/rlox/src/interpreter.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'users/tazjin/rlox/src/interpreter.rs') 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 = 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>) { + for token in tokens { println!("{:?}", token); } } + +fn report_errors(errors: Vec) { + for error in errors { + report(&error); + } +} -- cgit 1.4.1