expr_solver/ast.rs
1use crate::token::Token;
2
3/// Enum for modeling AST nodes.
4pub enum AST {
5 // each node.
6 Node(Token),
7 // connections.
8 Con(Token, Vec<AST>),
9}
10
11/// fmt display for ast
12/// recursively prints AST.
13impl core::fmt::Display for AST {
14 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
15 match self {
16 AST::Node(token) => write!(f, " {}", token),
17 AST::Con(head, rest) => {
18 write!(f, "({}", head)?;
19 for node in rest {
20 write!(f, "{}", node)?;
21 }
22
23 write!(f, ")")
24 }
25 }
26 }
27}