Display as text
This commit is contained in:
parent
2b51bcff01
commit
80c9d47399
3 changed files with 61 additions and 1 deletions
|
|
@ -78,6 +78,26 @@ impl Node {
|
|||
pub fn modify_tree(&mut self) -> NodeModifier {
|
||||
NodeModifier::from_node(self, None)
|
||||
}
|
||||
pub fn as_text(&self) -> String {
|
||||
let mut children_text = "".to_string();
|
||||
if self.children.len() > 0 {
|
||||
for i in 0..self.children.len() {
|
||||
children_text += (&self.children[i]).as_text().as_str();
|
||||
if i < self.children.len() - 1 {
|
||||
children_text += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
match &self.handler {
|
||||
NodeHandler::Function {
|
||||
name,
|
||||
function,
|
||||
max_args,
|
||||
} => name.clone() + "(" + children_text.as_str() + ")",
|
||||
NodeHandler::Empty => children_text,
|
||||
_ => self.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Node {
|
||||
|
|
@ -93,7 +113,7 @@ impl fmt::Display for Node {
|
|||
max_args,
|
||||
} => name.clone(),
|
||||
NodeHandler::Variable => "X".to_string(),
|
||||
NodeHandler::Empty => "Empty".to_string(),
|
||||
NodeHandler::Empty => "".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue