mirror of https://github.com/rm-dr/daisy
Prettier output
parent
1f98645dd4
commit
0927cf25e4
22
src/main.rs
22
src/main.rs
|
@ -6,15 +6,15 @@ use termion::raw::RawTerminal;
|
||||||
use termion::{color, style};
|
use termion::{color, style};
|
||||||
|
|
||||||
mod parser;
|
mod parser;
|
||||||
//use crate::parser::Token;
|
use crate::parser::Token;
|
||||||
//use crate::parser::ParserError;
|
//use crate::parser::ParserError;
|
||||||
use crate::parser::LineLocation;
|
use crate::parser::LineLocation;
|
||||||
|
use crate::parser::Eval;
|
||||||
|
|
||||||
|
|
||||||
fn draw_line(stdout: &mut RawTerminal<std::io::Stdout>, s: &String) -> Result<(), std::io::Error> {
|
fn draw_line(stdout: &mut RawTerminal<std::io::Stdout>, s: &String) -> Result<(), std::io::Error> {
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout, "\r{}{}==>{}{} {s} {}",
|
||||||
"\r{}{}==>{}{} {s} {}",
|
|
||||||
style::Bold,
|
style::Bold,
|
||||||
color::Fg(color::Blue),
|
color::Fg(color::Blue),
|
||||||
color::Fg(color::Reset),
|
color::Fg(color::Reset),
|
||||||
|
@ -57,15 +57,21 @@ fn main() -> Result<(), std::io::Error> {
|
||||||
|
|
||||||
match g {
|
match g {
|
||||||
Ok(g) => {
|
Ok(g) => {
|
||||||
RawTerminal::suspend_raw_mode(&stdout)?;
|
let n = g.eval();
|
||||||
writeln!(stdout, "Tokenized: {g:#?}")?;
|
if let Token::Number(_, v) = n {
|
||||||
RawTerminal::activate_raw_mode(&stdout)?;
|
write!(
|
||||||
|
stdout, "\r\n {}{}={} {v}{}\r\n\n",
|
||||||
|
style::Bold,
|
||||||
|
color::Fg(color::Green),
|
||||||
|
style::Reset,
|
||||||
|
color::Fg(color::Reset)
|
||||||
|
)?;
|
||||||
|
} else { panic!(); }
|
||||||
},
|
},
|
||||||
Err((l, e)) => {
|
Err((l, e)) => {
|
||||||
let LineLocation{pos, len} = l;
|
let LineLocation{pos, len} = l;
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout, "{}{}{} {e:?}{}\r\n",
|
||||||
"{}{}{} {e:?}{}\r\n",
|
|
||||||
color::Fg(color::Red),
|
color::Fg(color::Red),
|
||||||
" ".repeat(pos + 4),
|
" ".repeat(pos + 4),
|
||||||
"^".repeat(len),
|
"^".repeat(len),
|
||||||
|
|
|
@ -51,6 +51,14 @@ pub enum Token {
|
||||||
impl Eval for Token {
|
impl Eval for Token {
|
||||||
fn eval(&self) -> Token {
|
fn eval(&self) -> Token {
|
||||||
match self {
|
match self {
|
||||||
|
Token::Root(ref v) => {
|
||||||
|
if v.len() != 1 {panic!()};
|
||||||
|
|
||||||
|
if let Token::Number(l, v) = v[0] {
|
||||||
|
Token::Number(l, v)
|
||||||
|
} else { panic!(); }
|
||||||
|
},
|
||||||
|
|
||||||
Token::Negative(ref v) => {
|
Token::Negative(ref v) => {
|
||||||
if v.len() != 1 {panic!()};
|
if v.len() != 1 {panic!()};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue