use super::{Query, QueryMatch, QueryMatches};
use crate::parser_v4::ParseNode;
use std::ops::Range;
pub struct QueryCursor {
byte_range: Option<Range<usize>>,
match_root: bool,
}
impl QueryCursor {
pub fn new() -> Self {
QueryCursor {
byte_range: None,
match_root: false,
}
}
pub fn set_byte_range(&mut self, range: Range<usize>) {
self.byte_range = Some(range);
}
pub fn clear_byte_range(&mut self) {
self.byte_range = None;
}
pub fn set_match_root(&mut self, match_root: bool) {
self.match_root = match_root;
}
pub fn matches<'a>(&'a mut self, query: &'a Query, root: &'a ParseNode) -> QueryMatches<'a> {
QueryMatches::new(query, root)
}
pub fn collect_matches(&mut self, query: &Query, root: &ParseNode) -> Vec<QueryMatch> {
self.matches(query, root).collect()
}
#[allow(dead_code)]
fn is_in_range(&self, node: &ParseNode) -> bool {
if let Some(ref range) = self.byte_range {
node.start_byte >= range.start && node.end_byte <= range.end
} else {
true
}
}
}
impl Default for QueryCursor {
fn default() -> Self {
Self::new()
}
}