diff --git a/src/lib.rs b/src/lib.rs index 8d970d7..b16d474 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,75 @@ cfg_attr(doc, doc = ::document_features::document_features!()) )] //! +//! ## Syntax +//! +//! Nomo tries to keep a consistent syntax across its features. +//! The main concepts are: +//! +//! [`nomo`](crate) uses `{{ }}` as its identifiers. Each of them forms a 'block'. +//! +//! There are two kinds of blocks: +//! +//! - `{{= }}` Interpolations +//! - `{{ }}` everything else +//! +//! ### Expressions +//! +//! An expression in [`nomo`](crate) is anything that produces a value. Notably, control structures +//! _do not_ create values. This is different to rust. +//! +//! So for example this does not work: +//! +//! ```nomo +//! {{= if is_active "Active" else "Inactive" end }} +//! ``` +//! +//! If you wish to conditionally output something, you would write: +//! +//! ```nomo +//! {{ if is_active }} +//! Active +//! {{ else }} +//! Inactive +//! {{ end }} +//! ``` +//! +//! In expressions you can write: +//! - Mathematical expressions (`+-*/`) +//! - Logical/Binary expressions (`&&`, `||`, `>`, ...) +//! - Literals (`12`, `292.21`, `"Hello"`) +//! +//! ### Interpolations +//! +//! Interpolations is how one prints out data. A [`NomoValue`] can be printed if it is a: +//! +//! - String +//! - Integer/SignedInteger +//! - Bool +//! - Float +//! +//! All other values will result in an error. +//! +//! ### Control Structures +//! +//! [`Nomo`](crate) supports several control structures: +//! +//! **Conditions `if/else`**: +//! +//! ```nomo +//! {{ if }} +//! {{ else if }} +//! {{ else }} +//! {{ end }} +//! ``` +//! +//! **Loops `for .. in`** +//! +//! ```nomo +//! {{ for in }} +//! {{ else }} +//! {{ end }} +//! ``` use std::collections::HashMap; diff --git a/src/value.rs b/src/value.rs index 903fc73..b652dfd 100644 --- a/src/value.rs +++ b/src/value.rs @@ -246,12 +246,12 @@ impl NomoValue { pub(crate) fn try_to_string(&self) -> Option { match self { NomoValue::String { value } => Some(value.to_string()), - NomoValue::Array { .. } => None, NomoValue::Bool { value } => Some(value.to_string()), - NomoValue::Object { .. } => None, NomoValue::Integer { value } => Some(value.to_string()), NomoValue::SignedInteger { value } => Some(value.to_string()), NomoValue::Float { value } => Some(value.to_string()), + NomoValue::Array { .. } => None, + NomoValue::Object { .. } => None, NomoValue::Iterator { .. } => None, NomoValue::Undefined => None, }