pub trait Parser: Recognizer {
// Required methods
fn build_parse_trees(&self) -> bool;
fn set_build_parse_trees(&mut self, build: bool);
// Provided methods
fn number_of_syntax_errors(&self) -> usize { ... }
fn report_diagnostic_errors(&self) -> bool { ... }
fn set_report_diagnostic_errors(&mut self, _report: bool) { ... }
fn prediction_mode(&self) -> PredictionMode { ... }
fn set_prediction_mode(&mut self, _mode: PredictionMode) { ... }
fn max_rule_depth(&self) -> Option<usize> { ... }
fn set_max_rule_depth(&mut self, _depth: Option<usize>) { ... }
fn add_parse_listener(&mut self, _listener: Box<dyn ParseListener>) { ... }
fn remove_parse_listeners(&mut self) -> Vec<Box<dyn ParseListener>> { ... }
}Required Methods§
Sourcefn build_parse_trees(&self) -> bool
fn build_parse_trees(&self) -> bool
Reports whether generated parser rules should build parse-tree nodes while recognizing input.
Sourcefn set_build_parse_trees(&mut self, build: bool)
fn set_build_parse_trees(&mut self, build: bool)
Enables or disables parse-tree construction for subsequent rule calls.
Provided Methods§
Sourcefn number_of_syntax_errors(&self) -> usize
fn number_of_syntax_errors(&self) -> usize
Returns the number of parser syntax errors recorded by committed parse paths so far.
Sourcefn report_diagnostic_errors(&self) -> bool
fn report_diagnostic_errors(&self) -> bool
Reports whether prediction diagnostic-listener messages are emitted during parser ATN recognition.
Sourcefn set_report_diagnostic_errors(&mut self, _report: bool)
fn set_report_diagnostic_errors(&mut self, _report: bool)
Enables or disables ANTLR-style prediction diagnostics for subsequent rule calls.
Sourcefn prediction_mode(&self) -> PredictionMode
fn prediction_mode(&self) -> PredictionMode
Reports the prediction strategy used when selecting among alternatives.
Sourcefn set_prediction_mode(&mut self, _mode: PredictionMode)
fn set_prediction_mode(&mut self, _mode: PredictionMode)
Sets the prediction strategy for subsequent rule calls.
Sourcefn max_rule_depth(&self) -> Option<usize>
fn max_rule_depth(&self) -> Option<usize>
Maximum rule-nesting depth accepted before the parse aborts, or None
for unlimited (the default).
Sourcefn set_max_rule_depth(&mut self, _depth: Option<usize>)
fn set_max_rule_depth(&mut self, _depth: Option<usize>)
Bounds the rule-nesting depth for subsequent rule calls.
Deeply nested input is parsed safely regardless (rule recursion grows onto a segmented stack), but each nesting level still costs CPU and tree memory. Callers parsing untrusted input can cap that work: when the limit is exceeded the parse stops with a positioned syntax error instead of consuming unbounded resources. The measure counts rule frames plus left-recursive operator expansions, matching what an upstream-ANTLR rule-entry listener observes.
The cap is enforced by generated recursive-descent rule bodies. When one is set, generated dispatch routes ATN-preferred rules through their generated bodies too, trading that fast path for enforcement. Rules the generator emitted no body for (interpreter-only fallback) do not check the cap.
Sourcefn add_parse_listener(&mut self, _listener: Box<dyn ParseListener>)
fn add_parse_listener(&mut self, _listener: Box<dyn ParseListener>)
Registers a listener for committed rule enter/exit events during
recognition (ANTLR’s addParseListener). See ParseListener for
the delivery contract. The default implementation drops the listener;
BaseParser and generated parsers deliver events.
Sourcefn remove_parse_listeners(&mut self) -> Vec<Box<dyn ParseListener>>
fn remove_parse_listeners(&mut self) -> Vec<Box<dyn ParseListener>>
Removes every registered parse listener and returns them, dropping any sticky abort a removed listener had requested.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".