From 92dbff3cda66a2a677f0c2306bb8508c64884445 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 11 Jun 2026 10:43:24 -0700 Subject: Broke out error and renamed it. I like the new name, now it could be for all sorts. --- src/lib.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index feb00f0..9b838f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,9 @@ use std::time::SystemTime; mod lexer; mod parser; mod position; +mod error; -pub use parser::ParseError; +pub use error::{CrimError,CrimResult}; pub use position::*; #[derive(Debug)] @@ -38,7 +39,7 @@ struct View { } impl View { - fn process(&self, input: &impl MappedStructure) -> Result { + fn process(&self, input: &impl MappedStructure) -> Result { let mut out_vars = Context::new(); for output in &self.outputs { let mut buf = String::new(); @@ -61,6 +62,9 @@ type Properties = HashMap; enum Token { Loop(Identifier, Vec), Show(Identifier,Properties), + If(Identifier, Vec), + ElseIf(Identifier, Vec), + Else(Vec), Text(String), } @@ -165,13 +169,13 @@ impl Crimtag { Ok(()) } - pub fn load_static(&mut self, data: &str) -> Result<(),ParseError> { + pub fn load_static(&mut self, data: &str) -> Result<(),CrimError> { let source_id = self.id_source( &ViewSource::Static ); let p = parser::Parser::new(); self.register_views( p.parse( &data, source_id )? ) } - pub fn load_external(&mut self, key: &str, data: &str) -> Result<(),ParseError> { + pub fn load_external(&mut self, key: &str, data: &str) -> Result<(),CrimError> { let source_id = self.id_source( &ViewSource::External{ key: key.to_string()} ); @@ -182,7 +186,7 @@ impl Crimtag { ) } - fn register_views(&mut self, views: Vec) -> Result<(),ParseError> { + fn register_views(&mut self, views: Vec) -> Result<(),CrimError> { for view in views { self.views.insert( view.name.clone(), view ); } @@ -201,15 +205,15 @@ impl Crimtag { } } - pub fn render_partial(&self, view: &str, input: &impl MappedStructure ) -> Result { + pub fn render_partial(&self, view: &str, input: &impl MappedStructure ) -> Result { if let Some(view) = self.views.get(view) { return view.process( input ) } else { - return Err(ParseError::new(Position::new(0,0),"No such view found")); + return Err(CrimError::new(Position::none(),"No such view found".into())); } } - pub fn render(&self, view: &str, input: &impl MappedStructure ) -> Result { + pub fn render(&self, view: &str, input: &impl MappedStructure ) -> Result { if let Some(view) = self.views.get( view ) { let mut output = view.process( input )?; if let Some(l) = &view.layout { @@ -220,17 +224,17 @@ impl Crimtag { Ok(s) } else { - Err(ParseError::new(Position::new(0,0),"No content found in root layout.")) + Err(CrimError::new(Position::none(), "No content found in root layout.".into())) } } } else { - Err(ParseError::new(Position::new(0,0),"No such view found")) + Err(CrimError::new(Position::none(),"No such view found".into())) } } } -fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> Result<(),ParseError> { +fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> Result<(),CrimError> { for token in tokens { match token { Token::Loop(ident,code) => { @@ -279,6 +283,7 @@ fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> Token::Text(s) => { buf.push_str( s ); } + _ => {} } } Ok(()) -- cgit v1.2.3