From 057bd8cb2d4a1539701d65489fe647b96a538e98 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 4 Jun 2026 15:41:42 -0700 Subject: Start of my new templating library. --- src/lib.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..57f777e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,75 @@ +use std::path::{PathBuf,Path}; +use std::collections::HashMap; +use core::error::Error; + +mod lexer; + +pub struct Tx { + fragments: HashMap, +} + +enum FragmentSource { + File { + path: PathBuf, + loaded: usize, + } +} + +struct Fragment { + name: String, + source: FragmentSource, + sections: HashMap, +} + +struct Section { + name: String, + ast_root: Token, +} + +type Properties = HashMap; + +enum Token { + Root(Vec), + Fragment(String,Properties,Vec), + Section(String,Properties,Vec), + Text(String), + +} + +struct State { +} + +impl Tx { + pub fn new() -> Self { + Self { + fragments: HashMap::new(), + } + } + + pub fn load(path: &Path) -> Result<(),Box::> { + Ok(()) + } + + pub fn parse(data: String) -> Result<(),Box::> { + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn lexing() { + let data = r#"Leading comment: [|fragment "basic"|>Hello there <|fragment|] Trailing text"#; + let ll = lexer::Lexer::new( &data ); + for sym in ll { + if let lexer::Symbol::Error{line,row,what} = sym { + println!("Error {}:{}: {}", line, row, what ); + break; + } else { + println!("Symbol: {:?}", sym ); + } + } + } +} -- cgit v1.2.3