mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-11-24 06:18:44 +01:00
implement raw token/typed repr debug printing
This commit is contained in:
parent
0a6d9a27c5
commit
3b0e7f3edd
|
@ -6,4 +6,6 @@ pub struct Args {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub debug_tokens: bool,
|
pub debug_tokens: bool,
|
||||||
|
#[arg(long)]
|
||||||
|
pub debug_typed_repr: bool,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,20 @@ use codespan_reporting::{
|
||||||
|
|
||||||
use crate::Span;
|
use crate::Span;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Errors {
|
pub struct Errors {
|
||||||
pub kind: ErrorKind,
|
pub kind: ErrorKind,
|
||||||
pub locs: Vec<Span>,
|
pub locs: Vec<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum ErrorKind {
|
pub enum ErrorKind {
|
||||||
InvalidToken,
|
InvalidToken,
|
||||||
SyntaxError(SyntaxErrorKind),
|
SyntaxError(SyntaxErrorKind),
|
||||||
CommandNotFound,
|
CommandNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum SyntaxErrorKind {
|
pub enum SyntaxErrorKind {
|
||||||
/// `MissingStreamer` means, that the pipeline starts with a Pipe (`|`), so it has no streamer as input in front of it.
|
/// `MissingStreamer` means, that the pipeline starts with a Pipe (`|`), so it has no streamer as input in front of it.
|
||||||
MissingStreamer,
|
MissingStreamer,
|
||||||
|
|
|
@ -19,21 +19,36 @@ use crate::{
|
||||||
typed::into_typed_repr,
|
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
|
// this is also bad
|
||||||
// need a better architecture for this
|
// need a better architecture for this
|
||||||
|
|
||||||
pub struct Evaluator<'a> {
|
pub struct Evaluator<'a> {
|
||||||
curr_phase: EvalPhase,
|
curr_phase: EvalPhase,
|
||||||
files: SimpleFiles<&'a str, String>,
|
files: SimpleFiles<&'a str, String>,
|
||||||
errors: HashMap<usize, Vec<Errors>>,
|
errors: HashMap<usize, Vec<Errors>>,
|
||||||
|
cfg: EvalConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Evaluator<'a> {
|
impl<'a> Evaluator<'a> {
|
||||||
pub fn init() -> Self {
|
pub fn init(cfg: EvalConfig) -> Self {
|
||||||
Self {
|
Self {
|
||||||
curr_phase: EvalPhase::Lex,
|
curr_phase: EvalPhase::Lex,
|
||||||
files: SimpleFiles::new(),
|
files: SimpleFiles::new(),
|
||||||
errors: HashMap::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 fid = self.files.add(name.unwrap_or("input"), input.clone());
|
||||||
|
|
||||||
let syntax = parse_syntax(&input);
|
let syntax = parse_syntax(&input);
|
||||||
|
if self.cfg.debug_raw_toks {
|
||||||
|
println!("Raw tokens: {syntax:#?}");
|
||||||
|
}
|
||||||
|
|
||||||
match syntax {
|
match syntax {
|
||||||
Ok(syntax) => self.curr_phase = EvalPhase::Check(fid, 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.errors.insert(file_id, vec![errs]);
|
||||||
self.curr_phase = EvalPhase::Failed;
|
self.curr_phase = EvalPhase::Failed;
|
||||||
} else {
|
} else {
|
||||||
|
if self.cfg.debug_print_typed_repr {
|
||||||
|
let typed = r.unwrap();
|
||||||
|
println!("Typed repr: {typed:#?}");
|
||||||
|
}
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +116,7 @@ impl<'a> Evaluator<'a> {
|
||||||
curr_phase,
|
curr_phase,
|
||||||
files,
|
files,
|
||||||
errors,
|
errors,
|
||||||
|
cfg,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let writer = StandardStream::stderr(ColorChoice::Always);
|
let writer = StandardStream::stderr(ColorChoice::Always);
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::ops::Range;
|
||||||
|
|
||||||
use args::Args;
|
use args::Args;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use evaluator::Evaluator;
|
use evaluator::{EvalConfig, Evaluator};
|
||||||
|
|
||||||
mod args;
|
mod args;
|
||||||
mod builtins;
|
mod builtins;
|
||||||
|
@ -21,7 +21,7 @@ type Span = Range<usize>;
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
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.run(args.text, None);
|
||||||
evaluator.next();
|
evaluator.next();
|
||||||
|
|
Loading…
Reference in a new issue