Expand description
§mst-parser
A zero-dependency, mustache-style template parser supporting nested variables.
This crate provides a recursive descent parser for {{variable}} style syntax.
It produces an Abstract Syntax Tree (AST) but does not perform any rendering or substitution.
§Features
- Nested Variables: Supports
{{ key.{{subsection}} }}syntax. - Safety: Configurable limits on recursion depth and node count to prevent malicious inputs.
- no_std: Compatible with
#![no_std]environments (requiresalloc). - Diagnostics: Optional
tracingintegration for parser debugging.
§Example
use mst_parser::{parse, Limits, Node, Parser};
let input = "Hello {{user.{{attr}}}}!";
// Use default limits
let nodes = parse(input).unwrap();
assert_eq!(nodes.len(), 3);
match &nodes[1] {
Node::Variable { parts } => {
// parts represents: "user.", {{attr}}
assert_eq!(parts.len(), 2);
}
_ => panic!("Expected variable"),
}
// Or with custom limits
let limits = Limits { max_depth: 2, ..Limits::default() };
let parser = Parser::new(limits);
let nodes = parser.parse(input).unwrap();Structs§
- Limits
- Configuration limits to prevent resource exhaustion attacks.
- Parser
- A configured template parser.
Enums§
- Error
- Errors that can occur during template parsing.
- Node
- Represents a node in the parsed template AST.
Functions§
- parse
- Convenience function that parses with default limits.