From c31a97eb761e8190902ca2ae980d7d7ea479f60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 15:26:34 +0100 Subject: [PATCH] Cargo features to control debugging output --- Cargo.toml | 5 +++++ src/main.rs | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 807258c..964eeea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,8 @@ edition = "2021" [dependencies] lazy_static = "1.4.0" + +[features] +debug_output = ["dump_tokens", "dump_ast"] +dump_tokens = [] +dump_ast = [] diff --git a/src/main.rs b/src/main.rs index 7ba4541..e100606 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use std::{ process::ExitCode, }; +#[cfg(feature = "dump_ast")] use ast::AstDumper; use errors::{ErrorHandler, ErrorType}; use interpreter::evaluate; @@ -24,6 +25,7 @@ fn run(source: String) -> ErrorHandler { let scanner = Scanner::new(source); let tokens = scanner.scan_tokens(&mut error_handler); + #[cfg(feature = "dump_tokens")] for token in tokens.iter() { println!("{:#?}", token); } @@ -32,10 +34,9 @@ fn run(source: String) -> ErrorHandler { match parser.parse(&mut error_handler) { None => (), Some(ast) => { + #[cfg(feature = "dump_ast")] println!("AST generated ! {}", ast.dump()); - if let Some(v) = evaluate(&mut error_handler, &ast) { - println!("Final evaluated value: {:?}", v) - } + evaluate(&mut error_handler, &ast); } }