From c9889f7c6622def3b6badde2738c3e912b48144f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 11 Jun 2026 13:42:31 -0700 Subject: Basic if statements work. I need to tweak the parser to get mid-tags working, then we can have else, and maybe elif. After that is expressions. --- src/lib.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index b0bc688..8c91686 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,7 @@ enum Token { Loop(Identifier, Vec), Show(Identifier,Properties), If(Identifier, Vec), - ElseIf(Identifier, Vec), + ElIf(Identifier, Vec), Else(Vec), Text(String), } @@ -205,6 +205,14 @@ fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> } } } + Token::If(ident,code) => { + if let Some(value) = input.get_value( &ident ) && + let Value::Bool(b) = value && + b { + + exec(input, code, buf)? + } + } Token::Show(ident,p) => { let format = if let Some(s) = p.get("format") { s @@ -219,6 +227,13 @@ fn exec(input: &impl MappedStructure, tokens: &Vec, buf: &mut String) -> Value::List(_) => { buf.push_str(""); } + Value::Bool(b) => { + if b { + buf.push_str("true"); + } else { + buf.push_str("false"); + } + } Value::String(s) => { buf.push_str(s.as_str()); } @@ -313,7 +328,7 @@ Now with explicit outputs: let mut ct = Crimtag::new(); if let Err(e) = ct.load_static(r#"Looping code: [|view "index"|>We will enumerate people here:[|loop people|> - - [|show last_name|], [|show first_name|]: [|show title|] [|loop tags|> [|show tag|]<|loop|] <|loop|] + - [|show last_name|], [|show first_name|][|if show_title |>: [|show title|] <|if|] [|loop tags|> [|show tag|]<|loop|] <|loop|] <|view|] "#) { println!("Error: {:?}", e ); @@ -325,21 +340,25 @@ Now with explicit outputs: [ ("first_name".into(), "Joe".into()), ("last_name".into(), "Smith".into()), + ("show_title".into(), true.into()), ("title".into(), "CEO".into()), ].into(), [ ("first_name".into(), "Chris".into()), ("last_name".into(), "Perkens".into()), + ("show_title".into(), false.into()), ("title".into(), "Baconeer".into()), ].into(), [ ("first_name".into(), "Will".into()), ("last_name".into(), "Power".into()), + ("show_title".into(), false.into()), ("title".into(), "CFO".into()), ].into(), [ ("first_name".into(), "Justin".into()), ("last_name".into(), "Time".into()), + ("show_title".into(), true.into()), ("title".into(), "CIO".into()), ].into(), ].into()), -- cgit v1.2.3