mst_parser/ast.rs
1/* src/ast.rs */
2
3use alloc::string::String;
4use alloc::vec::Vec;
5
6/// Represents a node in the parsed template AST.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum Node {
9 /// A literal text segment.
10 Text(String),
11 /// A variable segment, e.g., `{{ ... }}`.
12 ///
13 /// The `parts` vector contains the segments inside the variable tag.
14 Variable {
15 /// The content parts within the variable delimiters.
16 parts: Vec<Self>,
17 },
18}
19
20/// Configuration limits to prevent resource exhaustion attacks.
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct Limits {
23 /// Maximum allowed nesting depth of variables. Default is 5.
24 pub max_depth: usize,
25 /// Maximum allowed total nodes in the AST. Default is 50.
26 pub max_nodes: usize,
27}
28
29impl Default for Limits {
30 fn default() -> Self {
31 Self {
32 max_depth: 5,
33 max_nodes: 50,
34 }
35 }
36}