pub struct ParseBudget {
pub max_errors: usize,
pub max_depth: usize,
pub max_tokens_skipped: usize,
pub max_recoveries: usize,
}Expand description
Budget limits for parser operations to prevent runaway parsing.
These limits ensure the parser terminates in bounded time even when processing malformed or adversarial input. Each budget parameter has a sensible default that works for most real-world Perl code.
§Usage
use perl_error::ParseBudget;
// Use defaults for normal parsing
let budget = ParseBudget::default();
// Stricter limits for untrusted input
let strict = ParseBudget {
max_errors: 10,
max_depth: 64,
max_tokens_skipped: 100,
max_recoveries: 50,
};Fields§
§max_errors: usizeMaximum number of errors to collect before giving up. After this limit, parsing stops to avoid flooding diagnostics. Default: 100
max_depth: usizeMaximum nesting depth for recursive constructs (blocks, expressions). Prevents stack overflow on deeply nested input. Default: 256
max_tokens_skipped: usizeMaximum tokens to skip during a single recovery attempt. Prevents infinite loops when recovery can’t find a sync point. Default: 1000
max_recoveries: usizeMaximum number of recovery attempts per parse. Bounds total recovery work to prevent pathological cases. Default: 500
Implementations§
Source§impl ParseBudget
impl ParseBudget
Sourcepub fn for_ide() -> ParseBudget
pub fn for_ide() -> ParseBudget
Create a budget suitable for IDE/LSP usage with generous limits.
Sourcepub fn strict() -> ParseBudget
pub fn strict() -> ParseBudget
Create a strict budget for parsing untrusted input.
Sourcepub fn unlimited() -> ParseBudget
pub fn unlimited() -> ParseBudget
Create an unlimited budget (use with caution).
Trait Implementations§
Source§impl Clone for ParseBudget
impl Clone for ParseBudget
Source§fn clone(&self) -> ParseBudget
fn clone(&self) -> ParseBudget
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParseBudget
impl Debug for ParseBudget
Source§impl Default for ParseBudget
impl Default for ParseBudget
Source§fn default() -> ParseBudget
fn default() -> ParseBudget
Source§impl PartialEq for ParseBudget
impl PartialEq for ParseBudget
impl Copy for ParseBudget
impl Eq for ParseBudget
impl StructuralPartialEq for ParseBudget
Auto Trait Implementations§
impl Freeze for ParseBudget
impl RefUnwindSafe for ParseBudget
impl Send for ParseBudget
impl Sync for ParseBudget
impl Unpin for ParseBudget
impl UnsafeUnpin for ParseBudget
impl UnwindSafe for ParseBudget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.