1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2026 Bo Lin
//! Compile-time static DFA tables of the parser decisions (tool side).
//!
//! [`DecisionTableBuilder`] builds the static prediction table of each
//! prediction decision of a compiled parser unit, so that the generated parser
//! predicts without `adaptive_predict` wherever a table can decide. A state
//! that no table can decide soundly escapes to the adaptive simulation, or,
//! under `--static-dfa-only`, gets a static resolution. The tables drive
//! `--static-parser-dfa`, `--dump-dfas`, `--profile-decisions`, and the
//! `G4S190`, `G4S192`, and `G4S193` diagnostics. The budget of each decision
//! (see [`DecisionBudget`]) limits the construction.
//!
//! # Where the machinery lives
//!
//! The builder is a *driver*: it owns the construction policy, the subset
//! construction over token intervals, and the frontier of a table, while the
//! ATN/DFA mechanics stay in `dbt-antlr-runtime` behind the `static-dfa-build`
//! feature (see `dbt_antlr_runtime::analysis`):
//!
//! - A [`ParserATNSimulatorManager`] is created from the unit's `&'static ATN`;
//! its `get_simulator` borrows an arena and yields the parser simulator.
//! - DFA states and token edges are interned through the simulator's own
//! [`DFA`] (`add_state`, `set_edge`), so config-set deduplication, the edge
//! store, and the memory accounting are the runtime's.
//! - Closures run on [`MutableATNConfigSet`] with the runtime's
//! [`MergeCache`], so build-time contexts merge exactly like the lazy
//! simulator's, and conflicts are decided by the runtime
//! [`has_sll_conflict_terminating_prediction`].
//!
//! What is *not* shared is the closure *policy*. The runtime closure has an
//! input stream, so recursion is bounded by the input, predicates are
//! evaluated against the parser, and a rule stop pops a real caller frame.
//! A build-time closure has none of that: it must bound recursion by a depth
//! budget (widening), treat predicates symbolically, and chase grammar-wide
//! FOLLOW links to model "any caller". `closure` implements that policy and
//! keeps the resulting approximations as taint bits in a side map per config
//! set - never on the configs themselves, whose identity defines the DFA
//! states.
//!
//! # Output
//!
//! A decision ends in one [`DecisionOutcome`]: its [`DecisionKind`], the
//! [`NoTableReason`] when it has no table, and, when the construction
//! succeeded, a [`StaticDfaTable`] snapshot: the DFA states, their
//! accept/fallback/escape verdicts, and their token edges. The snapshot is
//! what `--dump-dfas` prints and what the table emission phase serializes, so
//! it is plain owned data - the arena and the simulator are dropped as soon as
//! a decision is done.
pub use DEFAULT_VISIT_BUDGET;
pub use ;
pub use ;
pub use AttemptOutcome;
pub use ;
pub use ;
pub use ;
pub use ;
pub use StaticDfaTable;
pub use ;
/// Table marker of a state whose decision must be recomputed by the adaptive
/// simulation: the static construction stopped here.
pub const ESCAPE: i32 = -1;
/// Table marker of a state where the static construction found an SLL conflict
/// it does not trust; the runtime can skip the SLL stage entirely.
pub const CONFLICT_ESCAPE: i32 = -2;
/// Table marker of a state whose alternative is decided by a runtime stack
/// guard: the take is resolved unless the real parse stack can reach one of the
/// decision's guard roots.
pub const GUARDED: i32 = -3;