implement raw token/typed repr debug printing

This commit is contained in:
Schrottkatze 2023-11-20 09:41:07 +01:00
commit 3b0e7f3edd
4 changed files with 33 additions and 4 deletions

View file

@ -19,21 +19,36 @@ use crate::{
typed::into_typed_repr,
};
pub struct EvalConfig {
debug_raw_toks: bool,
debug_print_typed_repr: bool,
}
impl EvalConfig {
pub fn new(debug_raw_toks: bool, debug_print_typed_repr: bool) -> Self {
Self {
debug_raw_toks,
debug_print_typed_repr,
}
}
}
// this is also bad
// need a better architecture for this
pub struct Evaluator<'a> {
curr_phase: EvalPhase,
files: SimpleFiles<&'a str, String>,
errors: HashMap<usize, Vec<Errors>>,
cfg: EvalConfig,
}
impl<'a> Evaluator<'a> {
pub fn init() -> Self {
pub fn init(cfg: EvalConfig) -> Self {
Self {
curr_phase: EvalPhase::Lex,
files: SimpleFiles::new(),
errors: HashMap::new(),
cfg,
}
}
@ -41,6 +56,9 @@ impl<'a> Evaluator<'a> {
let fid = self.files.add(name.unwrap_or("input"), input.clone());
let syntax = parse_syntax(&input);
if self.cfg.debug_raw_toks {
println!("Raw tokens: {syntax:#?}");
}
match syntax {
Ok(syntax) => self.curr_phase = EvalPhase::Check(fid, syntax),
@ -80,6 +98,11 @@ impl<'a> Evaluator<'a> {
self.errors.insert(file_id, vec![errs]);
self.curr_phase = EvalPhase::Failed;
} else {
if self.cfg.debug_print_typed_repr {
let typed = r.unwrap();
println!("Typed repr: {typed:#?}");
}
todo!()
}
}
@ -93,6 +116,7 @@ impl<'a> Evaluator<'a> {
curr_phase,
files,
errors,
cfg,
} = self;
let writer = StandardStream::stderr(ColorChoice::Always);