From c7c7704b5d910b3ab0adf24722d1aae79b5e25e0 Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Fri, 27 Jan 2023 08:25:01 +0000 Subject: [PATCH] Proper printing --- src/basic.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/basic.rs b/src/basic.rs index 7a400ce..20da862 100644 --- a/src/basic.rs +++ b/src/basic.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, fmt::Display}; use nom::{bytes::complete::tag, multi::separated_list0, IResult}; @@ -22,6 +22,16 @@ pub enum Primitive { Assignment(String), } +impl Display for Primitive { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Primitive::Int(i) => write!(f, "{}", i), + Primitive::String(s) => write!(f, "{}", s), + Primitive::Assignment(a) => write!(f, "Assigment from {}", a), + } + } +} + #[derive(Debug, PartialEq, Eq, Clone)] pub enum PrintOutput { Value(String), @@ -96,7 +106,7 @@ impl Program { match item.1 { Command::Print(PrintOutput::Value(line)) => println!("{}", line), Command::Print(PrintOutput::Variable(variable)) => { - println!("{:?}", self.vars.get(&variable).unwrap()) + println!("{}", self.vars.get(&variable).unwrap()) } Command::GoTo(line) => iter.jump_to_line(line), Command::Var((id, Primitive::Assignment(variable))) => {