Merge branch 'master' into query-pattern-is-definite
This commit is contained in:
commit
1ea29053e1
33 changed files with 2004 additions and 763 deletions
|
|
@ -170,7 +170,7 @@ pub enum QueryError {
|
|||
enum TextPredicate {
|
||||
CaptureEqString(u32, String, bool),
|
||||
CaptureEqCapture(u32, u32, bool),
|
||||
CaptureMatchString(u32, regex::bytes::Regex),
|
||||
CaptureMatchString(u32, regex::bytes::Regex, bool),
|
||||
}
|
||||
|
||||
impl Language {
|
||||
|
|
@ -1314,7 +1314,7 @@ impl Query {
|
|||
});
|
||||
}
|
||||
|
||||
"match?" => {
|
||||
"match?" | "not-match?" => {
|
||||
if p.len() != 3 {
|
||||
return Err(QueryError::Predicate(format!(
|
||||
"Wrong number of arguments to #match? predicate. Expected 2, got {}.",
|
||||
|
|
@ -1334,12 +1334,14 @@ impl Query {
|
|||
)));
|
||||
}
|
||||
|
||||
let is_positive = operator_name == "match?";
|
||||
let regex = &string_values[p[2].value_id as usize];
|
||||
text_predicates.push(TextPredicate::CaptureMatchString(
|
||||
p[1].value_id,
|
||||
regex::bytes::Regex::new(regex).map_err(|_| {
|
||||
QueryError::Predicate(format!("Invalid regex '{}'", regex))
|
||||
})?,
|
||||
is_positive,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -1631,9 +1633,9 @@ impl<'a> QueryMatch<'a> {
|
|||
let node = self.capture_for_index(*i).unwrap();
|
||||
(text_callback(node).as_ref() == s.as_bytes()) == *is_positive
|
||||
}
|
||||
TextPredicate::CaptureMatchString(i, r) => {
|
||||
TextPredicate::CaptureMatchString(i, r, is_positive) => {
|
||||
let node = self.capture_for_index(*i).unwrap();
|
||||
r.is_match(text_callback(node).as_ref())
|
||||
r.is_match(text_callback(node).as_ref()) == *is_positive
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue