implement raw token/typed repr debug printing
This commit is contained in:
parent
0a6d9a27c5
commit
3b0e7f3edd
4 changed files with 33 additions and 4 deletions
|
@ -6,4 +6,6 @@ pub struct Args {
|
|||
pub text: String,
|
||||
#[arg(long)]
|
||||
pub debug_tokens: bool,
|
||||
#[arg(long)]
|
||||
pub debug_typed_repr: bool,
|
||||
}
|
||||
|
|
|
@ -7,17 +7,20 @@ use codespan_reporting::{
|
|||
|
||||
use crate::Span;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Errors {
|
||||
pub kind: ErrorKind,
|
||||
pub locs: Vec<Span>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<usize>;
|
|||
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();
|
||||
|
|
Loading…
Reference in a new issue