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
//! AND operator state tracking (AND-01)
use super::types::{Predicate, SharedEvent};
/// Configuration for an AND branch
#[derive(Debug, Clone)]
pub struct AndBranch {
/// Event type expected for this branch
pub event_type: String,
/// Optional predicate
pub predicate: Option<Predicate>,
/// Alias for the captured event
pub alias: Option<String>,
}
/// Configuration for AND states in the NFA
#[derive(Debug, Clone)]
pub struct AndConfig {
/// The branches that need to be completed
pub branches: Vec<AndBranch>,
/// State to transition to after all branches complete
pub join_state: usize,
}
/// Runtime state tracking for AND pattern completion
#[derive(Debug, Clone)]
pub struct AndState {
/// Which branches have been completed (indexed by branch position)
pub completed: Vec<bool>,
/// Captured events for completed branches
pub branch_events: Vec<Option<SharedEvent>>,
}
impl AndState {
/// Create a new empty AND state with no completed branches.
pub fn new() -> Self {
Self {
completed: Vec::new(),
branch_events: Vec::new(),
}
}
/// Check whether the branch at position `idx` has been completed.
pub fn is_branch_completed(&self, idx: usize) -> bool {
self.completed.get(idx).copied().unwrap_or(false)
}
/// Mark branch `idx` as completed with the given event.
pub fn complete_branch(&mut self, idx: usize, event: SharedEvent) {
while self.completed.len() <= idx {
self.completed.push(false);
self.branch_events.push(None);
}
self.completed[idx] = true;
self.branch_events[idx] = Some(event);
}
/// Return true if all `total` branches have been completed.
pub fn all_completed(&self, total: usize) -> bool {
self.completed.len() >= total && self.completed.iter().take(total).all(|&c| c)
}
}
impl Default for AndState {
fn default() -> Self {
Self::new()
}
}
/// Information about what to forbid in negation states
#[derive(Debug, Clone)]
pub struct NegationInfo {
/// Event type that must NOT occur
pub forbidden_type: String,
/// Optional predicate for the forbidden event
pub predicate: Option<Predicate>,
/// NFA state to transition to once negation is confirmed
pub continue_state: usize,
}