From 8244fa09182890d8ca6022c0553264657881a9e8 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 17 Jun 2024 16:20:24 +0000 Subject: [PATCH] handle null captures --- controllers/llguidance_ctrl/src/earley/parser.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/controllers/llguidance_ctrl/src/earley/parser.rs b/controllers/llguidance_ctrl/src/earley/parser.rs index 25fc59d7..2601f911 100644 --- a/controllers/llguidance_ctrl/src/earley/parser.rs +++ b/controllers/llguidance_ctrl/src/earley/parser.rs @@ -1055,11 +1055,18 @@ impl Parser { if sym_data.is_nullable { self.scratch .add_unique(item.advance_dot(), item_idx, "null"); + if self.scratch.definitive && sym_data.props.capture_name.is_some() { + // nullable capture + let var_name = sym_data.props.capture_name.as_ref().unwrap(); + debug!(" capture: {} NULL", var_name); + self.captures.push((var_name.clone(), vec![])); + } } for rule in &sym_data.rules { let new_item = Item::new(*rule, curr_idx); self.scratch.add_unique(new_item, item_idx, "predict"); } + // TODO the hidden stuff is no longer used if self.scratch.definitive && sym_data.props.hidden { for rule in &sym_data.rules { let new_item = Item::new(*rule, curr_idx);