diff --git a/src/component_layout.rs b/src/component_layout.rs index 7d18d07a..5f37b85a 100644 --- a/src/component_layout.rs +++ b/src/component_layout.rs @@ -1,6 +1,6 @@ use std::fs; use std::io; -use crate::parsed_layout_node::*; +use crate::layout_parsed_node::*; pub struct ComponentLayout { @@ -9,19 +9,17 @@ pub struct ComponentLayout { impl ComponentLayout { pub fn new() -> ComponentLayout { let parsed_layout_tree = Self::parse_xml_file("gui/window/main.xml").unwrap(); - for node in parsed_layout_tree.descendants() { - println!("{:?}", node); - } + Self::interpret_abstract_syntax_tree(parsed_layout_tree); Self {} } - pub fn parse_xml_file(path: &str) -> io::Result> { + pub fn parse_xml_file(path: &str) -> io::Result> { let source = fs::read_to_string(path)?; let parsed = xmlparser::Tokenizer::from(&source[..]); - let mut stack: Vec> = Vec::new(); - let mut current: Option> = None; - let mut result: Option> = None; + let mut stack: Vec> = Vec::new(); + let mut current: Option> = None; + let mut result: Option> = None; for token in parsed { match token.unwrap() { @@ -29,7 +27,7 @@ impl ComponentLayout { let namespace = String::from(prefix.as_str()); let tag_name = String::from(local.as_str()); - let new_parsed_layout_node = ParsedLayoutNode::new_tag(namespace, tag_name); + let new_parsed_layout_node = LayoutParsedNode::new_tag(namespace, tag_name); let new_node = rctree::Node::new(new_parsed_layout_node); current = Some(new_node); @@ -49,11 +47,11 @@ impl ComponentLayout { match &mut current { Some(current_node) => { match &mut *current_node.borrow_mut() { - ParsedLayoutNode::Tag(tag) => { + LayoutParsedNode::Tag(tag) => { // Add this attribute to the current node that has not yet reached its closing angle bracket tag.add_attribute(attribute); } - ParsedLayoutNode::Text(_) => { + LayoutParsedNode::Text(_) => { panic!("Error adding attribute to tag when parsing XML layout in file: {}", path); } } @@ -99,7 +97,7 @@ impl ComponentLayout { let text_string = String::from(text.as_str()); if !text_string.trim().is_empty() { - let text_node = ParsedLayoutNode::new_text(text_string); + let text_node = LayoutParsedNode::new_text(text_string); let new_node = rctree::Node::new(text_node); parent_node.append(new_node); } @@ -113,4 +111,10 @@ impl ComponentLayout { Some(tree) => Ok(tree) } } + + pub fn interpret_abstract_syntax_tree(root: rctree::Node) { + for node in root.descendants() { + println!("{:?}", node); + } + } } \ No newline at end of file diff --git a/src/layout_abstract_syntax.rs b/src/layout_abstract_syntax.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/parsed_layout_node.rs b/src/layout_parsed_node.rs similarity index 76% rename from src/parsed_layout_node.rs rename to src/layout_parsed_node.rs index 6110f36e..0db4fa51 100644 --- a/src/parsed_layout_node.rs +++ b/src/layout_parsed_node.rs @@ -1,12 +1,12 @@ #[derive(Debug)] -pub enum ParsedLayoutNode { - Tag(ParsedLayoutTag), +pub enum LayoutParsedNode { + Tag(LayoutParsedTag), Text(String), } -impl ParsedLayoutNode { +impl LayoutParsedNode { pub fn new_tag(namespace: String, tag: String) -> Self { - Self::Tag(ParsedLayoutTag::new(namespace, tag)) + Self::Tag(LayoutParsedTag::new(namespace, tag)) } pub fn new_text(text: String) -> Self { @@ -15,13 +15,13 @@ impl ParsedLayoutNode { } #[derive(Debug)] -pub struct ParsedLayoutTag { +pub struct LayoutParsedTag { pub namespace: Option, pub tag: String, pub attributes: Vec<(String, String)>, } -impl ParsedLayoutTag { +impl LayoutParsedTag { pub fn new(namespace: String, tag: String) -> Self { let namespace = if namespace.is_empty() { None } else { Some(namespace) }; diff --git a/src/main.rs b/src/main.rs index b5e53000..92b33074 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ mod gui_node; mod gui_attributes; mod window_events; mod component_layout; -mod parsed_layout_node; +mod layout_parsed_node; use application::Application; use winit::event_loop::EventLoop;