Skip to main content

MAX_NESTING

Constant MAX_NESTING 

Source
pub const MAX_NESTING: usize = 32; // 32usize
Expand description

How deeply captures and nested templates may nest before the scanner refuses (D10).

scan_template and [crate::body::parse_capture_body] are mutually recursive once a capture body may hold a template of its own, so "{a:" + "{".repeat(100_000) is adversarial input — and a compiler may not answer adversarial input with a stack overflow. The bound is far above anything a person writes. How deeply backtick templates may nest inside each other’s captures (D10).

A capture body is a full parser expression, so `{g:choice(A: `{x:int}`)}` is one template containing another — which makes the lexer’s template run and the input parser’s scan_template mutually recursive with the file’s own text. Both must refuse deep nesting rather than overflow the stack, and they must refuse it at the same depth or one of them accepts what the other cannot read. It lives here because praxis-syntax is the crate they both already depend on.

The bound is far above anything a person writes.