mirror of
https://github.com/rm-dr/daisy
synced 2025-07-01 06:33:34 -07:00
Reorganized code, added basic error handling
This commit is contained in:
24
src/main.rs
24
src/main.rs
@ -4,6 +4,8 @@ use std::io::Write;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
|
||||
|
||||
use termcolor::{
|
||||
Color,
|
||||
ColorChoice,
|
||||
@ -13,6 +15,9 @@ use termcolor::{
|
||||
};
|
||||
|
||||
mod parser;
|
||||
use crate::parser::Token;
|
||||
//use crate::parser::ParserError;
|
||||
use crate::parser::LineLocation;
|
||||
|
||||
const PROMPT_PREFIX: &str = "==> ";
|
||||
|
||||
@ -77,23 +82,26 @@ fn main() -> Result<(), std::io::Error> {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tokenize input.
|
||||
// Parse input.
|
||||
// Fail if we encounter invalid characters.
|
||||
let mut g = match parser::tokenize::tokenize(&input) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
let g: Token = match parser::parse(&input) {
|
||||
Ok(g) => g,
|
||||
Err((l, e)) => {
|
||||
let LineLocation{pos, len} = l;
|
||||
|
||||
let s = " ";
|
||||
let m = "^";
|
||||
println!("{}{} {:?}", s.repeat(pos + 4), m.repeat(len), e);
|
||||
stdout.flush()?;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
|
||||
write!(stdout, "\n => ")?;
|
||||
stdout.reset()?;
|
||||
write!(stdout, "Got {input}\n\n\n")?;
|
||||
|
||||
parser::parse(&mut g).expect("Could not parse");
|
||||
|
||||
|
||||
writeln!(stdout, "Tokenized: {g:#?}")?;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user