diff options
author | Vincent Ambo <mail@tazj.in> | 2020-12-06T14·49+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-12-06T14·58+0000 |
commit | 1835b2be990f51f4111c847aa8ad3c8477191eba (patch) | |
tree | 7a8a6af22267f427f59a3accd8a075a56dada11b /users/tazjin/rlox/src/interpreter.rs | |
parent | 4812fc2ee64536502093da04ea8a0efe616ffb26 (diff) |
feat(tazjin/rlox): Wire up parser to the REPL r/1990
Change-Id: I940448c63ce105d53a0f281b6320ffb01378f207 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2235 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.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/users/tazjin/rlox/src/interpreter.rs b/users/tazjin/rlox/src/interpreter.rs index 77f2492a46a2..8a4d5cfef0df 100644 --- a/users/tazjin/rlox/src/interpreter.rs +++ b/users/tazjin/rlox/src/interpreter.rs @@ -1,4 +1,5 @@ use crate::errors::{report, Error}; +use crate::parser; use crate::scanner::{self, Token}; // Run some Lox code and print it to stdout @@ -6,12 +7,19 @@ pub fn run(code: &str) { let chars: Vec<char> = code.chars().collect(); match scanner::scan(&chars) { - Ok(tokens) => print_tokens(tokens), + 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>>) { +fn print_tokens<'a>(tokens: &Vec<Token<'a>>) { + println!("Tokens:"); for token in tokens { println!("{:?}", token); } |