diff options
| author | Stanisław Zagórowski <hasohasacz@gmail.com> | 2024-01-11 15:29:25 +0100 |
|---|---|---|
| committer | Stanisław Zagórowski <hasohasacz@gmail.com> | 2024-01-11 15:29:25 +0100 |
| commit | 8d9e00edacbc061ec5efba100e2af71be6824af8 (patch) | |
| tree | 3f03f5a11a3a4e1ee804bc4b55e29a867a9db563 /src/luax/mod.rs | |
| parent | 343bcfdfaaba32b7a46e1a945a4538e72d166ea8 (diff) | |
luax
Diffstat (limited to 'src/luax/mod.rs')
| -rw-r--r-- | src/luax/mod.rs | 65 |
1 files changed, 2 insertions, 63 deletions
diff --git a/src/luax/mod.rs b/src/luax/mod.rs index a7eb38f..df9f57d 100644 --- a/src/luax/mod.rs +++ b/src/luax/mod.rs @@ -2,71 +2,10 @@ use crate::Result; mod lexer; mod preprocessor; +#[cfg(test)] +mod tests; mod tokens; -#[derive(Debug)] -pub enum Node<'s> { - Code(&'s str), - Text(&'s str), - Element(Element<'s>), -} - -impl<'s> Node<'s> { - pub fn to_table<W: std::io::Write>(&self, f: &mut W) -> Result<()> { - match &self { - Node::Code(s) => write!(f, "{}", s)?, - Node::Text(s) => write!(f, "\"{}\"", s)?, - Node::Element(element) => { - write!(f, "{{")?; - write!(f, "tag=\"{}\", ", element.tag)?; - for attribute in &element.attributes { - match &attribute.value { - Value::Literal(s) => write!(f, "{}=\"{}\", ", attribute.key, s)?, - Value::Expression(s) => write!(f, "{}={}, ", attribute.key, s)?, - } - } - write!(f, "children={{")?; - for child in &element.children { - child.to_table(f)?; - } - write!(f, "}}")?; - write!(f, "}}")?; - } - } - Ok(()) - } -} - -#[derive(Debug)] -pub struct Element<'s> { - pub tag: &'s str, - pub attributes: Vec<Attribute<'s>>, - pub children: Vec<Node<'s>>, -} - -#[derive(Debug)] -pub struct Attribute<'s> { - pub key: &'s str, - pub value: Value<'s>, -} - -#[derive(Debug)] -pub enum Value<'s> { - Literal(&'s str), - Expression(&'s str), -} - -#[derive(Debug)] -pub struct Template<'s> { - pub root: Node<'s>, -} - -impl<'s> Template<'s> { - pub fn to_table<W: std::io::Write>(&self, f: &mut W) -> Result<()> { - self.root.to_table(f) - } -} - pub fn preprocess(s: &str) -> Result<String> { let mut buf = Vec::new(); let preprocessor = preprocessor::Preprocessor::new(s, &mut buf)?; |
