Skip to main content

xgrammar/parser/
capture_event.rs

1//! A completion event of a captured rule.
2
3use super::capture_occurrence::CaptureOccurrence;
4
5/// Recorded when a captured (or capture-hiding) rule is completed during parsing. The matched
6/// span is `[start_pos, r)` in input positions, where `r` is the history row at which the event
7/// is recorded.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct CaptureEvent {
10    /// The id of the completed rule.
11    pub rule_id: i32,
12    /// The position where the rule started matching. `NO_PREV_INPUT_POS` means position 0 (the
13    /// rule acts as the root).
14    pub start_pos: i32,
15    /// The unadjusted start position of this rule occurrence. Differs from `start_pos` for the
16    /// zero-width event inserted after a dynamic-dispatch marker.
17    pub occurrence_start_pos: i32,
18    /// Number of trailing bytes hidden only from this rule's own capture.
19    pub hidden_suffix_bytes: i32,
20    /// Number of trailing bytes hidden from every containing capture.
21    pub hidden_stop_bytes: i32,
22    /// The captured rule occurrences whose concrete Earley parent chains contain this stop
23    /// completion. Includes this rule's occurrence when the rule itself is captured.
24    pub stop_capture_targets: Vec<CaptureOccurrence>,
25}