From 3b0e7f3edd977a62615c08c14764165bb28a90d0 Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Mon, 20 Nov 2023 09:41:07 +0100 Subject: [PATCH] implement raw token/typed repr debug printing --- src/args.rs | 2 ++ src/error/mod.rs | 3 +++ src/evaluator.rs | 28 ++++++++++++++++++++++++++-- src/main.rs | 4 ++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/args.rs b/src/args.rs index 1ac3ad2..6a0e72b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -6,4 +6,6 @@ pub struct Args { pub text: String, #[arg(long)] pub debug_tokens: bool, + #[arg(long)] + pub debug_typed_repr: bool, } diff --git a/src/error/mod.rs b/src/error/mod.rs index 62afd5d..1c20444 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -7,17 +7,20 @@ use codespan_reporting::{ use crate::Span; +#[derive(Debug)] pub struct Errors { pub kind: ErrorKind, pub locs: Vec, } +#[derive(Debug)] pub enum ErrorKind { InvalidToken, SyntaxError(SyntaxErrorKind), CommandNotFound, } +#[derive(Debug)] pub enum SyntaxErrorKind { /// `MissingStreamer` means, that the pipeline starts with a Pipe (`|`), so it has no streamer as input in front of it. MissingStreamer, diff --git a/src/evaluator.rs b/src/evaluator.rs index de55473..f1f6832 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -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>, + 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); diff --git a/src/main.rs b/src/main.rs index b7e6a77..fe63cf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use std::ops::Range; use args::Args; use clap::Parser; -use evaluator::Evaluator; +use evaluator::{EvalConfig, Evaluator}; mod args; mod builtins; @@ -21,7 +21,7 @@ type Span = Range; fn main() { let args = Args::parse(); - let mut evaluator = Evaluator::init(); + let mut evaluator = Evaluator::init(EvalConfig::new(args.debug_tokens, args.debug_typed_repr)); evaluator.run(args.text, None); evaluator.next();