bynk_syntax/lib.rs
1//! Bynk's syntax foundation — the lowest leaf of the compiler crate set.
2//!
3//! This crate holds the modules every other layer depends *on* and none depend
4//! *up* from: the lexer, the parser and its AST, source [`span`]s, the
5//! [`keywords`] table, the structured [`CompileError`]
6//! type, and the [`diagnostics`] code registry (the single source of truth for
7//! `bynk.*` codes). Diagnostics, positions, and codes therefore cross every
8//! crate without an upward edge.
9//!
10//! Extracted from the old `bynkc` crate as slice 1 of the crate-decomposition
11//! track (ADRs 0099 layering, 0102 foundation boundary). Behaviour is unchanged
12//! from when these modules lived there.
13
14// The README's `rust` examples are compiled (and, unless marked `no_run`, run)
15// as doctests, so they cannot rot (#1645). `cfg(doctest)` keeps this item out of
16// every build and out of the docs.rs front page, which the `//!` docs above own.
17#[cfg(doctest)]
18#[doc = include_str!("../README.md")]
19struct ReadmeDoctests;
20
21pub mod ast;
22pub mod cron;
23pub mod decimal;
24pub mod diagnostics;
25pub mod error;
26pub mod fix;
27pub mod keywords;
28pub mod lexer;
29pub mod parser;
30pub mod print;
31pub mod semantic_tokens;
32pub mod span;
33
34pub use error::{CompileError, Severity, partition_by_severity};
35
36/// Maximum nesting depth the recursive-descent parser and the interpolation
37/// lexer accept before reporting a bounded-depth diagnostic instead of
38/// recursing another frame (#713). A compiler/LSP must never abort on
39/// malformed source, but every nesting level costs a stack frame, so an
40/// unbounded parser overflows and the process aborts (`SIGABRT`) on
41/// pathologically nested input — reachable on the 8 MB main thread (~880
42/// parenthesised levels) and, at ~8× smaller frames-to-stack ratio, in the
43/// low hundreds on the ~1 MB stacks the LSP and the in-browser playground
44/// run with.
45///
46/// The value sits well below the ~110 levels a 1 MB stack holds, leaving
47/// comfortable headroom, and far above any realistic hand-written or
48/// generated source (expression, type, and interpolation nesting past a
49/// handful is already exceptional). Source that exceeds it is rejected with
50/// a diagnostic rather than crashing the process.
51pub(crate) const MAX_NESTING_DEPTH: usize = 64;