Skip to main content

Parser

Trait Parser 

Source
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§

Source

fn build_parse_trees(&self) -> bool

Reports whether generated parser rules should build parse-tree nodes while recognizing input.

Source

fn set_build_parse_trees(&mut self, build: bool)

Enables or disables parse-tree construction for subsequent rule calls.

Provided Methods§

Source

fn number_of_syntax_errors(&self) -> usize

Returns the number of parser syntax errors recorded by committed parse paths so far.

Source

fn report_diagnostic_errors(&self) -> bool

Reports whether prediction diagnostic-listener messages are emitted during parser ATN recognition.

Source

fn set_report_diagnostic_errors(&mut self, _report: bool)

Enables or disables ANTLR-style prediction diagnostics for subsequent rule calls.

Source

fn prediction_mode(&self) -> PredictionMode

Reports the prediction strategy used when selecting among alternatives.

Source

fn set_prediction_mode(&mut self, _mode: PredictionMode)

Sets the prediction strategy for subsequent rule calls.

Source

fn max_rule_depth(&self) -> Option<usize>

Maximum rule-nesting depth accepted before the parse aborts, or None for unlimited (the default).

Source

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.

Source

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.

Source

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".

Implementors§

Source§

impl<S, H> Parser for BaseParser<S, H>