From 46c6906aaa4ca0fa16a1fbbcc5993d621d2fb7a7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 27 Nov 2020 18:16:42 +0100 Subject: chore(tazjin/rlox): Wire scanner to interpreter to reduce warnings ... they're just noisy at the moment. This isn't complete because it doesn't thread through scanner errors. Change-Id: I0f75d2b20fa3f57be1af5d1d8aa8059856855825 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2162 Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/tazjin/rlox/src/interpreter.rs | 6 +++++- users/tazjin/rlox/src/scanner.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'users/tazjin') diff --git a/users/tazjin/rlox/src/interpreter.rs b/users/tazjin/rlox/src/interpreter.rs index 6a7687c2685e..2aff971f09a5 100644 --- a/users/tazjin/rlox/src/interpreter.rs +++ b/users/tazjin/rlox/src/interpreter.rs @@ -1,4 +1,8 @@ +use crate::scanner; + // Run some Lox code and print it to stdout -pub fn run(_code: &str) { +pub fn run(code: &str) { + let chars: Vec = code.chars().collect(); + let _tokens = scanner::scan(&chars); println!("no interpreter yet, sorry") } diff --git a/users/tazjin/rlox/src/scanner.rs b/users/tazjin/rlox/src/scanner.rs index 659f280de72b..edd85496a73e 100644 --- a/users/tazjin/rlox/src/scanner.rs +++ b/users/tazjin/rlox/src/scanner.rs @@ -133,3 +133,16 @@ impl<'a> Scanner<'a> { return self.tokens; } } + +pub fn scan<'a>(input: &'a [char]) -> Vec> { + let scanner = Scanner { + source: &input, + tokens: vec![], + errors: vec![], + start: 0, + current: 0, + line: 0, + }; + + return scanner.scan_tokens(); +} -- cgit 1.4.1