refactor(tazjin/rlox): Prepare scanner for shared use
In the book, the clox interpreter has its own scanner which uses a pull-based model for a single pass compiler. I can't be bothered to write another scanner, or amend this one into pull-mode to work with the treewalk interpreter, so instead I will just reuse it and pull from a vector of tokens. The tokens are shared between both interpreters and the scanner is not what I'm interested in here. Change-Id: Ib07e89127fce2b047f9b3e1ff7e9908d798b3b2b Reviewed-on: https://cl.tvl.fyi/c/depot/+/2420 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
This commit is contained in:
parent
2d136e0327
commit
5868d4bd49
5 changed files with 35 additions and 12 deletions
|
|
@ -200,7 +200,9 @@ impl Lox for Interpreter {
|
|||
fn interpret(&mut self, code: String) -> Result<Value, Vec<Error>> {
|
||||
let chars: Vec<char> = code.chars().collect();
|
||||
|
||||
let mut program = scanner::scan(&chars).and_then(|tokens| parser::parse(tokens))?;
|
||||
let mut program = scanner::scan(&chars)
|
||||
.map_err(|errors| errors.into_iter().map(Into::into).collect())
|
||||
.and_then(|tokens| parser::parse(tokens))?;
|
||||
|
||||
let globals = self
|
||||
.env
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue