Pretty-print evaluated AST nodes
This commit is contained in:
parent
ce8c511929
commit
be36d4697d
@ -73,7 +73,7 @@ impl Evaluator {
|
||||
}
|
||||
}
|
||||
|
||||
format!("{:?}", node) //TODO make better
|
||||
format!("{}", node) //TODO make better
|
||||
}
|
||||
|
||||
fn step(&mut self, node: ASTNode) -> ASTNode {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::fmt;
|
||||
use tokenizer::{Token, Kw, Op};
|
||||
|
||||
/* Grammar
|
||||
@ -45,6 +46,28 @@ pub enum Expression {
|
||||
Call(String, Vec<Expression>),
|
||||
}
|
||||
|
||||
impl fmt::Display for ASTNode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::ASTNode::*;
|
||||
match self {
|
||||
&ExprNode(ref expr) => write!(f, "{}", expr),
|
||||
&FuncNode(_) => write!(f, "UNIMPLEMENTED"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Expression {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Expression::*;
|
||||
match self {
|
||||
&Null => write!(f, "null"),
|
||||
&StringLiteral(ref s) => write!(f, "\"{}\"", s),
|
||||
&Number(n) => write!(f, "{}", n),
|
||||
_ => write!(f, "UNIMPLEMENTED"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type AST = Vec<ASTNode>;
|
||||
|
||||
type Precedence = u8;
|
||||
|
Loading…
Reference in New Issue
Block a user