Flesh out syntax part of documentation

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-16 10:04:33 +01:00
parent 560d37f633
commit 79a037b749
2 changed files with 71 additions and 2 deletions

View file

@ -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:
//!
//! - `{{= <expr> }}` Interpolations
//! - `{{ <control> }}` 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 <expr> }}
//! {{ else if <expr> }}
//! {{ else }}
//! {{ end }}
//! ```
//!
//! **Loops `for .. in`**
//!
//! ```nomo
//! {{ for <identifier> in <expr> }}
//! {{ else }}
//! {{ end }}
//! ```
use std::collections::HashMap;

View file

@ -246,12 +246,12 @@ impl NomoValue {
pub(crate) fn try_to_string(&self) -> Option<String> {
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,
}