From b2e79f64387b8cd11911f2fa2db8038478e9b22b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 14 Feb 2020 20:50:07 -0800 Subject: [PATCH] rust: In queries, allow `set!` w/ capture and constant --- lib/binding_rust/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 9f78a1f5..0cd9685d 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -1439,12 +1439,17 @@ impl Query { let mut value = None; if i < args.len() { if args[i].type_ == ffi::TSQueryPredicateStepType_TSQueryPredicateStepTypeCapture { - return Err(QueryError::Predicate(format!( - "Invalid arguments to {} predicate. Expected string, got @{}", - function_name, capture_names[args[i].value_id as usize] - ))); + if capture_id.is_some() { + return Err(QueryError::Predicate(format!( + "Invalid arguments to {} predicate. Unexpected second capture name @{}", + function_name, capture_names[args[i].value_id as usize] + ))); + } else { + capture_id = Some(args[i].value_id as usize); + } + } else { + value = Some(string_values[args[i].value_id as usize].as_str()); } - value = Some(string_values[args[i].value_id as usize].as_str()); } Ok(QueryProperty::new(key, value, capture_id))