Layout language AST building now complete with recursive parsing referenced XML files

This commit is contained in:
Keavon Chambers
2020-05-31 22:02:41 -07:00
parent 0c7e6bc883
commit 559833be8e
17 changed files with 429 additions and 288 deletions
+46 -16
View File
@@ -1,23 +1,53 @@
use crate::layout_abstract_attributes::*;
use crate::layout_abstract_types::*;
#[derive(Debug)]
pub struct LayoutAbstractSyntaxNode {
pub namespace: Option<String>,
pub enum LayoutAbstractNode {
Tag(LayoutAbstractTag),
Text(String),
}
impl LayoutAbstractNode {
pub fn new_tag(namespace: String, name: String) -> Self {
Self::Tag(LayoutAbstractTag::new(namespace, name))
}
pub fn new_text(text: String) -> Self {
Self::Text(text)
}
}
#[derive(Debug)]
pub struct LayoutAbstractTag {
pub namespace: String,
pub name: String,
pub attributes: Vec<Attribute>,
}
impl LayoutAbstractSyntaxNode {
pub fn new(namespace: Option<String>, tag: String, attributes: &Vec<(String, String)>) -> Self {
for attribute in attributes {
let parsed = parse_attribute(&attribute.1[..]);
println!("{} : {:?} -> {:?}", attribute.0, attribute.1, parsed);
}
Self {
namespace,
name: tag,
attributes: Vec::new(),
}
impl LayoutAbstractTag {
pub fn new(namespace: String, name: String) -> Self {
Self { namespace, name, attributes: Vec::new() }
}
}
pub fn add_attribute(&mut self, attribute: Attribute) {
self.attributes.push(attribute);
}
}
#[derive(Debug)]
pub struct Attribute {
pub name: String,
pub value: AttributeValue,
}
impl Attribute {
pub fn new(name: String, value: AttributeValue) -> Self {
Self { name, value }
}
}
#[derive(Debug)]
pub enum AttributeValue {
VariableParameter(VariableParameter),
TypeValue(Vec<TypeValueOrArgument>),
}