added trait for output
Some checks are pending
Interp Tester / Check (push) Waiting to run
Interp Tester / Test Suite (push) Waiting to run
Interp Tester / Rustfmt (push) Waiting to run
Interp Tester / Clippy (push) Waiting to run
Interp Tester / build (push) Waiting to run

This commit is contained in:
hendrik 2024-09-06 15:37:54 +02:00
parent acca9b6f04
commit 9f6b12cd72
6 changed files with 737 additions and 47 deletions

32
Cargo.lock generated
View File

@ -4,15 +4,15 @@ version = 3
[[package]]
name = "anyhow"
version = "1.0.68"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "bytes"
version = "1.3.0"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]]
name = "interpreter-starter-rust"
@ -34,38 +34,38 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.36"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "1.0.48"
version = "2.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.38"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.38"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [
"proc-macro2",
"quote",
@ -77,9 +77,3 @@ name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"

View File

@ -47,3 +47,19 @@ pub trait ErrorProducer {
self.clear_errors()
}
}
pub trait ErrorPrinter {
fn flush_errors_to_std(&self);
fn flush_errors_to(&self, err:impl Write);
fn flush_errors_to_configured(&self, err: impl Write);
fn print_errors_to_std(&self);
fn print_errors_to(&self, err:impl Write);
fn print_errors_to_configured(&self, err: impl Write);
fn print_error_to_std(&self);
fn print_error_to(&self, err:impl Write);
fn print_error_to_configured(&self, err: impl Write);
}
//impl <T: ErrorProducer> ErrorPrinter for T {
//}

View File

@ -10,6 +10,7 @@ use crate::functions::callable::LoxFunction;
use crate::functions::handler::GlobalsHandler;
use crate::functions::traits::Callable;
use crate::output::config::print_ln;
use crate::output::handler::OutputPrinter;
use crate::statements;
use crate::statements::declaration::Declaration;
use crate::statements::expr::ExprStatement;
@ -63,24 +64,19 @@ impl Interpreter {
}
fn output(&mut self, output: String) {
//print_ln(&output);
// self.print_config(&output);
self.output.push(output);
}
fn output_all_th(&mut self) {
for s in &self.output {
print_ln(&s);
}
self.prints_config();
// tmp: rn each statement calles this fkt:
self.output = Vec::new()
}
fn output_all(&mut self, out: &mut impl std::io::Write) {
for s in &self.output {
let _ = writeln!(out, "{}", s);
}
self.prints_custom(out);
// tmp: rn each statement calles this fkt:
self.output = Vec::new()
}
@ -452,3 +448,9 @@ impl Interpreter {
Ok(())
}
}
impl OutputPrinter for Interpreter {
fn get_output(&self) -> &Vec<String> {
&self.output
}
}

View File

@ -1,25 +1,32 @@
use std::cell::RefCell;
use std::io::Write;
use std::sync::{Arc, Mutex};
use std::io::{self, Write};
pub struct CapturingOutputGen {
stdout: Arc<Mutex<Box<dyn Write + Send>>>,
stderr: Arc<Mutex<Box<dyn Write + Send>>>,
}
use super::config::print_ln;
impl CapturingOutputGen {
pub fn new(std: Box<dyn Write + Send>, str: Box<dyn Write + Send>) -> Self {
let stdout = Arc::new(Mutex::new(std as Box<dyn Write + Send>));
let stderr = Arc::new(Mutex::new(str as Box<dyn Write + Send>));
CapturingOutputGen { stdout, stderr }
pub trait OutputPrinter {
fn get_output(&self) -> &Vec<String>;
fn prints_std(&self){
for msg in self.get_output() {
self.print_std(msg);
}
}
pub fn get_stdout(&self) -> Arc<Mutex<Box<dyn Write + Send>>> {
self.stdout.clone()
fn prints_custom(&self, io: &mut impl Write) {
for msg in self.get_output() {
self.print_custom(msg, io);
}
}
pub fn get_stderr(&self) -> Arc<Mutex<Box<dyn Write + Send>>> {
self.stderr.clone()
fn print_std(&self, msg : &str) {
self.print_custom(msg,&mut io::stdout());
}
}
fn print_custom(&self, msg: &str, io: &mut impl Write) {
let _ = io.write_all(format!("{}\n",msg).as_bytes());
}
fn prints_config(&self) {
for msg in self.get_output() {
print_ln(msg);
}
}
fn print_config(&self, msg: &str) {
print_ln(msg);
}
}

View File

@ -1,4 +1,4 @@
pub mod capturer;
pub mod config;
pub mod handler;
mod writer;

671
tarpaulin-report.html Normal file

File diff suppressed because one or more lines are too long