blob: 8a4d5cfef0df0a1bc881a1771656c8e69731e073 (
plain) (
tree)
|
|
use crate::errors::{report, Error};
use crate::parser;
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();
match scanner::scan(&chars) {
Ok(tokens) => {
print_tokens(&tokens);
match parser::parse(tokens) {
Ok(expr) => println!("Expression:\n{:?}", expr),
Err(error) => report_errors(vec![error]),
}
}
Err(errors) => report_errors(errors),
}
}
fn print_tokens<'a>(tokens: &Vec<Token<'a>>) {
println!("Tokens:");
for token in tokens {
println!("{:?}", token);
}
}
fn report_errors(errors: Vec<Error>) {
for error in errors {
report(&error);
}
}
|