Skip to content

Commit

Permalink
create function to print with name
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-extracts committed Nov 28, 2024
1 parent 3b83a10 commit 1bd1462
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn main() {
if result != Parameters::Null {
println!(
"{}",
result.pretty_print(Some(&mut ram), Some(&mut functions))
result.argument_print(Some(&mut ram), Some(&mut functions))
)
}
exit(0);
Expand Down Expand Up @@ -426,7 +426,7 @@ fn main() {
if result != Parameters::Null {
println!(
"{}",
result.pretty_print(Some(&mut ram), Some(&mut functions))
result.argument_print(Some(&mut ram), Some(&mut functions))
)
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/parsing/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,35 @@ impl Parameters {
_ => format!("{self}"),
}
}
pub fn argument_print(
&self,
ram: Option<&mut HashMap<String, Parameters>>,
function: Option<&mut HashMap<String, (Vec<Ast>, Ast)>>,
) -> String {
match self.clone() {
Int(_) => format!("val = int: {}", self.pretty_print(ram, function)),
Float(_) => format!("val = float: {}", self.pretty_print(ram, function)),
Identifier(s) => {
if s.starts_with("@") {
self.pretty_print(ram, function)
} else {
format!("val = ident: {}", self.pretty_print(ram, function))
}
}
Rational(_) => format!("val = rational: {}", self.pretty_print(ram, function)),
Bool(_) => format!("val = bool: {}", self.pretty_print(ram, function)),
InterpreterVector(_) => {
format!("val = matrix: \n{}", self.pretty_print(ram, function))
}
Var(_, _, _) => {
format!("val = var: {}", self.pretty_print(ram, function))
}
Plus(_, _) | Mul(_, _) | Div(_, _) => {
format!("val = op: {}", self.pretty_print(ram, function))
}
_ => self.pretty_print(ram, function),
}
}
}

pub fn token_to_parameter(token: Token) -> Parameters {
Expand Down

0 comments on commit 1bd1462

Please sign in to comment.